From 962a3d38eba92f0a75a7a8f426ba2909ce03890e Mon Sep 17 00:00:00 2001 From: SwimmingRieux <141845753+SwimmingRieux@users.noreply.github.com> Date: Sat, 7 Sep 2024 23:34:45 +0330 Subject: [PATCH 1/2] fix(generate deps file): Deps file bug fix (#60) * merge * reformat and fixed csproj files --- RelationAnalysis.Migrations/Program.cs | 71 ++- .../RelationAnalysis.Migrations.csproj | 34 +- .../Controllers/Panel/AdminControllerTests.cs | 10 +- .../Controllers/Panel/UserControllerTests.cs | 3 +- ...lationshipAnalysis.Integration.Test.csproj | 18 +- .../Resources.Designer.cs | 222 +++------ .../Resources.resx | 3 +- .../RelationshipAnalysis.Test.csproj | 2 +- .../Resources.Designer.cs | 267 ++++------- RelationshipAnalysis.Test/Resources.resx | 3 +- .../AuthServices/LoginServiceTests.cs | 3 +- .../Permissions/PermissionsReceiverTests.cs | 5 +- .../Services/CRUD/Role/RoleReceiverTests.cs | 15 +- .../Services/CRUD/User/UserAdderTests.cs | 4 +- .../Services/CRUD/User/UserDeleterTests.cs | 5 +- .../Services/CRUD/User/UserUpdaterTests.cs | 132 +++--- .../CRUD/UserRole/UserRolesAdderTests.cs | 112 ++--- .../CRUD/UserRole/UserRolesRemoverTests.cs | 154 +++---- .../Edge/ContextEdgesAdditionServiceTests.cs | 37 +- .../Edge/EdgesAdditionServiceTests.cs | 25 +- .../Edge/SingleEdgeAdditionServiceTests.cs | 10 +- .../Graph/GraphDtoCreatorTests.cs | 23 +- .../GraphServices/Graph/GraphReceiverTests.cs | 10 +- .../Node/ContextNodesAdditionServiceTests.cs | 39 +- .../Node/NodesAdditionServiceTests.cs | 25 +- .../Node/SingleNodeAdditionServiceTests.cs | 25 +- .../AllUserService/AllUserDtoCreatorTests.cs | 6 +- .../AllUserService/AllUserServiceTests.cs | 9 +- .../AllUserServiceValidatorTests.cs | 4 +- .../CreateUserDtoMapperTests.cs | 2 +- .../UserCreateServiceTests.cs | 1 - .../UserCreateServiceValidatorTests.cs | 11 +- .../UserDeleteServiceTests.cs | 12 +- .../UserUpdateRolesServiceTests.cs | 21 +- .../UserUpdateRolesServiceValidatorTests.cs | 4 +- .../UserInfoService/UserInfoServiceTests.cs | 149 +++--- .../UserOutputInfoDtoCreatorTests.cs | 98 ++-- .../UserUpdateInfoMapperTests.cs | 5 +- .../UserUpdateInfoServiceTests.cs | 12 +- .../UserUpdateInfoServiceValidatorTests.cs | 6 +- .../UserUpdatePasswordServiceTests.cs | 13 +- ...UserUpdatePasswordServiceValidatorTests.cs | 2 +- .../Controllers/AttributesController.cs | 7 +- .../Controllers/Auth/AuthController.cs | 3 +- .../Controllers/Graph/EdgeController.cs | 17 +- .../Controllers/Graph/GraphController.cs | 14 +- .../Controllers/Graph/NodeController.cs | 12 +- .../Controllers/Panel/AdminController.cs | 4 +- .../Controllers/Panel/UserController.cs | 1 - .../Dto/Graph/Edge/UploadEdgeDto.cs | 1 - .../Dto/Graph/ExpansionDto.cs | 15 +- RelationshipAnalysis/Dto/Graph/GraphDto.cs | 1 - .../Dto/Graph/Node/UploadNodeDto.cs | 1 - .../Dto/Graph/SearchGraphDto.cs | 25 +- .../Dto/Panel/Admin/CreateUserDto.cs | 3 +- .../Dto/Panel/Admin/GetAllUsersDto.cs | 5 +- .../Dto/Panel/User/UserOutputInfoDto.cs | 2 - .../Middlewares/SanitizationMiddleware.cs | 6 - .../20240907090417_InitialCreate.Designer.cs | 427 ++++++++++++++++++ .../20240907090417_InitialCreate.cs | 319 +++++++++++++ RelationshipAnalysis/Models/Auth/Role.cs | 3 +- RelationshipAnalysis/Models/Auth/User.cs | 3 +- .../Models/Graph/Edge/Edge.cs | 1 - .../Models/Graph/Edge/EdgeAttribute.cs | 1 - .../Models/Graph/Edge/EdgeCategory.cs | 1 - .../Models/Graph/Node/Node.cs | 1 - .../Models/Graph/Node/NodeAttribute.cs | 1 - .../Models/Graph/Node/NodeCategory.cs | 1 - RelationshipAnalysis/Program.cs | 13 +- .../RelationshipAnalysis.csproj | 18 +- RelationshipAnalysis/Resources.resx | 3 +- .../AuthServices/Abstraction/ICookieSetter.cs | 4 +- .../AuthServices/Abstraction/ILoginService.cs | 5 +- .../Services/AuthServices/CookieSetter.cs | 4 +- .../AuthServices/CustomPasswordHasher.cs | 3 +- .../AuthServices/JwtTokenGenerator.cs | 4 +- .../Services/AuthServices/LoginService.cs | 8 +- .../Abstraction/IPermissionsReceiver.cs | 5 +- .../CRUD/Permissions/PermissionsReceiver.cs | 6 +- .../CRUD/Role/Abstraction/IRoleReceiver.cs | 3 - .../Services/CRUD/Role/RoleReceiver.cs | 5 - .../CRUD/User/Abstraction/IUserAdder.cs | 4 +- .../CRUD/User/Abstraction/IUserDeleter.cs | 4 +- .../CRUD/User/Abstraction/IUserReceiver.cs | 2 - .../CRUD/User/Abstraction/IUserUpdater.cs | 4 +- .../Services/CRUD/User/UserAdder.cs | 5 +- .../Services/CRUD/User/UserDeleter.cs | 5 +- .../Services/CRUD/User/UserReceiver.cs | 9 +- .../Services/CRUD/User/UserUpdater.cs | 5 +- .../UserRole/Abstraction/IUserRolesAdder.cs | 5 +- .../UserRole/Abstraction/IUserRolesRemover.cs | 4 +- .../Services/CRUD/UserRole/UserRolesAdder.cs | 7 +- .../CRUD/UserRole/UserRolesRemover.cs | 5 +- .../Abstraction/IAttributesReceiver.cs | 3 - .../Abstraction/ICsvProcessorService.cs | 4 - .../Abstraction/ICsvValidatorService.cs | 1 - .../Abstraction/IInfoReceiver.cs | 2 - .../GraphServices/CsvProcessorService.cs | 4 - .../GraphServices/CsvValidatorService.cs | 5 - .../IContextEdgesAdditionService.cs | 2 - .../Abstraction/ICreateEdgeCategoryService.cs | 3 +- .../Edge/Abstraction/IEdgeCategoryReceiver.cs | 5 +- .../Abstraction/IEdgeValueAdditionService.cs | 2 - .../Edge/Abstraction/IEdgesAdditionService.cs | 3 +- .../Abstraction/ISingleEdgeAdditionService.cs | 4 +- .../Edge/ContextEdgesAdditionService.cs | 17 +- .../Edge/CreateEdgeCategoryService.cs | 15 +- .../Edge/EdgeAttributesReceiver.cs | 6 - .../Edge/EdgeCategoryReceiver.cs | 7 +- .../GraphServices/Edge/EdgeInfoReceiver.cs | 18 +- .../Edge/EdgeValueAdditionService.cs | 7 +- .../Edge/EdgesAdditionService.cs | 33 +- .../Edge/SingleEdgeAdditionService.cs | 38 +- .../Abstraction/IExpansionGraphReceiver.cs | 2 - .../Graph/Abstraction/IGraphDtoCreator.cs | 3 - .../Graph/Abstraction/IGraphReceiver.cs | 1 - .../Graph/ExpansionGraphReceiver.cs | 24 +- .../GraphServices/Graph/GraphDtoCreator.cs | 8 +- .../GraphServices/Graph/GraphReceiver.cs | 5 - .../Graph/GraphSearcherService.cs | 28 +- .../IContextNodesAdditionService.cs | 2 - .../Abstraction/ICreateNodeCategoryService.cs | 3 +- .../Node/Abstraction/INodeCategoryReceiver.cs | 5 +- .../Abstraction/INodeValueAdditionService.cs | 2 - .../Node/Abstraction/INodesAdditionService.cs | 1 - .../Abstraction/ISingleNodeAdditionService.cs | 2 - .../Node/ContextNodesAdditionService.cs | 11 +- .../Node/CreateNodeCategoryService.cs | 16 +- .../Node/NodeAttributesReceiver.cs | 5 - .../Node/NodeCategoryReceiver.cs | 7 +- .../GraphServices/Node/NodeInfoReceiver.cs | 19 +- .../Node/NodeValueAdditionService.cs | 13 +- .../Node/NodesAdditionService.cs | 17 +- .../Node/SingleNodeAdditionService.cs | 28 +- .../Services/MessageResponseCreator.cs | 2 +- .../Abstraction/IAllUserDtoCreator.cs | 4 +- .../Abstraction/IAllUserService.cs | 5 +- .../Abstraction/IAllUserServiceValidator.cs | 4 +- .../AllUserService/AllUserDtoCreator.cs | 6 +- .../AllUserService/AllUserService.cs | 8 +- .../AllUserService/AllUserServiceValidator.cs | 4 +- .../Abstraction/IUserCreateService.cs | 4 +- .../IUserCreateServiceValidator.cs | 3 +- .../CreateUserService/UserCreateService.cs | 5 +- .../UserCreateServiceValidator.cs | 28 +- .../Abstraction/IUserDeleteService.cs | 3 +- .../IUserDeleteServiceValidator.cs | 3 +- .../UserDeleteService/UserDeleteService.cs | 6 +- .../UserDeleteServiceValidator.cs | 13 +- .../Abstraction/IUserUpdateRolesService.cs | 4 +- .../IUserUpdateRolesServiceValidator.cs | 4 +- .../UserUpdateRolesService.cs | 5 +- .../UserUpdateRolesServiceValidator.cs | 18 +- .../Abstraction/ILogoutService.cs | 2 - .../LogoutService/LogoutService.cs | 1 - .../Abstraction/IPermissionService.cs | 4 +- .../PermissionsService/PermissionService.cs | 3 +- .../Abstraction/IUserInfoService.cs | 2 - .../Abstraction/IUserInfoServiceValidator.cs | 3 +- .../Abstraction/IUserOutputInfoDtoCreator.cs | 3 +- .../UserInfoService/UserInfoService.cs | 3 +- .../UserInfoServiceValidator.cs | 3 +- .../UserOutputInfoDtoCreator.cs | 3 +- .../Abstraction/IUserUpdateInfoService.cs | 3 - .../IUserUpdateInfoServiceValidator.cs | 3 +- .../UserUpdateInfoService.cs | 4 +- .../UserUpdateInfoServiceValidator.cs | 23 +- .../Abstraction/IUserUpdatePasswordService.cs | 2 - .../IUserUpdatePasswordServiceValidator.cs | 3 +- .../UserUpdatePasswordService.cs | 3 +- .../UserUpdatePasswordServiceValidator.cs | 13 +- RelationshipAnalysis/appsettings.json | 2 +- 172 files changed, 1711 insertions(+), 1509 deletions(-) create mode 100644 RelationshipAnalysis/Migrations/20240907090417_InitialCreate.Designer.cs create mode 100644 RelationshipAnalysis/Migrations/20240907090417_InitialCreate.cs diff --git a/RelationAnalysis.Migrations/Program.cs b/RelationAnalysis.Migrations/Program.cs index 5cfbbbd..cd4307e 100644 --- a/RelationAnalysis.Migrations/Program.cs +++ b/RelationAnalysis.Migrations/Program.cs @@ -4,47 +4,46 @@ using Microsoft.Extensions.Hosting; using RelationshipAnalysis.Context; -namespace RelationAnalysis.Migrations +namespace RelationAnalysis.Migrations; + +internal class Program { - class Program + private static async Task Main(string[] args) { - static async Task Main(string[] args) - { - Console.WriteLine("Run console app!"); - - - var host = Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((context, config) => - { - config.AddJsonFile("appsettings.json"); - config.AddEnvironmentVariables(); - }) - .ConfigureServices((context, services) => - { - var configuration = context.Configuration; - var connectionString = configuration.GetValue("CONNECTION_STRING"); - - services.AddDbContext(options => - options.UseNpgsql(connectionString)); - - services.AddTransient(); - }) - .Build(); - - var configuration = host.Services.GetRequiredService(); - Console.WriteLine(configuration.GetValue("CONNECTION_STRING")); - Console.WriteLine(configuration.GetValue("DefaultPassword")); - - using (var scope = host.Services.CreateScope()) + Console.WriteLine("Run console app!"); + + + var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((context, config) => + { + config.AddJsonFile("appsettings.json"); + config.AddEnvironmentVariables(); + }) + .ConfigureServices((context, services) => { - var dbContext = scope.ServiceProvider.GetRequiredService(); - await dbContext.Database.MigrateAsync(); + var configuration = context.Configuration; + var connectionString = configuration.GetValue("CONNECTION_STRING"); - var myService = scope.ServiceProvider.GetRequiredService(); - await myService.AddInitialRecords(); - } + services.AddDbContext(options => + options.UseNpgsql(connectionString)); - Console.WriteLine("Done"); + services.AddTransient(); + }) + .Build(); + + var configuration = host.Services.GetRequiredService(); + Console.WriteLine(configuration.GetValue("CONNECTION_STRING")); + Console.WriteLine(configuration.GetValue("DefaultPassword")); + + using (var scope = host.Services.CreateScope()) + { + var dbContext = scope.ServiceProvider.GetRequiredService(); + await dbContext.Database.MigrateAsync(); + + var myService = scope.ServiceProvider.GetRequiredService(); + await myService.AddInitialRecords(); } + + Console.WriteLine("Done"); } } \ No newline at end of file diff --git a/RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj b/RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj index f2690c7..40f9a2f 100644 --- a/RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj +++ b/RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj @@ -1,31 +1,23 @@  - Exe net8.0 enable enable - - - - - - - - - - - - - ..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.AspNetCore.Hosting.dll - - - ..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.Extensions.Configuration.dll - + + + + + + + + + + + - - + - + \ No newline at end of file diff --git a/RelationshipAnalysis.Integration.Test/Controllers/Panel/AdminControllerTests.cs b/RelationshipAnalysis.Integration.Test/Controllers/Panel/AdminControllerTests.cs index 6d7021b..e53ad75 100644 --- a/RelationshipAnalysis.Integration.Test/Controllers/Panel/AdminControllerTests.cs +++ b/RelationshipAnalysis.Integration.Test/Controllers/Panel/AdminControllerTests.cs @@ -3,6 +3,7 @@ using System.Net.Http.Json; using System.Text; using System.Text.Json; +using Microsoft.Extensions.Options; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Dto.Panel.User; @@ -37,10 +38,10 @@ private string GenerateAdminJwtToken() FirstName = "Admin", LastName = "User", Email = "admin@example.com", - UserRoles = new List { new UserRole { Role = new Role { Name = "Admin" } } } + UserRoles = new List { new() { Role = new Role { Name = "Admin" } } } }; - return new JwtTokenGenerator(new Microsoft.Extensions.Options.OptionsWrapper(jwtSettings)) + return new JwtTokenGenerator(new OptionsWrapper(jwtSettings)) .GenerateJwtToken(user); } @@ -92,7 +93,6 @@ public async Task GetAllUsers_ShouldReturnUsers_WhenAdminIsAuthorized() Assert.NotNull(responseData); Assert.True(responseData.AllUserCount > 0); Assert.True(responseData.Users.Count > 0); - } [Fact] @@ -126,7 +126,7 @@ public async Task CreateUser_ShouldReturnSuccess_WhenAdminIsAuthorized() FirstName = "New", LastName = "User", Email = "newuser@example.com", - Roles = [ "Admin" ] + Roles = ["Admin"] }; var request = new HttpRequestMessage(HttpMethod.Post, "/api/admin/users"); @@ -160,7 +160,7 @@ public async Task CreateUser_ShouldReturnBadRequest_WhenUsernameIsNotUnique() FirstName = "Existing", LastName = "User", Email = "existinguser@example.com", - Roles = [ "Admin" ] + Roles = ["Admin"] }; var request = new HttpRequestMessage(HttpMethod.Post, "/api/admin/users"); diff --git a/RelationshipAnalysis.Integration.Test/Controllers/Panel/UserControllerTests.cs b/RelationshipAnalysis.Integration.Test/Controllers/Panel/UserControllerTests.cs index 10e9b7a..3e72e26 100644 --- a/RelationshipAnalysis.Integration.Test/Controllers/Panel/UserControllerTests.cs +++ b/RelationshipAnalysis.Integration.Test/Controllers/Panel/UserControllerTests.cs @@ -3,6 +3,7 @@ using System.Net.Http.Json; using System.Text; using System.Text.Json; +using Microsoft.Extensions.Options; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; @@ -38,7 +39,7 @@ private string GenerateJwtToken() Email = "admin@example.com" }; - return new JwtTokenGenerator(new Microsoft.Extensions.Options.OptionsWrapper(jwtSettings)).GenerateJwtToken(user); + return new JwtTokenGenerator(new OptionsWrapper(jwtSettings)).GenerateJwtToken(user); } [Fact] diff --git a/RelationshipAnalysis.Integration.Test/RelationshipAnalysis.Integration.Test.csproj b/RelationshipAnalysis.Integration.Test/RelationshipAnalysis.Integration.Test.csproj index 7f0f897..abb25f8 100644 --- a/RelationshipAnalysis.Integration.Test/RelationshipAnalysis.Integration.Test.csproj +++ b/RelationshipAnalysis.Integration.Test/RelationshipAnalysis.Integration.Test.csproj @@ -1,14 +1,11 @@ - net8.0 enable enable - false true - @@ -18,25 +15,19 @@ - - - - - ResXFileCodeGenerator Resources.Designer.cs - True @@ -44,11 +35,4 @@ Resources.resx - - - - ..\..\..\..\.nuget\packages\nsubstitute\5.1.0\lib\net6.0\NSubstitute.dll - - - - + \ No newline at end of file diff --git a/RelationshipAnalysis.Integration.Test/Resources.Designer.cs b/RelationshipAnalysis.Integration.Test/Resources.Designer.cs index cd8e1ae..434b002 100644 --- a/RelationshipAnalysis.Integration.Test/Resources.Designer.cs +++ b/RelationshipAnalysis.Integration.Test/Resources.Designer.cs @@ -11,46 +11,32 @@ namespace RelationshipAnalysis.Integration.Test { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RelationshipAnalysis.Integration.Test.Resources", typeof(Resources).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("RelationshipAnalysis.Integration.Test.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -59,239 +45,159 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to You cant delete your account!. - /// - internal static string DeleteAccountAccessErrorMessage { + internal static string ValidFileMessage { get { - return ResourceManager.GetString("DeleteAccountAccessErrorMessage", resourceCulture); + return ResourceManager.GetString("ValidFileMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Chosen email already exists. - /// - internal static string EmailExistsMessage { + internal static string FailedAddRecordsMessage { get { - return ResourceManager.GetString("EmailExistsMessage", resourceCulture); + return ResourceManager.GetString("FailedAddRecordsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Roles cant be empty!. - /// - internal static string EmptyRolesMessage { + internal static string InvalidHeaderAttribute { get { - return ResourceManager.GetString("EmptyRolesMessage", resourceCulture); + return ResourceManager.GetString("InvalidHeaderAttribute", resourceCulture); } } - /// - /// Looks up a localized string similar to Add records failed!. - /// - internal static string FailedAddRecordsMessage { + internal static string TwoSameHeadersMessage { get { - return ResourceManager.GetString("FailedAddRecordsMessage", resourceCulture); + return ResourceManager.GetString("TwoSameHeadersMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered header is invalid. - /// - internal static string InvalidHeaderAttribute { + internal static string InvalidNodeCategory { get { - return ResourceManager.GetString("InvalidHeaderAttribute", resourceCulture); + return ResourceManager.GetString("InvalidNodeCategory", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered node category is invalid. - /// - internal static string InvalidNodeCategory { + internal static string SuccessfulNodeAdditionMessage { get { - return ResourceManager.GetString("InvalidNodeCategory", resourceCulture); + return ResourceManager.GetString("SuccessfulNodeAdditionMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Password must contain one digit from 1 to 9, one lowercase letter, one uppercase letter, one special - /// character, no space, and it must be 8-16 characters long. - /// . - /// - internal static string InvalidPasswordMessage { + internal static string NoFileUploadedMessage { get { - return ResourceManager.GetString("InvalidPasswordMessage", resourceCulture); + return ResourceManager.GetString("NoFileUploadedMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Roles are invalid!. - /// - internal static string InvalidRolesListMessage { + internal static string EmailExistsMessage { get { - return ResourceManager.GetString("InvalidRolesListMessage", resourceCulture); + return ResourceManager.GetString("EmailExistsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Login Failed!. - /// - internal static string LoginFailedMessage { + internal static string SuccessfulLogoutMessage { get { - return ResourceManager.GetString("LoginFailedMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulLogoutMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to New password is required. - /// - internal static string NewPasswordRequired { + internal static string InvalidPasswordMessage { get { - return ResourceManager.GetString("NewPasswordRequired", resourceCulture); + return ResourceManager.GetString("InvalidPasswordMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to No file uploaded!. - /// - internal static string NoFileUploadedMessage { + internal static string UserNotFoundMessage { get { - return ResourceManager.GetString("NoFileUploadedMessage", resourceCulture); + return ResourceManager.GetString("UserNotFoundMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Old password is required. - /// - internal static string OldPasswordRequired { + internal static string WrongOldPasswordMessage { get { - return ResourceManager.GetString("OldPasswordRequired", resourceCulture); + return ResourceManager.GetString("WrongOldPasswordMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Password is required!. - /// - internal static string PasswordRequired { + internal static string OldPasswordRequired { get { - return ResourceManager.GetString("PasswordRequired", resourceCulture); + return ResourceManager.GetString("OldPasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to User Created Successfuly!. - /// - internal static string SucceddfulCreateUser { + internal static string NewPasswordRequired { get { - return ResourceManager.GetString("SucceddfulCreateUser", resourceCulture); + return ResourceManager.GetString("NewPasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to User Deleted successfully!. - /// - internal static string SuccessfulDeleteUserMessage { + internal static string UsernameRequired { get { - return ResourceManager.GetString("SuccessfulDeleteUserMessage", resourceCulture); + return ResourceManager.GetString("UsernameRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to Login was successful!. - /// - internal static string SuccessfulLoginMessage { + internal static string PasswordRequired { get { - return ResourceManager.GetString("SuccessfulLoginMessage", resourceCulture); + return ResourceManager.GetString("PasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to Logout was successful!. - /// - internal static string SuccessfulLogoutMessage { + internal static string SuccessfulUpdateUserMessage { get { - return ResourceManager.GetString("SuccessfulLogoutMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulUpdateUserMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Nodes added successfully. - /// - internal static string SuccessfulNodeAdditionMessage { + internal static string SuccessfulDeleteUserMessage { get { - return ResourceManager.GetString("SuccessfulNodeAdditionMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulDeleteUserMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to User roles updated successfuly!. - /// - internal static string SuccessfulUpdateRolesMessage { + internal static string UsernameExistsMessage { get { - return ResourceManager.GetString("SuccessfulUpdateRolesMessage", resourceCulture); + return ResourceManager.GetString("UsernameExistsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to User updated successfully!. - /// - internal static string SuccessfulUpdateUserMessage { + internal static string SucceddfulCreateUser { get { - return ResourceManager.GetString("SuccessfulUpdateUserMessage", resourceCulture); + return ResourceManager.GetString("SucceddfulCreateUser", resourceCulture); } } - /// - /// Looks up a localized string similar to Two headers have the same title!. - /// - internal static string TwoSameHeadersMessage { + internal static string EmptyRolesMessage { get { - return ResourceManager.GetString("TwoSameHeadersMessage", resourceCulture); + return ResourceManager.GetString("EmptyRolesMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Chosen username already exists. - /// - internal static string UsernameExistsMessage { + internal static string InvalidRolesListMessage { get { - return ResourceManager.GetString("UsernameExistsMessage", resourceCulture); + return ResourceManager.GetString("InvalidRolesListMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Username is required!. - /// - internal static string UsernameRequired { + internal static string SuccessfulUpdateRolesMessage { get { - return ResourceManager.GetString("UsernameRequired", resourceCulture); + return ResourceManager.GetString("SuccessfulUpdateRolesMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Could not find user!. - /// - internal static string UserNotFoundMessage { + internal static string LoginFailedMessage { get { - return ResourceManager.GetString("UserNotFoundMessage", resourceCulture); + return ResourceManager.GetString("LoginFailedMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to File is valid!. - /// - internal static string ValidFileMessage { + internal static string SuccessfulLoginMessage { get { - return ResourceManager.GetString("ValidFileMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulLoginMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered old password is wrong. - /// - internal static string WrongOldPasswordMessage { + internal static string DeleteAccountAccessErrorMessage { get { - return ResourceManager.GetString("WrongOldPasswordMessage", resourceCulture); + return ResourceManager.GetString("DeleteAccountAccessErrorMessage", resourceCulture); } } } diff --git a/RelationshipAnalysis.Integration.Test/Resources.resx b/RelationshipAnalysis.Integration.Test/Resources.resx index 4e89175..6f03822 100644 --- a/RelationshipAnalysis.Integration.Test/Resources.resx +++ b/RelationshipAnalysis.Integration.Test/Resources.resx @@ -58,7 +58,8 @@ User Deleted successfully! - diff --git a/RelationshipAnalysis.Test/RelationshipAnalysis.Test.csproj b/RelationshipAnalysis.Test/RelationshipAnalysis.Test.csproj index be8ffa8..00e70d1 100644 --- a/RelationshipAnalysis.Test/RelationshipAnalysis.Test.csproj +++ b/RelationshipAnalysis.Test/RelationshipAnalysis.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/RelationshipAnalysis.Test/Resources.Designer.cs b/RelationshipAnalysis.Test/Resources.Designer.cs index cfa7177..7b293ca 100644 --- a/RelationshipAnalysis.Test/Resources.Designer.cs +++ b/RelationshipAnalysis.Test/Resources.Designer.cs @@ -11,46 +11,32 @@ namespace RelationshipAnalysis.Test { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RelationshipAnalysis.Test.Resources", typeof(Resources).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("RelationshipAnalysis.Test.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -59,302 +45,201 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to You cant delete your account!. - /// - internal static string DeleteAccountAccessErrorMessage { + internal static string InvalidTargetNodeCategory { get { - return ResourceManager.GetString("DeleteAccountAccessErrorMessage", resourceCulture); + return ResourceManager.GetString("InvalidTargetNodeCategory", resourceCulture); } } - /// - /// Looks up a localized string similar to Chosen email already exists. - /// - internal static string EmailExistsMessage { + internal static string InvalidSourceNodeCategory { get { - return ResourceManager.GetString("EmailExistsMessage", resourceCulture); + return ResourceManager.GetString("InvalidSourceNodeCategory", resourceCulture); } } - /// - /// Looks up a localized string similar to Roles cant be empty!. - /// - internal static string EmptyRolesMessage { + internal static string InvalidEdgeCategory { get { - return ResourceManager.GetString("EmptyRolesMessage", resourceCulture); + return ResourceManager.GetString("InvalidEdgeCategory", resourceCulture); } } - /// - /// Looks up a localized string similar to Add records failed!. - /// - internal static string FailedAddRecordsMessage { + internal static string SuccessfulEdgeAdditionMessage { get { - return ResourceManager.GetString("FailedAddRecordsMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulEdgeAdditionMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Edge category is invalid!. - /// - internal static string InvalidEdgeCategory { + internal static string ValidFileMessage { get { - return ResourceManager.GetString("InvalidEdgeCategory", resourceCulture); + return ResourceManager.GetString("ValidFileMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered header is invalid. - /// - internal static string InvalidHeaderAttribute { + internal static string FailedAddRecordsMessage { get { - return ResourceManager.GetString("InvalidHeaderAttribute", resourceCulture); + return ResourceManager.GetString("FailedAddRecordsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered node category is invalid. - /// - internal static string InvalidNodeCategory { + internal static string InvalidHeaderAttribute { get { - return ResourceManager.GetString("InvalidNodeCategory", resourceCulture); + return ResourceManager.GetString("InvalidHeaderAttribute", resourceCulture); } } - /// - /// Looks up a localized string similar to Password must contain one digit from 1 to 9, one lowercase letter, one uppercase letter, one special - /// character, no space, and it must be 8-16 characters long. - /// . - /// - internal static string InvalidPasswordMessage { + internal static string TwoSameHeadersMessage { get { - return ResourceManager.GetString("InvalidPasswordMessage", resourceCulture); + return ResourceManager.GetString("TwoSameHeadersMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Roles are invalid!. - /// - internal static string InvalidRolesListMessage { + internal static string InvalidNodeCategory { get { - return ResourceManager.GetString("InvalidRolesListMessage", resourceCulture); + return ResourceManager.GetString("InvalidNodeCategory", resourceCulture); } } - /// - /// Looks up a localized string similar to Source Node category is invalid!. - /// - internal static string InvalidSourceNodeCategory { + internal static string SuccessfulNodeAdditionMessage { get { - return ResourceManager.GetString("InvalidSourceNodeCategory", resourceCulture); + return ResourceManager.GetString("SuccessfulNodeAdditionMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Target Node category is invalid!. - /// - internal static string InvalidTargetNodeCategory { + internal static string NoFileUploadedMessage { get { - return ResourceManager.GetString("InvalidTargetNodeCategory", resourceCulture); + return ResourceManager.GetString("NoFileUploadedMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Login Failed!. - /// - internal static string LoginFailedMessage { + internal static string EmailExistsMessage { get { - return ResourceManager.GetString("LoginFailedMessage", resourceCulture); + return ResourceManager.GetString("EmailExistsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to New password is required. - /// - internal static string NewPasswordRequired { + internal static string SuccessfulLogoutMessage { get { - return ResourceManager.GetString("NewPasswordRequired", resourceCulture); + return ResourceManager.GetString("SuccessfulLogoutMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to No file uploaded!. - /// - internal static string NoFileUploadedMessage { + internal static string InvalidPasswordMessage { get { - return ResourceManager.GetString("NoFileUploadedMessage", resourceCulture); + return ResourceManager.GetString("InvalidPasswordMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Category Name is not unique!. - /// - internal static string NotUniqueCategoryNameErrorMessage { + internal static string UserNotFoundMessage { get { - return ResourceManager.GetString("NotUniqueCategoryNameErrorMessage", resourceCulture); + return ResourceManager.GetString("UserNotFoundMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Input Dto can not be null!. - /// - internal static string NullDtoErrorMessage { + internal static string WrongOldPasswordMessage { get { - return ResourceManager.GetString("NullDtoErrorMessage", resourceCulture); + return ResourceManager.GetString("WrongOldPasswordMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Old password is required. - /// internal static string OldPasswordRequired { get { return ResourceManager.GetString("OldPasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to Password is required!. - /// - internal static string PasswordRequired { + internal static string NewPasswordRequired { get { - return ResourceManager.GetString("PasswordRequired", resourceCulture); + return ResourceManager.GetString("NewPasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to User Created Successfuly!. - /// - internal static string SucceddfulCreateUser { + internal static string UsernameRequired { get { - return ResourceManager.GetString("SucceddfulCreateUser", resourceCulture); + return ResourceManager.GetString("UsernameRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to Category Created successfylly!. - /// - internal static string SuccessfulCreateCategory { + internal static string PasswordRequired { get { - return ResourceManager.GetString("SuccessfulCreateCategory", resourceCulture); + return ResourceManager.GetString("PasswordRequired", resourceCulture); } } - /// - /// Looks up a localized string similar to User Deleted successfully!. - /// - internal static string SuccessfulDeleteUserMessage { + internal static string SuccessfulUpdateUserMessage { get { - return ResourceManager.GetString("SuccessfulDeleteUserMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulUpdateUserMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Edges added successfully!. - /// - internal static string SuccessfulEdgeAdditionMessage { + internal static string SuccessfulDeleteUserMessage { get { - return ResourceManager.GetString("SuccessfulEdgeAdditionMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulDeleteUserMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Login was successful!. - /// - internal static string SuccessfulLoginMessage { + internal static string UsernameExistsMessage { get { - return ResourceManager.GetString("SuccessfulLoginMessage", resourceCulture); + return ResourceManager.GetString("UsernameExistsMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Logout was successful!. - /// - internal static string SuccessfulLogoutMessage { + internal static string SucceddfulCreateUser { get { - return ResourceManager.GetString("SuccessfulLogoutMessage", resourceCulture); + return ResourceManager.GetString("SucceddfulCreateUser", resourceCulture); } } - /// - /// Looks up a localized string similar to Nodes added successfully. - /// - internal static string SuccessfulNodeAdditionMessage { + internal static string EmptyRolesMessage { get { - return ResourceManager.GetString("SuccessfulNodeAdditionMessage", resourceCulture); + return ResourceManager.GetString("EmptyRolesMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to User roles updated successfuly!. - /// - internal static string SuccessfulUpdateRolesMessage { + internal static string InvalidRolesListMessage { get { - return ResourceManager.GetString("SuccessfulUpdateRolesMessage", resourceCulture); + return ResourceManager.GetString("InvalidRolesListMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to User updated successfully!. - /// - internal static string SuccessfulUpdateUserMessage { + internal static string SuccessfulUpdateRolesMessage { get { - return ResourceManager.GetString("SuccessfulUpdateUserMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulUpdateRolesMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Two headers have the same title!. - /// - internal static string TwoSameHeadersMessage { + internal static string LoginFailedMessage { get { - return ResourceManager.GetString("TwoSameHeadersMessage", resourceCulture); + return ResourceManager.GetString("LoginFailedMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Chosen username already exists. - /// - internal static string UsernameExistsMessage { + internal static string SuccessfulLoginMessage { get { - return ResourceManager.GetString("UsernameExistsMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulLoginMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Username is required!. - /// - internal static string UsernameRequired { + internal static string DeleteAccountAccessErrorMessage { get { - return ResourceManager.GetString("UsernameRequired", resourceCulture); + return ResourceManager.GetString("DeleteAccountAccessErrorMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Could not find user!. - /// - internal static string UserNotFoundMessage { + internal static string NullDtoErrorMessage { get { - return ResourceManager.GetString("UserNotFoundMessage", resourceCulture); + return ResourceManager.GetString("NullDtoErrorMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to File is valid!. - /// - internal static string ValidFileMessage { + internal static string NotUniqueCategoryNameErrorMessage { get { - return ResourceManager.GetString("ValidFileMessage", resourceCulture); + return ResourceManager.GetString("NotUniqueCategoryNameErrorMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to Entered old password is wrong. - /// - internal static string WrongOldPasswordMessage { + internal static string SuccessfulCreateCategory { get { - return ResourceManager.GetString("WrongOldPasswordMessage", resourceCulture); + return ResourceManager.GetString("SuccessfulCreateCategory", resourceCulture); } } } diff --git a/RelationshipAnalysis.Test/Resources.resx b/RelationshipAnalysis.Test/Resources.resx index 6b1634d..a3c6f68 100644 --- a/RelationshipAnalysis.Test/Resources.resx +++ b/RelationshipAnalysis.Test/Resources.resx @@ -71,7 +71,8 @@ User Deleted successfully! - diff --git a/RelationshipAnalysis.Test/Services/AuthServices/LoginServiceTests.cs b/RelationshipAnalysis.Test/Services/AuthServices/LoginServiceTests.cs index 56b6984..e29e1ca 100644 --- a/RelationshipAnalysis.Test/Services/AuthServices/LoginServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/AuthServices/LoginServiceTests.cs @@ -115,4 +115,5 @@ // Assert.Equal(StatusCodeType.Unauthorized, result.StatusCode); // Assert.Equal("Login Failed!", result.Data.Message); // } -// } \ No newline at end of file +// } + diff --git a/RelationshipAnalysis.Test/Services/CRUD/Permissions/PermissionsReceiverTests.cs b/RelationshipAnalysis.Test/Services/CRUD/Permissions/PermissionsReceiverTests.cs index 5880817..7f154c3 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/Permissions/PermissionsReceiverTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/Permissions/PermissionsReceiverTests.cs @@ -7,10 +7,9 @@ namespace RelationshipAnalysis.Test.Services.CRUD.Permissions; public class PermissionsReceiverTests { - private readonly PermissionsReceiver _sut; - private readonly Mock _roleReceiverMock; - private readonly List _expectedPermissions = ["Read", "Write", "Delete"]; + private readonly Mock _roleReceiverMock; + private readonly PermissionsReceiver _sut; public PermissionsReceiverTests() { diff --git a/RelationshipAnalysis.Test/Services/CRUD/Role/RoleReceiverTests.cs b/RelationshipAnalysis.Test/Services/CRUD/Role/RoleReceiverTests.cs index 6f1f6b7..b0297cf 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/Role/RoleReceiverTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/Role/RoleReceiverTests.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; -using RelationshipAnalysis.Models.Auth; using RelationshipAnalysis.Services.CRUD.Role; namespace RelationshipAnalysis.Test.Services.CRUD.Role; @@ -35,18 +34,18 @@ private void SeedDatabase() context.Roles.AddRange(new List { - new Models.Auth.Role { Id = 1, Name = "Admin", Permissions = "" }, - new Models.Auth.Role { Id = 2, Name = "User", Permissions = "" } + new() { Id = 1, Name = "Admin", Permissions = "" }, + new() { Id = 2, Name = "User", Permissions = "" } }); context.Users.AddRange(new List { - new Models.Auth.User + new() { Id = 1, Username = "user1", Email = "user1@example.com", PasswordHash = "hash1", FirstName = "User", LastName = "One" }, - new Models.Auth.User + new() { Id = 2, Username = "user2", Email = "user2@example.com", PasswordHash = "hash2", FirstName = "User", LastName = "Two" @@ -55,9 +54,9 @@ private void SeedDatabase() context.UserRoles.AddRange(new List { - new Models.Auth.UserRole { UserId = 1, RoleId = 1 }, - new Models.Auth.UserRole { UserId = 1, RoleId = 2 }, - new Models.Auth.UserRole { UserId = 2, RoleId = 2 } + new() { UserId = 1, RoleId = 1 }, + new() { UserId = 1, RoleId = 2 }, + new() { UserId = 2, RoleId = 2 } }); context.SaveChanges(); diff --git a/RelationshipAnalysis.Test/Services/CRUD/User/UserAdderTests.cs b/RelationshipAnalysis.Test/Services/CRUD/User/UserAdderTests.cs index 0062b10..b6990b1 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/User/UserAdderTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/User/UserAdderTests.cs @@ -33,7 +33,7 @@ private void SeedDatabase() var context = scope.ServiceProvider.GetRequiredService(); context.Users.AddRange(new List { - new Models.Auth.User + new() { Id = 1, Username = "existinguser1", @@ -42,7 +42,7 @@ private void SeedDatabase() FirstName = "Jane", LastName = "Doe" }, - new Models.Auth.User + new() { Id = 2, Username = "existinguser2", diff --git a/RelationshipAnalysis.Test/Services/CRUD/User/UserDeleterTests.cs b/RelationshipAnalysis.Test/Services/CRUD/User/UserDeleterTests.cs index 60a1389..37df164 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/User/UserDeleterTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/User/UserDeleterTests.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.User; -using RelationshipAnalysis.Services.CRUD.User.Abstraction; namespace RelationshipAnalysis.Test.Services.CRUD.User; @@ -35,12 +34,12 @@ private void SeedDatabase() context.Users.AddRange(new List { - new Models.Auth.User + new() { Id = 1, Username = "user1", Email = "user1@example.com", PasswordHash = "hash1", FirstName = "User", LastName = "One" }, - new Models.Auth.User + new() { Id = 2, Username = "user2", Email = "user2@example.com", PasswordHash = "hash2", FirstName = "User", LastName = "Two" diff --git a/RelationshipAnalysis.Test/Services/CRUD/User/UserUpdaterTests.cs b/RelationshipAnalysis.Test/Services/CRUD/User/UserUpdaterTests.cs index d0b6dcb..278c545 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/User/UserUpdaterTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/User/UserUpdaterTests.cs @@ -6,85 +6,85 @@ namespace RelationshipAnalysis.Test.Services.CRUD.User; public class UserUpdaterTests - { - private readonly IServiceProvider _serviceProvider; - private readonly UserUpdater _sut; - - public UserUpdaterTests() - { - var serviceCollection = new ServiceCollection(); - - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(Guid.NewGuid().ToString()) - .Options; +{ + private readonly IServiceProvider _serviceProvider; + private readonly UserUpdater _sut; - serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + public UserUpdaterTests() + { + var serviceCollection = new ServiceCollection(); - _serviceProvider = serviceCollection.BuildServiceProvider(); - _sut = new UserUpdater(_serviceProvider); + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; - SeedDatabase(); - } + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); - private void SeedDatabase() - { - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new UserUpdater(_serviceProvider); - var testUsers = new List - { - new() - { - Id = 1, - Username = "user1", - Email = "user1@example.com", - PasswordHash = "hashedpassword1", - FirstName = "Jane", - LastName = "Doe" - }, - new() - { - Id = 2, - Username = "user2", - Email = "user2@example.com", - PasswordHash = "hashedpassword2", - FirstName = "John", - LastName = "Smith" - } - }; + SeedDatabase(); + } - context.Users.AddRange(testUsers); - context.SaveChanges(); - } + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); - [Fact] - public async Task UpdateUserAsync_ShouldUpdateExistingUser() + var testUsers = new List { - // Arrange - var userToUpdate = new Models.Auth.User + new() { Id = 1, - Username = "user1_updated", - Email = "user1_updated@example.com", - PasswordHash = "newhashedpassword1", + Username = "user1", + Email = "user1@example.com", + PasswordHash = "hashedpassword1", FirstName = "Jane", LastName = "Doe" - }; + }, + new() + { + Id = 2, + Username = "user2", + Email = "user2@example.com", + PasswordHash = "hashedpassword2", + FirstName = "John", + LastName = "Smith" + } + }; + + context.Users.AddRange(testUsers); + context.SaveChanges(); + } + + [Fact] + public async Task UpdateUserAsync_ShouldUpdateExistingUser() + { + // Arrange + var userToUpdate = new Models.Auth.User + { + Id = 1, + Username = "user1_updated", + Email = "user1_updated@example.com", + PasswordHash = "newhashedpassword1", + FirstName = "Jane", + LastName = "Doe" + }; - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - context.Users.Update(userToUpdate); - await context.SaveChangesAsync(); + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.Users.Update(userToUpdate); + await context.SaveChangesAsync(); - // Act - await _sut.UpdateUserAsync(userToUpdate); + // Act + await _sut.UpdateUserAsync(userToUpdate); - // Assert - var updatedUser = await context.Users.FindAsync(userToUpdate.Id); + // Assert + var updatedUser = await context.Users.FindAsync(userToUpdate.Id); - Assert.NotNull(updatedUser); - Assert.Equal(userToUpdate.Username, updatedUser.Username); - Assert.Equal(userToUpdate.Email, updatedUser.Email); - Assert.Equal(userToUpdate.PasswordHash, updatedUser.PasswordHash); - } - } \ No newline at end of file + Assert.NotNull(updatedUser); + Assert.Equal(userToUpdate.Username, updatedUser.Username); + Assert.Equal(userToUpdate.Email, updatedUser.Email); + Assert.Equal(userToUpdate.PasswordHash, updatedUser.PasswordHash); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesAdderTests.cs b/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesAdderTests.cs index 1452acc..b560c88 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesAdderTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesAdderTests.cs @@ -6,71 +6,71 @@ namespace RelationshipAnalysis.Test.Services.CRUD.UserRole; public class UserRolesAdderTests - { - private readonly IServiceProvider _serviceProvider; - private readonly UserRolesAdder _sut; +{ + private readonly IServiceProvider _serviceProvider; + private readonly UserRolesAdder _sut; - public UserRolesAdderTests() - { - var serviceCollection = new ServiceCollection(); + public UserRolesAdderTests() + { + var serviceCollection = new ServiceCollection(); - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(Guid.NewGuid().ToString()) - .UseLazyLoadingProxies() - .Options; + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .UseLazyLoadingProxies() + .Options; - serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); - _serviceProvider = serviceCollection.BuildServiceProvider(); - _sut = new UserRolesAdder(_serviceProvider); + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new UserRolesAdder(_serviceProvider); - SeedDatabase(); - } + SeedDatabase(); + } - private void SeedDatabase() + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.Users.Add(new Models.Auth.User + { + Id = 1, + Username = "existinguser", + Email = "existing@example.com", + PasswordHash = "hashedpassword", + FirstName = "Jane", + LastName = "Doe" + }); + context.Roles.AddRange(new List { - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - context.Users.Add(new Models.Auth.User - { - Id = 1, - Username = "existinguser", - Email = "existing@example.com", - PasswordHash = "hashedpassword", - FirstName = "Jane", - LastName = "Doe" - }); - context.Roles.AddRange(new List - { - new Models.Auth.Role { Id = 1, Name = "Admin", Permissions = "[]" }, - new Models.Auth.Role { Id = 2, Name = "User", Permissions = "[]" } - }); - context.SaveChanges(); - } + new() { Id = 1, Name = "Admin", Permissions = "[]" }, + new() { Id = 2, Name = "User", Permissions = "[]" } + }); + context.SaveChanges(); + } - [Fact] - public async Task AddUserRoles_ShouldAddRolesToUser() + [Fact] + public async Task AddUserRoles_ShouldAddRolesToUser() + { + // Arrange + var user = new Models.Auth.User { Id = 1 }; + var roles = new List { - // Arrange - var user = new Models.Auth.User { Id = 1 }; - var roles = new List - { - new Models.Auth.Role { Id = 1, Name = "Admin" }, - new Models.Auth.Role { Id = 2, Name = "User" } - }; + new() { Id = 1, Name = "Admin" }, + new() { Id = 2, Name = "User" } + }; - // Act - await _sut.AddUserRoles(roles, user); + // Act + await _sut.AddUserRoles(roles, user); - // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - var userRoles = await context.UserRoles - .Where(ur => ur.UserId == user.Id) - .ToListAsync(); + // Assert + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var userRoles = await context.UserRoles + .Where(ur => ur.UserId == user.Id) + .ToListAsync(); - Assert.Equal(roles.Count, userRoles.Count); - Assert.Contains(userRoles, ur => ur.RoleId == 1); - Assert.Contains(userRoles, ur => ur.RoleId == 2); - } - } \ No newline at end of file + Assert.Equal(roles.Count, userRoles.Count); + Assert.Contains(userRoles, ur => ur.RoleId == 1); + Assert.Contains(userRoles, ur => ur.RoleId == 2); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesRemoverTests.cs b/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesRemoverTests.cs index b50d0c3..023454e 100644 --- a/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesRemoverTests.cs +++ b/RelationshipAnalysis.Test/Services/CRUD/UserRole/UserRolesRemoverTests.cs @@ -6,93 +6,93 @@ namespace RelationshipAnalysis.Test.Services.CRUD.UserRole; public class UserRolesRemoverTests +{ + private readonly IServiceProvider _serviceProvider; + private readonly UserRolesRemover _sut; + + public UserRolesRemoverTests() { - private readonly IServiceProvider _serviceProvider; - private readonly UserRolesRemover _sut; + var serviceCollection = new ServiceCollection(); - public UserRolesRemoverTests() - { - var serviceCollection = new ServiceCollection(); + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .UseLazyLoadingProxies() + .Options; - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(Guid.NewGuid().ToString()) - .UseLazyLoadingProxies() - .Options; + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); - serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new UserRolesRemover(_serviceProvider); - _serviceProvider = serviceCollection.BuildServiceProvider(); - _sut = new UserRolesRemover(_serviceProvider); + SeedDatabase(); + } - SeedDatabase(); - } + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); - private void SeedDatabase() + context.Users.Add(new Models.Auth.User { - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - - context.Users.Add(new Models.Auth.User - { - Id = 1, - Username = "existinguser", - Email = "existing@example.com", - PasswordHash = "hashedpassword", - FirstName = "Jane", - LastName = "Doe" - }); - - context.Roles.AddRange(new List - { - new Models.Auth.Role { Id = 1, Name = "Admin", Permissions = "[]" }, - new Models.Auth.Role { Id = 2, Name = "User", Permissions = "[]" } - }); - - context.UserRoles.AddRange(new List - { - new Models.Auth.UserRole { UserId = 1, RoleId = 1 }, - new Models.Auth.UserRole { UserId = 1, RoleId = 2 } - }); - - context.SaveChanges(); - } - - [Fact] - public async Task RemoveUserRoles_ShouldRemoveRolesFromUser() + Id = 1, + Username = "existinguser", + Email = "existing@example.com", + PasswordHash = "hashedpassword", + FirstName = "Jane", + LastName = "Doe" + }); + + context.Roles.AddRange(new List + { + new() { Id = 1, Name = "Admin", Permissions = "[]" }, + new() { Id = 2, Name = "User", Permissions = "[]" } + }); + + context.UserRoles.AddRange(new List { - // Arrange - var user = new Models.Auth.User { Id = 1 }; + new() { UserId = 1, RoleId = 1 }, + new() { UserId = 1, RoleId = 2 } + }); - // Act - await _sut.RemoveUserRoles(user); + context.SaveChanges(); + } - // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - var userRoles = await context.UserRoles - .Where(ur => ur.UserId == user.Id) - .ToListAsync(); + [Fact] + public async Task RemoveUserRoles_ShouldRemoveRolesFromUser() + { + // Arrange + var user = new Models.Auth.User { Id = 1 }; - Assert.Empty(userRoles); - } + // Act + await _sut.RemoveUserRoles(user); - [Fact] - public async Task RemoveUserRoles_ShouldNotAffectOtherUsers() - { - // Arrange - var user1 = new Models.Auth.User { Id = 1 }; - var user2 = new Models.Auth.User { Id = 2 }; - - // Act - await _sut.RemoveUserRoles(user1); - - // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - var user2Roles = await context.UserRoles - .Where(ur => ur.UserId == user2.Id) - .ToListAsync(); - - Assert.Empty(user2Roles); - } - } \ No newline at end of file + // Assert + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var userRoles = await context.UserRoles + .Where(ur => ur.UserId == user.Id) + .ToListAsync(); + + Assert.Empty(userRoles); + } + + [Fact] + public async Task RemoveUserRoles_ShouldNotAffectOtherUsers() + { + // Arrange + var user1 = new Models.Auth.User { Id = 1 }; + var user2 = new Models.Auth.User { Id = 2 }; + + // Act + await _sut.RemoveUserRoles(user1); + + // Assert + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var user2Roles = await context.UserRoles + .Where(ur => ur.UserId == user2.Id) + .ToListAsync(); + + Assert.Empty(user2Roles); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Edge/ContextEdgesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Edge/ContextEdgesAdditionServiceTests.cs index b6f76db..a57e8b9 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Edge/ContextEdgesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Edge/ContextEdgesAdditionServiceTests.cs @@ -14,8 +14,9 @@ namespace RelationshipAnalysis.Test.Services.GraphServices.Edge; public class ContextEdgesAdditionServiceTests { - private IContextEdgesAdditionService _sut; private readonly IServiceProvider _serviceProvider; + private IContextEdgesAdditionService _sut; + public ContextEdgesAdditionServiceTests() { var serviceCollection = new ServiceCollection(); @@ -28,17 +29,16 @@ public ContextEdgesAdditionServiceTests() serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); _serviceProvider = serviceCollection.BuildServiceProvider(); - } - - + + [Fact] public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() { // Arrange - + var additionServiceMock = new Mock(); - + additionServiceMock.Setup(s => s.AddSingleEdge( It.IsAny(), It.IsAny>(), @@ -49,22 +49,27 @@ public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAd It.IsAny(), It.IsAny() )).ThrowsAsync(new Exception("Custom exception message")); - + _sut = new ContextEdgesAdditionService(new MessageResponseCreator(), additionServiceMock.Object); using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - - + + var nodeCategory = new NodeCategory { NodeCategoryId = 1 }; var edgeCategory = new EdgeCategory { EdgeCategoryId = 1 }; - var objects = new List { new Dictionary() { - { "UniqueEdge", "TestEdge" }, - { "SourceNode", "acc1" }, - { "TargetNode", "acc2" }, - { "Attribute1", "Value1" } - } }; + var objects = new List + { + new Dictionary + { + { "UniqueEdge", "TestEdge" }, + { "SourceNode", "acc1" }, + { "TargetNode", "acc2" }, + { "Attribute1", "Value1" } + } + }; // Act - var result = await _sut.AddToContext(context, edgeCategory, nodeCategory, nodeCategory, objects, new UploadEdgeDto()); + var result = await _sut.AddToContext(context, edgeCategory, nodeCategory, nodeCategory, objects, + new UploadEdgeDto()); // Assert Assert.Equal(0, context.Edges.Count()); Assert.Equal("Custom exception message", result.Data.Message); diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgesAdditionServiceTests.cs index 3e0ff49..7b3504e 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgesAdditionServiceTests.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.DependencyInjection; -using Moq; using NSubstitute; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; @@ -74,7 +73,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenUniqueHeaderIsInvalid() .Returns(expected); var processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -109,7 +109,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenUniqueSourceHeaderIsInvali .Returns(expected); var processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -145,7 +146,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenUniqueTargetHeaderIsInvali ICsvProcessorService processorMock; processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -179,7 +181,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenEdgeCategoryIsInvalid() var validatorMock = Substitute.For(); var processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -212,7 +215,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenSourceNodeCategoryIsInvali var validatorMock = Substitute.For(); var processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -245,7 +249,8 @@ public async Task AddEdges_ShouldReturnBadRequest_WhenTargetNodeCategoryIsInvali var validatorMock = Substitute.For(); var processorMock = Substitute.For(); var additionServiceMock = Substitute.For(); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { @@ -282,8 +287,10 @@ public async Task AddEdges_ShouldReturnSuccess_WhenNodeDtoIsValid() processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List()); var additionServiceMock = Substitute.For(); additionServiceMock.AddToContext(Arg.Any(), Arg.Any(), - Arg.Any(), Arg.Any(), Arg.Any>(), Arg.Any()).Returns(expected); - _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, new MessageResponseCreator()); + Arg.Any(), Arg.Any(), Arg.Any>(), Arg.Any()) + .Returns(expected); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock, + new MessageResponseCreator()); // Act var result = await _sut.AddEdges(new UploadEdgeDto { diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Edge/SingleEdgeAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Edge/SingleEdgeAdditionServiceTests.cs index 0af720c..f4f53f1 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Edge/SingleEdgeAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Edge/SingleEdgeAdditionServiceTests.cs @@ -1,8 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Moq; using NSubstitute; -using NSubstitute.Exceptions; using RelationshipAnalysis.Context; using RelationshipAnalysis.Models.Graph.Edge; using RelationshipAnalysis.Models.Graph.Node; @@ -15,7 +13,8 @@ public class SingleEdgeAdditionServiceTests { private readonly IServiceProvider _serviceProvider; private readonly SingleEdgeAdditionService _sut; - private IEdgeValueAdditionService _edgeValueAdditionService; + private readonly IEdgeValueAdditionService _edgeValueAdditionService; + public SingleEdgeAdditionServiceTests() { var serviceCollection = new ServiceCollection(); @@ -108,8 +107,8 @@ public async Task AddSingleEdge_ShouldCallAddKvpToValues_WhenValidRecordIsProvid Assert.Equal(2, edge.EdgeDestinationNodeId); Assert.Equal(1, edge.EdgeCategoryId); - _edgeValueAdditionService.Received().AddKvpToValues(context, Arg.Any>(), Arg.Any()); - + _edgeValueAdditionService.Received().AddKvpToValues(context, Arg.Any>(), + Arg.Any()); } // // [Fact] @@ -264,6 +263,7 @@ public async Task AddSingleEdge_ShouldThrowException_WhenTargetNodeDoesNotExist( // Assert await Assert.ThrowsAsync(action); } + // // [Fact] // public async Task AddSingleEdge_ShouldThrowException_WhenEdgeValueAlreadyExists() diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphDtoCreatorTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphDtoCreatorTests.cs index 1b4fe62..8cb0df2 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphDtoCreatorTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphDtoCreatorTests.cs @@ -1,3 +1,4 @@ +using RelationshipAnalysis.Models.Graph.Node; using RelationshipAnalysis.Services.GraphServices.Graph; namespace RelationshipAnalysis.Test.Services.GraphServices.Graph; @@ -17,14 +18,22 @@ public void CreateResultGraphDto_ShouldReturnGraphDto_WithCorrectNodesAndEdges() // Arrange var contextNodes = new List { - new Models.Graph.Node.Node { NodeId = 1, NodeCategory = new Models.Graph.Node.NodeCategory { NodeCategoryName = "Category1" }, NodeUniqueString = "Unique1" }, - new Models.Graph.Node.Node { NodeId = 2, NodeCategory = new Models.Graph.Node.NodeCategory { NodeCategoryName = "Category2" }, NodeUniqueString = "Unique2" } + new() + { + NodeId = 1, NodeCategory = new NodeCategory { NodeCategoryName = "Category1" }, + NodeUniqueString = "Unique1" + }, + new() + { + NodeId = 2, NodeCategory = new NodeCategory { NodeCategoryName = "Category2" }, + NodeUniqueString = "Unique2" + } }; var contextEdges = new List { - new Models.Graph.Edge.Edge { EdgeId = 1, EdgeSourceNodeId = 1, EdgeDestinationNodeId = 2 }, - new Models.Graph.Edge.Edge { EdgeId = 2, EdgeSourceNodeId = 2, EdgeDestinationNodeId = 1 } + new() { EdgeId = 1, EdgeSourceNodeId = 1, EdgeDestinationNodeId = 2 }, + new() { EdgeId = 2, EdgeSourceNodeId = 2, EdgeDestinationNodeId = 1 } }; // Act @@ -37,7 +46,7 @@ public void CreateResultGraphDto_ShouldReturnGraphDto_WithCorrectNodesAndEdges() Assert.Equal("1", result.Nodes[0].id); Assert.Equal("Category1/Unique1", result.Nodes[0].label); - + Assert.Equal("2", result.Nodes[1].id); Assert.Equal("Category2/Unique2", result.Nodes[1].label); @@ -49,7 +58,7 @@ public void CreateResultGraphDto_ShouldReturnGraphDto_WithCorrectNodesAndEdges() Assert.Equal("2", result.Edges[1].source); Assert.Equal("1", result.Edges[1].target); } - + [Fact] public void CreateResultGraphDto_ShouldThrowException_WhenContextNodesAndEdgesAreNull() { @@ -58,7 +67,7 @@ public void CreateResultGraphDto_ShouldThrowException_WhenContextNodesAndEdgesAr List contextEdges = null; // Act - var action = () => _graphDtoCreator.CreateResultGraphDto(contextNodes, contextEdges); + var action = () => _graphDtoCreator.CreateResultGraphDto(contextNodes, contextEdges); // Assert Assert.Throws(action); diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphReceiverTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphReceiverTests.cs index ec751ad..f804fc3 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphReceiverTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Graph/GraphReceiverTests.cs @@ -27,7 +27,6 @@ public GraphReceiverTests() serviceCollection.AddScoped(_ => _context); _serviceProvider = serviceCollection.BuildServiceProvider(); - } [Fact] @@ -99,14 +98,15 @@ public async Task GetGraph_ShouldReturnGraph_WhenDatabaseHasData() } }; - + var allNodes = await _context.Nodes.ToListAsync(); var allEdges = await _context.Edges.ToListAsync(); var graphDtoCreatorMock = Substitute.For(); - - graphDtoCreatorMock.CreateResultGraphDto(Arg.Any>(), Arg.Any>()) + + graphDtoCreatorMock.CreateResultGraphDto(Arg.Any>(), + Arg.Any>()) .Returns(new GraphDto { Edges = expectedEdges, Nodes = expectedNodes }); - + // Act _sut = new GraphReceiver(_serviceProvider, graphDtoCreatorMock); var resultGraph = await _sut.GetGraph(); diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Node/ContextNodesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Node/ContextNodesAdditionServiceTests.cs index c8912ae..c002d35 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Node/ContextNodesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Node/ContextNodesAdditionServiceTests.cs @@ -1,11 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; using Moq; using NSubstitute; using RelationshipAnalysis.Context; -using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Graph.Node; using RelationshipAnalysis.Services; @@ -16,8 +14,9 @@ namespace RelationshipAnalysis.Test.Services.GraphServices.Node; public class ContextNodesAdditionServiceTests { - private IContextNodesAdditionService _sut; private readonly IServiceProvider _serviceProvider; + private IContextNodesAdditionService _sut; + public ContextNodesAdditionServiceTests() { var serviceCollection = new ServiceCollection(); @@ -30,27 +29,30 @@ public ContextNodesAdditionServiceTests() serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); _serviceProvider = serviceCollection.BuildServiceProvider(); - } - + [Fact] public async Task AddToContext_ShouldReturnSuccess_WhenDataIsValid() { // Arrange - + using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); var nodeCategory = new NodeCategory { NodeCategoryId = 1 }; - var objects = new List { new Dictionary() { - { "UniqueEdge", "TestEdge" }, - { "SourceNode", "acc1" }, - { "TargetNode", "acc2" }, - { "Attribute1", "Value1" } - } }; + var objects = new List + { + new Dictionary + { + { "UniqueEdge", "TestEdge" }, + { "SourceNode", "acc1" }, + { "TargetNode", "acc2" }, + { "Attribute1", "Value1" } + } + }; var singleNodeAdditionService = Substitute.For(); - + _sut = new ContextNodesAdditionService(new MessageResponseCreator(), singleNodeAdditionService); // Act var result = await _sut.AddToContext("UniqueEdge", context, objects, nodeCategory); @@ -58,6 +60,7 @@ public async Task AddToContext_ShouldReturnSuccess_WhenDataIsValid() // Assert Assert.Equal(StatusCodeType.Success, result.StatusCode); } + [Fact] public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() { @@ -74,10 +77,10 @@ public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAd .ThrowsAsync(new Exception("Custom exception message")); _sut = new ContextNodesAdditionService(new MessageResponseCreator(), additionServiceMock.Object); - + using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - var newNodeCategory = new NodeCategory() + var newNodeCategory = new NodeCategory { NodeCategoryId = 1, NodeCategoryName = "Account" @@ -85,7 +88,7 @@ public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAd context.NodeCategories.Add(newNodeCategory); await context.SaveChangesAsync(); // Act - var result = await _sut.AddToContext("AccountID", context, new List() + var result = await _sut.AddToContext("AccountID", context, new List { new Dictionary { @@ -100,11 +103,9 @@ public async Task AddToContext_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAd { "IBAN", "IR033880987114000000028" } } }, newNodeCategory); - + // Assert Assert.Equal(0, context.Nodes.Count()); Assert.Equal("Custom exception message", result.Data.Message); } - - } \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Node/NodesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Node/NodesAdditionServiceTests.cs index f4db49a..972cdfa 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Node/NodesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Node/NodesAdditionServiceTests.cs @@ -1,9 +1,7 @@ -using System.Runtime.InteropServices.JavaScript; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.DependencyInjection; -using Moq; using NSubstitute; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; @@ -20,10 +18,12 @@ namespace RelationshipAnalysis.Test.Services.GraphServices.Node; public class NodesAdditionServiceTests { + private readonly IContextNodesAdditionService _contextAdditionServiceMock = + Substitute.For(); + + private readonly IMessageResponseCreator _responseCreator = new MessageResponseCreator(); private readonly IServiceProvider _serviceProvider; private INodesAdditionService _sut; - private readonly IContextNodesAdditionService _contextAdditionServiceMock = Substitute.For(); - private readonly IMessageResponseCreator _responseCreator = new MessageResponseCreator(); public NodesAdditionServiceTests() { @@ -39,9 +39,10 @@ public NodesAdditionServiceTests() _serviceProvider = serviceCollection.BuildServiceProvider(); _contextAdditionServiceMock.AddToContext(Arg.Any(), Arg.Any(), - Arg.Any>(),Arg.Any()).Returns(_responseCreator.Create(StatusCodeType.Success, Resources.SuccessfulNodeAdditionMessage)); + Arg.Any>(), Arg.Any()) + .Returns(_responseCreator.Create(StatusCodeType.Success, Resources.SuccessfulNodeAdditionMessage)); + - SeedDatabase(); } @@ -57,8 +58,7 @@ private void SeedDatabase() context.SaveChanges(); } - - + [Fact] public async Task AddNodes_ShouldReturnBadRequest_WhenUniqueHeaderIsInvalid() { @@ -78,7 +78,8 @@ public async Task AddNodes_ShouldReturnBadRequest_WhenUniqueHeaderIsInvalid() validatorMock.Validate(fileToBeSend, "SomeHeaderThatDoesntExist") .Returns(expected); var processorMock = Substitute.For(); - _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, _contextAdditionServiceMock); + _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, + _contextAdditionServiceMock); // Act var result = await _sut.AddNodes(new UploadNodeDto { @@ -107,7 +108,8 @@ public async Task AddNodes_ShouldReturnBadRequest_WhenNodeCategoryIsInvalid() var validatorMock = Substitute.For(); var processorMock = Substitute.For(); - _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, _contextAdditionServiceMock); + _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, + _contextAdditionServiceMock); // Act var result = await _sut.AddNodes(new UploadNodeDto @@ -139,7 +141,8 @@ public async Task AddNodes_ShouldReturnSuccess_WhenNodeDtoIsValid() validatorMock.Validate(fileToBeSend, "AccountID").Returns(expected); var processorMock = Substitute.For(); processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List()); - _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, _contextAdditionServiceMock); + _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, _responseCreator, + _contextAdditionServiceMock); // Act var result = await _sut.AddNodes(new UploadNodeDto diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Node/SingleNodeAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Node/SingleNodeAdditionServiceTests.cs index de24b78..923f436 100644 --- a/RelationshipAnalysis.Test/Services/GraphServices/Node/SingleNodeAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/GraphServices/Node/SingleNodeAdditionServiceTests.cs @@ -12,8 +12,8 @@ namespace RelationshipAnalysis.Test.Services.GraphServices.Node; public class SingleNodeAdditionServiceTests { private readonly IServiceProvider _serviceProvider; - private SingleNodeAdditionService _sut; private INodeValueAdditionService _nodeValueAdditionService; + private SingleNodeAdditionService _sut; public SingleNodeAdditionServiceTests() { @@ -68,16 +68,15 @@ public async Task AddSingleNode_ShouldCallTheAddFunction_WhenValidRecordIsProvid using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); _nodeValueAdditionService = Substitute.For(); - + _sut = new SingleNodeAdditionService(_nodeValueAdditionService); // Act await _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert - await _nodeValueAdditionService.Received().AddKvpToValues(Arg.Any(), Arg.Any>(), Arg.Any()); - - + await _nodeValueAdditionService.Received().AddKvpToValues(Arg.Any(), + Arg.Any>(), Arg.Any()); } [Fact] @@ -92,17 +91,17 @@ public async Task AddSingleNode_ShouldCallTheAddFunction_WhenNodeExists() using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - + _nodeValueAdditionService = Substitute.For(); - + _sut = new SingleNodeAdditionService(_nodeValueAdditionService); // Act await _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert - await _nodeValueAdditionService.Received().AddKvpToValues(Arg.Any(), Arg.Any>(), Arg.Any()); - + await _nodeValueAdditionService.Received().AddKvpToValues(Arg.Any(), + Arg.Any>(), Arg.Any()); } [Fact] @@ -117,12 +116,12 @@ public async Task AddSingleNode_ShouldThrowException_WhenUniqueNameIsEmpty() using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - + _nodeValueAdditionService = Substitute.For(); _nodeValueAdditionService.AddKvpToValues(Arg.Any(), Arg.Any>(), Arg.Any()).Throws(new Exception()); - + _sut = new SingleNodeAdditionService(_nodeValueAdditionService); // Act @@ -144,12 +143,12 @@ public async Task AddSingleNode_ShouldThrowException_WhenNodeValueAlreadyExists( using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - + _nodeValueAdditionService = Substitute.For(); _nodeValueAdditionService.AddKvpToValues(Arg.Any(), Arg.Any>(), Arg.Any()).ThrowsAsync(new Exception()); - + _sut = new SingleNodeAdditionService(_nodeValueAdditionService); diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreatorTests.cs index d50c379..cb7e38d 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreatorTests.cs @@ -13,8 +13,8 @@ public class AllUserDtoCreatorTests { private readonly Mock _mapperMock; private readonly Mock _rolesReceiverMock; - private readonly Mock _userReceiverMock; private readonly AllUserDtoCreator _sut; + private readonly Mock _userReceiverMock; public AllUserDtoCreatorTests() { @@ -31,8 +31,8 @@ public async Task Create_ShouldMapUsersAndRetrieveRolesAndUserCount() // Arrange var users = new List { - new User { Id = 1, Username = "user1", Email = "user1@example.com" }, - new User { Id = 2, Username = "user2", Email = "user2@example.com" } + new() { Id = 1, Username = "user1", Email = "user1@example.com" }, + new() { Id = 2, Username = "user2", Email = "user2@example.com" } }; _mapperMock diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceTests.cs index 17a78d4..5d3b4a3 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceTests.cs @@ -11,15 +11,16 @@ namespace RelationshipAnalysis.Test.Services.Panel.AdminPanelServices.AllUserSer public class AllUserServiceTests { - private readonly Mock _validatorMock; private readonly Mock _allUserDtoCreatorMock; private readonly RelationshipAnalysis.Services.Panel.AdminPanelServices.AllUserService.AllUserService _service; + private readonly Mock _validatorMock; public AllUserServiceTests() { _validatorMock = new Mock(); _allUserDtoCreatorMock = new Mock(); - _service = new RelationshipAnalysis.Services.Panel.AdminPanelServices.AllUserService.AllUserService(_validatorMock.Object, _allUserDtoCreatorMock.Object); + _service = new RelationshipAnalysis.Services.Panel.AdminPanelServices.AllUserService.AllUserService( + _validatorMock.Object, _allUserDtoCreatorMock.Object); } [Fact] @@ -28,7 +29,7 @@ public async Task GetAllUser_ShouldReturnSuccess_WhenValidationSucceeds() // Arrange var users = new List { - new User { Id = 1, Username = "user1", Email = "user1@example.com" } + new() { Id = 1, Username = "user1", Email = "user1@example.com" } }; var getAllUsersDto = new GetAllUsersDto { @@ -65,7 +66,7 @@ public async Task GetAllUser_ShouldReturnValidationError_WhenValidationFails() // Arrange var users = new List { - new User { Id = 1, Username = "user1", Email = "user1@example.com" } + new() { Id = 1, Username = "user1", Email = "user1@example.com" } }; _validatorMock.Setup(v => v.Validate(It.IsAny>())) diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidatorTests.cs index 14cd13b..4004e13 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidatorTests.cs @@ -20,8 +20,8 @@ public async Task Validate_ShouldReturnSuccess_WhenUsersListIsNotEmpty() // Arrange var users = new List { - new User { Id = 1, Username = "user1", Email = "user1@example.com" }, - new User { Id = 2, Username = "user2", Email = "user2@example.com" } + new() { Id = 1, Username = "user1", Email = "user1@example.com" }, + new() { Id = 2, Username = "user2", Email = "user2@example.com" } }; // Act diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/CreateUserDtoMapperTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/CreateUserDtoMapperTests.cs index 2d46d31..8b0198e 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/CreateUserDtoMapperTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/CreateUserDtoMapperTests.cs @@ -8,8 +8,8 @@ namespace RelationshipAnalysis.Test.Services.Panel.AdminPanelServices.CreateUser public class CreateUserDtoMapperTests { - private readonly Mock _passwordHasherMock; private readonly CreateUserDtoMapper _mapper; + private readonly Mock _passwordHasherMock; public CreateUserDtoMapperTests() { diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceTests.cs index 9d280b9..5fd34bd 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceTests.cs @@ -2,5 +2,4 @@ public class UserCreateServiceTests { - } \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceValidatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceValidatorTests.cs index 6731f94..7e10490 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceValidatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/CreateUserServiceTests/UserCreateServiceValidatorTests.cs @@ -1,5 +1,4 @@ -using FluentAssertions; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Moq; using RelationshipAnalysis.Context; @@ -14,8 +13,8 @@ namespace RelationshipAnalysis.Test.Services.Panel.AdminPanelServices.CreateUser public class UserCreateServiceValidatorTests { - private readonly IServiceProvider _serviceProvider; private readonly Mock _messageResponseCreatorMock; + private readonly IServiceProvider _serviceProvider; private readonly UserCreateServiceValidator _validator; public UserCreateServiceValidatorTests() @@ -43,7 +42,7 @@ private void SeedDatabase() using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - context.Users.Add(new Models.Auth.User + context.Users.Add(new User { Id = 1, Username = "user1", Email = "user1@example.com", PasswordHash = "hash1", FirstName = "User", LastName = "One" @@ -51,8 +50,8 @@ private void SeedDatabase() context.Roles.AddRange(new List { - new Role { Name = "Admin" , Permissions = ""}, - new Role { Name = "User" , Permissions = ""} + new() { Name = "Admin", Permissions = "" }, + new() { Name = "User", Permissions = "" } }); context.SaveChanges(); diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceTests.cs index 82d65d6..d754f2b 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceTests.cs @@ -9,15 +9,19 @@ namespace RelationshipAnalysis.Test.Services.Panel.AdminPanelServices.UserDelete public class UserDeleteServiceTests { - private readonly Mock _mockValidator; private readonly Mock _mockUserDeleter; - private readonly RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.UserDeleteService _userDeleteService; + private readonly Mock _mockValidator; + + private readonly RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.UserDeleteService + _userDeleteService; public UserDeleteServiceTests() { _mockValidator = new Mock(); _mockUserDeleter = new Mock(); - _userDeleteService = new RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.UserDeleteService(_mockValidator.Object, _mockUserDeleter.Object); + _userDeleteService = + new RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.UserDeleteService( + _mockValidator.Object, _mockUserDeleter.Object); } [Fact] @@ -53,7 +57,7 @@ public async Task DeleteUser_UserIsValid_DeletesUserAndReturnsSuccess() Username = "testuser", Email = "test@example.com" }; - + var validationResponse = new ActionResponse { StatusCode = StatusCodeType.Success, diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceTests.cs index 3c966c3..83f647e 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceTests.cs @@ -10,11 +10,13 @@ namespace RelationshipAnalysis.Test.Services.Panel.AdminPanelServices.UserUpdate public class UserUpdateRolesServiceTests { - private readonly Mock _mockValidator; private readonly Mock _mockRoleReceiver; private readonly Mock _mockUserRolesAdder; private readonly Mock _mockUserRolesRemover; - private readonly RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.UserUpdateRolesService _service; + private readonly Mock _mockValidator; + + private readonly + RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.UserUpdateRolesService _service; public UserUpdateRolesServiceTests() { @@ -23,11 +25,12 @@ public UserUpdateRolesServiceTests() _mockUserRolesAdder = new Mock(); _mockUserRolesRemover = new Mock(); - _service = new RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.UserUpdateRolesService( - _mockValidator.Object, - _mockRoleReceiver.Object, - _mockUserRolesAdder.Object, - _mockUserRolesRemover.Object); + _service = + new RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.UserUpdateRolesService( + _mockValidator.Object, + _mockRoleReceiver.Object, + _mockUserRolesAdder.Object, + _mockUserRolesRemover.Object); } [Fact] @@ -61,8 +64,8 @@ public async Task UpdateUserRolesAsync_ValidationSucceeds_UpdatesRolesSuccessful var newRoles = new List { "Admin", "User" }; var roleList = new List { - new Role { Name = "Admin" }, - new Role { Name = "User" } + new() { Name = "Admin" }, + new() { Name = "User" } }; _mockValidator.Setup(v => v.Validate(user, newRoles)) diff --git a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidatorTests.cs index ca4bcf4..c2d4146 100644 --- a/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidatorTests.cs @@ -41,8 +41,8 @@ private void SeedDatabase() context.Roles.AddRange(new List { - new Role { Id = 1, Name = "Admin" , Permissions = ""}, - new Role { Id = 2, Name = "User" , Permissions = ""} + new() { Id = 1, Name = "Admin", Permissions = "" }, + new() { Id = 2, Name = "User", Permissions = "" } }); context.SaveChanges(); diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceTests.cs index f20699c..62dc89e 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceTests.cs @@ -8,91 +8,92 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserInfoService; public class UserInfoServiceTests - { - private readonly Mock _userOutputInfoDtoCreatorMock; - private readonly Mock _validatorMock; - private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserInfoService.UserInfoService _sut; +{ + private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserInfoService.UserInfoService _sut; + private readonly Mock _userOutputInfoDtoCreatorMock; + private readonly Mock _validatorMock; - public UserInfoServiceTests() - { - _userOutputInfoDtoCreatorMock = new Mock(); - _validatorMock = new Mock(); - _sut = new RelationshipAnalysis.Services.Panel.UserPanelServices.UserInfoService.UserInfoService(_userOutputInfoDtoCreatorMock.Object, _validatorMock.Object); - } + public UserInfoServiceTests() + { + _userOutputInfoDtoCreatorMock = new Mock(); + _validatorMock = new Mock(); + _sut = new RelationshipAnalysis.Services.Panel.UserPanelServices.UserInfoService.UserInfoService( + _userOutputInfoDtoCreatorMock.Object, _validatorMock.Object); + } - [Fact] - public async Task GetUser_ValidationFails_ShouldReturnValidationResult() + [Fact] + public async Task GetUser_ValidationFails_ShouldReturnValidationResult() + { + // Arrange + var user = new User { Id = 1, Username = "testuser" }; + var validationResponse = new ActionResponse { - // Arrange - var user = new User { Id = 1, Username = "testuser" }; - var validationResponse = new ActionResponse - { - StatusCode = StatusCodeType.NotFound - }; + StatusCode = StatusCodeType.NotFound + }; - _validatorMock - .Setup(v => v.Validate(user)) - .ReturnsAsync(validationResponse); + _validatorMock + .Setup(v => v.Validate(user)) + .ReturnsAsync(validationResponse); - // Act - var result = await _sut.GetUser(user); + // Act + var result = await _sut.GetUser(user); - // Assert - Assert.NotNull(result); - Assert.Equal(StatusCodeType.NotFound, result.StatusCode); - Assert.Null(result.Data); - } + // Assert + Assert.NotNull(result); + Assert.Equal(StatusCodeType.NotFound, result.StatusCode); + Assert.Null(result.Data); + } - [Fact] - public async Task GetUser_ValidationSucceeds_ShouldReturnUserOutputInfoDto() + [Fact] + public async Task GetUser_ValidationSucceeds_ShouldReturnUserOutputInfoDto() + { + // Arrange + var user = new User { - // Arrange - var user = new User - { - Id = 1, - Username = "testuser", - Email = "testuser@example.com", - FirstName = "Test", - LastName = "User" - }; + Id = 1, + Username = "testuser", + Email = "testuser@example.com", + FirstName = "Test", + LastName = "User" + }; - var dto = new UserOutputInfoDto - { - Id = user.Id, - Username = user.Username, - Email = user.Email, - FirstName = user.FirstName, - LastName = user.LastName, - Roles = new List { "Role1", "Role2" } - }; + var dto = new UserOutputInfoDto + { + Id = user.Id, + Username = user.Username, + Email = user.Email, + FirstName = user.FirstName, + LastName = user.LastName, + Roles = new List { "Role1", "Role2" } + }; - var validationResponse = new ActionResponse - { - StatusCode = StatusCodeType.Success - }; + var validationResponse = new ActionResponse + { + StatusCode = StatusCodeType.Success + }; - _validatorMock - .Setup(v => v.Validate(user)) - .ReturnsAsync(validationResponse); + _validatorMock + .Setup(v => v.Validate(user)) + .ReturnsAsync(validationResponse); - _userOutputInfoDtoCreatorMock - .Setup(c => c.Create(user)) - .ReturnsAsync(dto); + _userOutputInfoDtoCreatorMock + .Setup(c => c.Create(user)) + .ReturnsAsync(dto); - // Act - var result = await _sut.GetUser(user); + // Act + var result = await _sut.GetUser(user); - // Assert - Assert.NotNull(result); - Assert.Equal(StatusCodeType.Success, result.StatusCode); - Assert.NotNull(result.Data); - Assert.Equal(user.Id, result.Data.Id); - Assert.Equal(user.Username, result.Data.Username); - Assert.Equal(user.Email, result.Data.Email); - Assert.Equal(user.FirstName, result.Data.FirstName); - Assert.Equal(user.LastName, result.Data.LastName); - Assert.Contains("Role1", result.Data.Roles); - Assert.Contains("Role2", result.Data.Roles); - Assert.Equal(2, result.Data.Roles.Count); - } - } \ No newline at end of file + // Assert + Assert.NotNull(result); + Assert.Equal(StatusCodeType.Success, result.StatusCode); + Assert.NotNull(result.Data); + Assert.Equal(user.Id, result.Data.Id); + Assert.Equal(user.Username, result.Data.Username); + Assert.Equal(user.Email, result.Data.Email); + Assert.Equal(user.FirstName, result.Data.FirstName); + Assert.Equal(user.LastName, result.Data.LastName); + Assert.Contains("Role1", result.Data.Roles); + Assert.Contains("Role2", result.Data.Roles); + Assert.Equal(2, result.Data.Roles.Count); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreatorTests.cs index dac37bc..2744733 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreatorTests.cs @@ -8,60 +8,60 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserInfoService; public class UserOutputInfoDtoCreatorTests +{ + private readonly Mock _mapperMock; + private readonly Mock _roleReceiverMock; + private readonly UserOutputInfoDtoCreator _sut; + + public UserOutputInfoDtoCreatorTests() { - private readonly Mock _mapperMock; - private readonly Mock _roleReceiverMock; - private readonly UserOutputInfoDtoCreator _sut; + _mapperMock = new Mock(); + _roleReceiverMock = new Mock(); + _sut = new UserOutputInfoDtoCreator(_mapperMock.Object, _roleReceiverMock.Object); + } - public UserOutputInfoDtoCreatorTests() + [Fact] + public async Task Create_ShouldMapUserToDtoAndRetrieveRoles() + { + // Arrange + var user = new User { - _mapperMock = new Mock(); - _roleReceiverMock = new Mock(); - _sut = new UserOutputInfoDtoCreator(_mapperMock.Object, _roleReceiverMock.Object); - } + Id = 1, + Username = "testuser", + Email = "testuser@example.com", + FirstName = "Test", + LastName = "User" + }; + var roleNames = new List { "Admin", "User" }; - [Fact] - public async Task Create_ShouldMapUserToDtoAndRetrieveRoles() - { - // Arrange - var user = new User + _mapperMock + .Setup(m => m.Map(user, It.IsAny())) + .Callback((src, dest) => { - Id = 1, - Username = "testuser", - Email = "testuser@example.com", - FirstName = "Test", - LastName = "User" - }; - var roleNames = new List { "Admin", "User" }; - - _mapperMock - .Setup(m => m.Map(user, It.IsAny())) - .Callback((src, dest) => - { - dest.Id = src.Id; - dest.Username = src.Username; - dest.Email = src.Email; - dest.FirstName = src.FirstName; - dest.LastName = src.LastName; - }); + dest.Id = src.Id; + dest.Username = src.Username; + dest.Email = src.Email; + dest.FirstName = src.FirstName; + dest.LastName = src.LastName; + }); - _roleReceiverMock - .Setup(r => r.ReceiveRoleNamesAsync(user.Id)) - .ReturnsAsync(roleNames); + _roleReceiverMock + .Setup(r => r.ReceiveRoleNamesAsync(user.Id)) + .ReturnsAsync(roleNames); - // Act - var result = await _sut.Create(user); + // Act + var result = await _sut.Create(user); - // Assert - Assert.NotNull(result); - Assert.Equal(user.Id, result.Id); - Assert.Equal(user.Username, result.Username); - Assert.Equal(user.Email, result.Email); - Assert.Equal(user.FirstName, result.FirstName); - Assert.Equal(user.LastName, result.LastName); - Assert.NotNull(result.Roles); - Assert.Contains("Admin", result.Roles); - Assert.Contains("User", result.Roles); - Assert.Equal(2, result.Roles.Count); - } - } \ No newline at end of file + // Assert + Assert.NotNull(result); + Assert.Equal(user.Id, result.Id); + Assert.Equal(user.Username, result.Username); + Assert.Equal(user.Email, result.Email); + Assert.Equal(user.FirstName, result.FirstName); + Assert.Equal(user.LastName, result.LastName); + Assert.NotNull(result.Roles); + Assert.Contains("Admin", result.Roles); + Assert.Contains("User", result.Roles); + Assert.Equal(2, result.Roles.Count); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoMapperTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoMapperTests.cs index 1f63f31..079cbde 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoMapperTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoMapperTests.cs @@ -11,10 +11,7 @@ public class UserUpdateInfoMapperTests public UserUpdateInfoMapperTests() { - var config = new MapperConfiguration(cfg => - { - cfg.AddProfile(); - }); + var config = new MapperConfiguration(cfg => { cfg.AddProfile(); }); _mapper = config.CreateMapper(); } diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceTests.cs index 1e8f610..b14bcc0 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceTests.cs @@ -13,10 +13,13 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserUpdateI public class UserUpdateInfoServiceTests { - private readonly Mock _validatorMock; - private readonly Mock _userUpdaterMock; private readonly Mock _mapperMock; - private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdateInfoService.UserUpdateInfoService _sut; + + private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdateInfoService.UserUpdateInfoService + _sut; + + private readonly Mock _userUpdaterMock; + private readonly Mock _validatorMock; public UserUpdateInfoServiceTests() { @@ -24,7 +27,8 @@ public UserUpdateInfoServiceTests() _userUpdaterMock = new Mock(); _mapperMock = new Mock(); - _sut = new RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdateInfoService.UserUpdateInfoService(_validatorMock.Object, _userUpdaterMock.Object, _mapperMock.Object); + _sut = new RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdateInfoService.UserUpdateInfoService( + _validatorMock.Object, _userUpdaterMock.Object, _mapperMock.Object); } [Fact] diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidatorTests.cs index 508c903..6a41168 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidatorTests.cs @@ -14,11 +14,11 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserUpdateI public class UserUpdateInfoServiceValidatorTests { + private readonly Mock _messageResponseCreatorMock; private readonly IServiceProvider _serviceProvider; private readonly UserUpdateInfoServiceValidator _sut; - private readonly Mock _messageResponseCreatorMock; - private readonly User _user1 = new User + private readonly User _user1 = new() { Id = 1, Username = "test", @@ -28,7 +28,7 @@ public class UserUpdateInfoServiceValidatorTests LastName = "Doe" }; - private readonly User _user2 = new User + private readonly User _user2 = new() { Id = 2, Username = "existinguser", diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceTests.cs index 34483c5..b6d0c87 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceTests.cs @@ -12,10 +12,13 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserUpdateP public class UserUpdatePasswordServiceTests { - private readonly Mock _validatorMock; - private readonly Mock _userUpdaterMock; private readonly Mock _passwordHasherMock; - private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdatePasswordService.UserUpdatePasswordService _sut; + + private readonly RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdatePasswordService. + UserUpdatePasswordService _sut; + + private readonly Mock _userUpdaterMock; + private readonly Mock _validatorMock; public UserUpdatePasswordServiceTests() { @@ -23,7 +26,9 @@ public UserUpdatePasswordServiceTests() _userUpdaterMock = new Mock(); _passwordHasherMock = new Mock(); - _sut = new RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdatePasswordService.UserUpdatePasswordService(_validatorMock.Object, _userUpdaterMock.Object, _passwordHasherMock.Object); + _sut = + new RelationshipAnalysis.Services.Panel.UserPanelServices.UserUpdatePasswordService. + UserUpdatePasswordService(_validatorMock.Object, _userUpdaterMock.Object, _passwordHasherMock.Object); } [Fact] diff --git a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidatorTests.cs b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidatorTests.cs index 1d0b83b..691a2de 100644 --- a/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidatorTests.cs +++ b/RelationshipAnalysis.Test/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidatorTests.cs @@ -12,8 +12,8 @@ namespace RelationshipAnalysis.Test.Services.Panel.UserPanelServices.UserUpdateP public class UserUpdatePasswordServiceValidatorTests { - private readonly Mock _passwordVerifierMock; private readonly Mock _messageResponseCreatorMock; + private readonly Mock _passwordVerifierMock; private readonly UserUpdatePasswordServiceValidator _sut; public UserUpdatePasswordServiceValidatorTests() diff --git a/RelationshipAnalysis/Controllers/AttributesController.cs b/RelationshipAnalysis/Controllers/AttributesController.cs index 9836a98..01c6962 100644 --- a/RelationshipAnalysis/Controllers/AttributesController.cs +++ b/RelationshipAnalysis/Controllers/AttributesController.cs @@ -1,7 +1,5 @@ -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Services.GraphServices.Abstraction; namespace RelationshipAnalysis.Controllers; @@ -9,7 +7,9 @@ namespace RelationshipAnalysis.Controllers; [Authorize] [ApiController] [Route("api/[controller]")] -public class AttributesController([FromKeyedServices("node")] IAttributesReceiver nodeAttributeReceiver,[FromKeyedServices("edge")] IAttributesReceiver edgeAttributeReceiver) : ControllerBase +public class AttributesController( + [FromKeyedServices("node")] IAttributesReceiver nodeAttributeReceiver, + [FromKeyedServices("edge")] IAttributesReceiver edgeAttributeReceiver) : ControllerBase { [HttpGet("nodes")] public async Task GetNodeAttributes(string nodeCategoryName) @@ -17,6 +17,7 @@ public async Task GetNodeAttributes(string nodeCategoryName) var result = await nodeAttributeReceiver.GetAllAttributes(nodeCategoryName); return Ok(result); } + [HttpGet("edges")] public async Task GetEdgeAttributes(string edgeCategoryName) { diff --git a/RelationshipAnalysis/Controllers/Auth/AuthController.cs b/RelationshipAnalysis/Controllers/Auth/AuthController.cs index 9d4a401..c0d312b 100644 --- a/RelationshipAnalysis/Controllers/Auth/AuthController.cs +++ b/RelationshipAnalysis/Controllers/Auth/AuthController.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using RelationshipAnalysis.Dto.Auth; using RelationshipAnalysis.Services.AuthServices.Abstraction; diff --git a/RelationshipAnalysis/Controllers/Graph/EdgeController.cs b/RelationshipAnalysis/Controllers/Graph/EdgeController.cs index 2963986..dacead8 100644 --- a/RelationshipAnalysis/Controllers/Graph/EdgeController.cs +++ b/RelationshipAnalysis/Controllers/Graph/EdgeController.cs @@ -1,7 +1,5 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Dto.Graph.Edge; using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; @@ -18,38 +16,35 @@ public class EdgeController( [FromKeyedServices("edge")] IInfoReceiver infoReceiver) : ControllerBase { - [HttpGet("categories")] public async Task GetAllEdgeCategories() { var result = await edgeCategoryReceiver.GetAllEdgeCategories(); return Ok(result); } - - + + [HttpGet] public async Task GetInfo(int edgeId) { var result = await infoReceiver.GetInfo(edgeId); return StatusCode((int)result.StatusCode, result.Data); } - + [HttpPost("categories")] public async Task CreateEdgeCategory([FromBody] CreateEdgeCategoryDto createEdgeCategoryDto) { var result = await createEdgeCategoryService.CreateEdgeCategory(createEdgeCategoryDto); return StatusCode((int)result.StatusCode, result.Data); } - + [HttpPost] public async Task UploadNode([FromForm] UploadEdgeDto uploadEdgeDto) { if (uploadEdgeDto.File == null || uploadEdgeDto.File.Length == 0) - { return BadRequest(Resources.NoFileUploadedMessage); - } var result = await edgesAdditionService.AddEdges(uploadEdgeDto); return StatusCode((int)result.StatusCode, result.Data); } -} +} \ No newline at end of file diff --git a/RelationshipAnalysis/Controllers/Graph/GraphController.cs b/RelationshipAnalysis/Controllers/Graph/GraphController.cs index 4c82f62..8a86a88 100644 --- a/RelationshipAnalysis/Controllers/Graph/GraphController.cs +++ b/RelationshipAnalysis/Controllers/Graph/GraphController.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using RelationshipAnalysis.Dto.Graph; @@ -10,7 +9,8 @@ namespace RelationshipAnalysis.Controllers.Graph; [ApiController] [Authorize] [Route("api/[controller]")] -public class GraphController(IGraphReceiver graphReceiver, +public class GraphController( + IGraphReceiver graphReceiver, IExpansionGraphReceiver expansionGraphReceiver, IGraphSearcherService searchService) : ControllerBase { @@ -19,17 +19,21 @@ public async Task GetGraph() { return Ok(await graphReceiver.GetGraph()); } - + [HttpPost] public async Task SearchGraph(SearchGraphDto searchGraphDto) { var result = await searchService.Search(searchGraphDto); return StatusCode((int)result.StatusCode, result.Data); } + [HttpGet("expansion")] - public async Task GetExpansionGraph([FromQuery] int nodeId,[FromQuery] string sourceCategoryName,[FromQuery] string targetCategoryName,[FromQuery] string edgeCategoryName) + public async Task GetExpansionGraph([FromQuery] int nodeId, [FromQuery] string sourceCategoryName, + [FromQuery] string targetCategoryName, [FromQuery] string edgeCategoryName) { - var result = await expansionGraphReceiver.GetExpansionGraph(nodeId, sourceCategoryName, targetCategoryName, edgeCategoryName); + var result = + await expansionGraphReceiver.GetExpansionGraph(nodeId, sourceCategoryName, targetCategoryName, + edgeCategoryName); return Ok(result); } } \ No newline at end of file diff --git a/RelationshipAnalysis/Controllers/Graph/NodeController.cs b/RelationshipAnalysis/Controllers/Graph/NodeController.cs index 81ed3b4..c7469a4 100644 --- a/RelationshipAnalysis/Controllers/Graph/NodeController.cs +++ b/RelationshipAnalysis/Controllers/Graph/NodeController.cs @@ -1,7 +1,5 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Dto.Graph.Node; using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Node.Abstraction; @@ -24,7 +22,7 @@ public async Task GetAllNodeCategories() var result = await nodeCategoryReceiver.GetAllNodeCategories(); return Ok(result); } - + [HttpGet] public async Task GetInfo(int nodeId) { @@ -38,16 +36,14 @@ public async Task CreateNodeCategory([FromBody] CreateNodeCategor var result = await createNodeCategoryService.CreateNodeCategory(createNodeCategoryDto); return StatusCode((int)result.StatusCode, result.Data); } - + [HttpPost] public async Task UploadNode([FromForm] UploadNodeDto uploadNodeDto) { if (uploadNodeDto.File == null || uploadNodeDto.File.Length == 0) - { return BadRequest(Resources.NoFileUploadedMessage); - } var result = await nodesAdditionService.AddNodes(uploadNodeDto); return StatusCode((int)result.StatusCode, result.Data); } -} +} \ No newline at end of file diff --git a/RelationshipAnalysis/Controllers/Panel/AdminController.cs b/RelationshipAnalysis/Controllers/Panel/AdminController.cs index 85d4c37..50f7543 100644 --- a/RelationshipAnalysis/Controllers/Panel/AdminController.cs +++ b/RelationshipAnalysis/Controllers/Panel/AdminController.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Dto.Panel.User; diff --git a/RelationshipAnalysis/Controllers/Panel/UserController.cs b/RelationshipAnalysis/Controllers/Panel/UserController.cs index 3095daa..7ddc7c2 100644 --- a/RelationshipAnalysis/Controllers/Panel/UserController.cs +++ b/RelationshipAnalysis/Controllers/Panel/UserController.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using RelationshipAnalysis.Dto; diff --git a/RelationshipAnalysis/Dto/Graph/Edge/UploadEdgeDto.cs b/RelationshipAnalysis/Dto/Graph/Edge/UploadEdgeDto.cs index c45b95f..900bad0 100644 --- a/RelationshipAnalysis/Dto/Graph/Edge/UploadEdgeDto.cs +++ b/RelationshipAnalysis/Dto/Graph/Edge/UploadEdgeDto.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Http; namespace RelationshipAnalysis.Dto.Graph.Edge; diff --git a/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs b/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs index 61ef24d..a7ba81f 100644 --- a/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs +++ b/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs @@ -4,12 +4,11 @@ namespace RelationshipAnalysis.Dto.Graph; public class ExpansionDto { - [Required] - public int NodeId { get; set; } - [Required] - public int SourceCategoryId { get; set; } - [Required] - public int TargetCategoryId { get; set; } - [Required] - public int EdgeCategoryId { get; set; } + [Required] public int NodeId { get; set; } + + [Required] public int SourceCategoryId { get; set; } + + [Required] public int TargetCategoryId { get; set; } + + [Required] public int EdgeCategoryId { get; set; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Dto/Graph/GraphDto.cs b/RelationshipAnalysis/Dto/Graph/GraphDto.cs index 518560a..e03b5e1 100644 --- a/RelationshipAnalysis/Dto/Graph/GraphDto.cs +++ b/RelationshipAnalysis/Dto/Graph/GraphDto.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using RelationshipAnalysis.Dto.Graph.Edge; using RelationshipAnalysis.Dto.Graph.Node; diff --git a/RelationshipAnalysis/Dto/Graph/Node/UploadNodeDto.cs b/RelationshipAnalysis/Dto/Graph/Node/UploadNodeDto.cs index a33a3f4..2e2e3eb 100644 --- a/RelationshipAnalysis/Dto/Graph/Node/UploadNodeDto.cs +++ b/RelationshipAnalysis/Dto/Graph/Node/UploadNodeDto.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Http; namespace RelationshipAnalysis.Dto.Graph.Node; diff --git a/RelationshipAnalysis/Dto/Graph/SearchGraphDto.cs b/RelationshipAnalysis/Dto/Graph/SearchGraphDto.cs index cdc3e5a..f176550 100644 --- a/RelationshipAnalysis/Dto/Graph/SearchGraphDto.cs +++ b/RelationshipAnalysis/Dto/Graph/SearchGraphDto.cs @@ -1,19 +1,18 @@ -namespace RelationshipAnalysis.Dto.Graph; using System.ComponentModel.DataAnnotations; +namespace RelationshipAnalysis.Dto.Graph; public class SearchGraphDto { - [Required] - public string SourceCategoryName { get; set; } - [Required] - public string TargetCategoryName { get; set; } - [Required] - public string EdgeCategoryName { get; set; } - [Required] - public Dictionary SourceCategoryClauses { get; set; } - [Required] - public Dictionary TargetCategoryClauses { get; set; } - [Required] - public Dictionary EdgeCategoryClauses { get; set; } + [Required] public string SourceCategoryName { get; set; } + + [Required] public string TargetCategoryName { get; set; } + + [Required] public string EdgeCategoryName { get; set; } + + [Required] public Dictionary SourceCategoryClauses { get; set; } + + [Required] public Dictionary TargetCategoryClauses { get; set; } + + [Required] public Dictionary EdgeCategoryClauses { get; set; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Dto/Panel/Admin/CreateUserDto.cs b/RelationshipAnalysis/Dto/Panel/Admin/CreateUserDto.cs index 6d3a411..d2b4730 100644 --- a/RelationshipAnalysis/Dto/Panel/Admin/CreateUserDto.cs +++ b/RelationshipAnalysis/Dto/Panel/Admin/CreateUserDto.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace RelationshipAnalysis.Dto.Panel.Admin; diff --git a/RelationshipAnalysis/Dto/Panel/Admin/GetAllUsersDto.cs b/RelationshipAnalysis/Dto/Panel/Admin/GetAllUsersDto.cs index b7018b2..23c9aba 100644 --- a/RelationshipAnalysis/Dto/Panel/Admin/GetAllUsersDto.cs +++ b/RelationshipAnalysis/Dto/Panel/Admin/GetAllUsersDto.cs @@ -1,10 +1,9 @@ -using System.Collections.Generic; -using RelationshipAnalysis.Dto.Panel.User; +using RelationshipAnalysis.Dto.Panel.User; namespace RelationshipAnalysis.Dto.Panel.Admin; public class GetAllUsersDto { - public List Users { get; init; } + public List Users { get; init; } public int AllUserCount { get; init; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Dto/Panel/User/UserOutputInfoDto.cs b/RelationshipAnalysis/Dto/Panel/User/UserOutputInfoDto.cs index 9a170e8..71d2e7c 100644 --- a/RelationshipAnalysis/Dto/Panel/User/UserOutputInfoDto.cs +++ b/RelationshipAnalysis/Dto/Panel/User/UserOutputInfoDto.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace RelationshipAnalysis.Dto.Panel.User; public class UserOutputInfoDto diff --git a/RelationshipAnalysis/Middlewares/SanitizationMiddleware.cs b/RelationshipAnalysis/Middlewares/SanitizationMiddleware.cs index 498fba0..7d14a27 100644 --- a/RelationshipAnalysis/Middlewares/SanitizationMiddleware.cs +++ b/RelationshipAnalysis/Middlewares/SanitizationMiddleware.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; using Ganss.Xss; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Newtonsoft.Json; diff --git a/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.Designer.cs b/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.Designer.cs new file mode 100644 index 0000000..adf7560 --- /dev/null +++ b/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.Designer.cs @@ -0,0 +1,427 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using RelationshipAnalysis.Context; + +#nullable disable + +namespace RelationshipAnalysis.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240907090417_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Permissions") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.UserRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.Edge", b => + { + b.Property("EdgeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EdgeId")); + + b.Property("EdgeCategoryId") + .HasColumnType("integer"); + + b.Property("EdgeDestinationNodeId") + .HasColumnType("integer"); + + b.Property("EdgeSourceNodeId") + .HasColumnType("integer"); + + b.Property("EdgeUniqueString") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("EdgeId"); + + b.HasIndex("EdgeCategoryId"); + + b.HasIndex("EdgeDestinationNodeId"); + + b.HasIndex("EdgeSourceNodeId"); + + b.ToTable("Edges"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeAttribute", b => + { + b.Property("EdgeAttributeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EdgeAttributeId")); + + b.Property("EdgeAttributeName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("EdgeAttributeId"); + + b.ToTable("EdgeAttributes"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeCategory", b => + { + b.Property("EdgeCategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EdgeCategoryId")); + + b.Property("EdgeCategoryName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("EdgeCategoryId"); + + b.ToTable("EdgeCategories"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeValue", b => + { + b.Property("ValueId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ValueId")); + + b.Property("EdgeAttributeId") + .HasColumnType("integer"); + + b.Property("EdgeId") + .HasColumnType("integer"); + + b.Property("ValueData") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ValueId"); + + b.HasIndex("EdgeAttributeId"); + + b.HasIndex("EdgeId"); + + b.ToTable("EdgeValues"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.Node", b => + { + b.Property("NodeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("NodeId")); + + b.Property("NodeCategoryId") + .HasColumnType("integer"); + + b.Property("NodeUniqueString") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("NodeId"); + + b.HasIndex("NodeCategoryId"); + + b.ToTable("Nodes"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeAttribute", b => + { + b.Property("NodeAttributeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("NodeAttributeId")); + + b.Property("NodeAttributeName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("NodeAttributeId"); + + b.ToTable("NodeAttributes"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeCategory", b => + { + b.Property("NodeCategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("NodeCategoryId")); + + b.Property("NodeCategoryName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("NodeCategoryId"); + + b.ToTable("NodeCategories"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeValue", b => + { + b.Property("ValueId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ValueId")); + + b.Property("NodeAttributeId") + .HasColumnType("integer"); + + b.Property("NodeId") + .HasColumnType("integer"); + + b.Property("ValueData") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ValueId"); + + b.HasIndex("NodeAttributeId"); + + b.HasIndex("NodeId"); + + b.ToTable("NodeValues"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.UserRole", b => + { + b.HasOne("RelationshipAnalysis.Models.Auth.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RelationshipAnalysis.Models.Auth.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.Edge", b => + { + b.HasOne("RelationshipAnalysis.Models.Graph.Edge.EdgeCategory", "EdgeCategory") + .WithMany("Edges") + .HasForeignKey("EdgeCategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RelationshipAnalysis.Models.Graph.Node.Node", "NodeDestination") + .WithMany("DestinationEdges") + .HasForeignKey("EdgeDestinationNodeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("RelationshipAnalysis.Models.Graph.Node.Node", "NodeSource") + .WithMany("SourceEdges") + .HasForeignKey("EdgeSourceNodeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EdgeCategory"); + + b.Navigation("NodeDestination"); + + b.Navigation("NodeSource"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeValue", b => + { + b.HasOne("RelationshipAnalysis.Models.Graph.Edge.EdgeAttribute", "EdgeAttribute") + .WithMany("EdgeValues") + .HasForeignKey("EdgeAttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RelationshipAnalysis.Models.Graph.Edge.Edge", "Edge") + .WithMany("EdgeValues") + .HasForeignKey("EdgeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Edge"); + + b.Navigation("EdgeAttribute"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.Node", b => + { + b.HasOne("RelationshipAnalysis.Models.Graph.Node.NodeCategory", "NodeCategory") + .WithMany("Nodes") + .HasForeignKey("NodeCategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("NodeCategory"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeValue", b => + { + b.HasOne("RelationshipAnalysis.Models.Graph.Node.NodeAttribute", "NodeAttribute") + .WithMany("Values") + .HasForeignKey("NodeAttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RelationshipAnalysis.Models.Graph.Node.Node", "Node") + .WithMany("Values") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Node"); + + b.Navigation("NodeAttribute"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.Role", b => + { + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Auth.User", b => + { + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.Edge", b => + { + b.Navigation("EdgeValues"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeAttribute", b => + { + b.Navigation("EdgeValues"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Edge.EdgeCategory", b => + { + b.Navigation("Edges"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.Node", b => + { + b.Navigation("DestinationEdges"); + + b.Navigation("SourceEdges"); + + b.Navigation("Values"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeAttribute", b => + { + b.Navigation("Values"); + }); + + modelBuilder.Entity("RelationshipAnalysis.Models.Graph.Node.NodeCategory", b => + { + b.Navigation("Nodes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.cs b/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.cs new file mode 100644 index 0000000..c5eb62a --- /dev/null +++ b/RelationshipAnalysis/Migrations/20240907090417_InitialCreate.cs @@ -0,0 +1,319 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace RelationshipAnalysis.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "EdgeAttributes", + columns: table => new + { + EdgeAttributeId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EdgeAttributeName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EdgeAttributes", x => x.EdgeAttributeId); + }); + + migrationBuilder.CreateTable( + name: "EdgeCategories", + columns: table => new + { + EdgeCategoryId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EdgeCategoryName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EdgeCategories", x => x.EdgeCategoryId); + }); + + migrationBuilder.CreateTable( + name: "NodeAttributes", + columns: table => new + { + NodeAttributeId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NodeAttributeName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_NodeAttributes", x => x.NodeAttributeId); + }); + + migrationBuilder.CreateTable( + name: "NodeCategories", + columns: table => new + { + NodeCategoryId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NodeCategoryName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_NodeCategories", x => x.NodeCategoryId); + }); + + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Permissions = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Username = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + PasswordHash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Nodes", + columns: table => new + { + NodeId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NodeUniqueString = table.Column(type: "text", nullable: false), + NodeCategoryId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Nodes", x => x.NodeId); + table.ForeignKey( + name: "FK_Nodes_NodeCategories_NodeCategoryId", + column: x => x.NodeCategoryId, + principalTable: "NodeCategories", + principalColumn: "NodeCategoryId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "UserRoles", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + RoleId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserRoles", x => x.Id); + table.ForeignKey( + name: "FK_UserRoles_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserRoles_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Edges", + columns: table => new + { + EdgeId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EdgeSourceNodeId = table.Column(type: "integer", nullable: false), + EdgeDestinationNodeId = table.Column(type: "integer", nullable: false), + EdgeCategoryId = table.Column(type: "integer", nullable: false), + EdgeUniqueString = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Edges", x => x.EdgeId); + table.ForeignKey( + name: "FK_Edges_EdgeCategories_EdgeCategoryId", + column: x => x.EdgeCategoryId, + principalTable: "EdgeCategories", + principalColumn: "EdgeCategoryId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Edges_Nodes_EdgeDestinationNodeId", + column: x => x.EdgeDestinationNodeId, + principalTable: "Nodes", + principalColumn: "NodeId", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Edges_Nodes_EdgeSourceNodeId", + column: x => x.EdgeSourceNodeId, + principalTable: "Nodes", + principalColumn: "NodeId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "NodeValues", + columns: table => new + { + ValueId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NodeId = table.Column(type: "integer", nullable: false), + NodeAttributeId = table.Column(type: "integer", nullable: false), + ValueData = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_NodeValues", x => x.ValueId); + table.ForeignKey( + name: "FK_NodeValues_NodeAttributes_NodeAttributeId", + column: x => x.NodeAttributeId, + principalTable: "NodeAttributes", + principalColumn: "NodeAttributeId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_NodeValues_Nodes_NodeId", + column: x => x.NodeId, + principalTable: "Nodes", + principalColumn: "NodeId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "EdgeValues", + columns: table => new + { + ValueId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EdgeId = table.Column(type: "integer", nullable: false), + EdgeAttributeId = table.Column(type: "integer", nullable: false), + ValueData = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EdgeValues", x => x.ValueId); + table.ForeignKey( + name: "FK_EdgeValues_EdgeAttributes_EdgeAttributeId", + column: x => x.EdgeAttributeId, + principalTable: "EdgeAttributes", + principalColumn: "EdgeAttributeId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EdgeValues_Edges_EdgeId", + column: x => x.EdgeId, + principalTable: "Edges", + principalColumn: "EdgeId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Edges_EdgeCategoryId", + table: "Edges", + column: "EdgeCategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_Edges_EdgeDestinationNodeId", + table: "Edges", + column: "EdgeDestinationNodeId"); + + migrationBuilder.CreateIndex( + name: "IX_Edges_EdgeSourceNodeId", + table: "Edges", + column: "EdgeSourceNodeId"); + + migrationBuilder.CreateIndex( + name: "IX_EdgeValues_EdgeAttributeId", + table: "EdgeValues", + column: "EdgeAttributeId"); + + migrationBuilder.CreateIndex( + name: "IX_EdgeValues_EdgeId", + table: "EdgeValues", + column: "EdgeId"); + + migrationBuilder.CreateIndex( + name: "IX_Nodes_NodeCategoryId", + table: "Nodes", + column: "NodeCategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_NodeValues_NodeAttributeId", + table: "NodeValues", + column: "NodeAttributeId"); + + migrationBuilder.CreateIndex( + name: "IX_NodeValues_NodeId", + table: "NodeValues", + column: "NodeId"); + + migrationBuilder.CreateIndex( + name: "IX_UserRoles_RoleId", + table: "UserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_UserRoles_UserId", + table: "UserRoles", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "EdgeValues"); + + migrationBuilder.DropTable( + name: "NodeValues"); + + migrationBuilder.DropTable( + name: "UserRoles"); + + migrationBuilder.DropTable( + name: "EdgeAttributes"); + + migrationBuilder.DropTable( + name: "Edges"); + + migrationBuilder.DropTable( + name: "NodeAttributes"); + + migrationBuilder.DropTable( + name: "Roles"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "EdgeCategories"); + + migrationBuilder.DropTable( + name: "Nodes"); + + migrationBuilder.DropTable( + name: "NodeCategories"); + } + } +} diff --git a/RelationshipAnalysis/Models/Auth/Role.cs b/RelationshipAnalysis/Models/Auth/Role.cs index 2d1587d..1a7037f 100644 --- a/RelationshipAnalysis/Models/Auth/Role.cs +++ b/RelationshipAnalysis/Models/Auth/Role.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; namespace RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Models/Auth/User.cs b/RelationshipAnalysis/Models/Auth/User.cs index 5e3cbba..e411b1a 100644 --- a/RelationshipAnalysis/Models/Auth/User.cs +++ b/RelationshipAnalysis/Models/Auth/User.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; namespace RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Models/Graph/Edge/Edge.cs b/RelationshipAnalysis/Models/Graph/Edge/Edge.cs index 0cf5ec0..750f4a8 100644 --- a/RelationshipAnalysis/Models/Graph/Edge/Edge.cs +++ b/RelationshipAnalysis/Models/Graph/Edge/Edge.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Models/Graph/Edge/EdgeAttribute.cs b/RelationshipAnalysis/Models/Graph/Edge/EdgeAttribute.cs index 0269f57..301c880 100644 --- a/RelationshipAnalysis/Models/Graph/Edge/EdgeAttribute.cs +++ b/RelationshipAnalysis/Models/Graph/Edge/EdgeAttribute.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Models/Graph/Edge/EdgeCategory.cs b/RelationshipAnalysis/Models/Graph/Edge/EdgeCategory.cs index cbf7c1f..9a41aba 100644 --- a/RelationshipAnalysis/Models/Graph/Edge/EdgeCategory.cs +++ b/RelationshipAnalysis/Models/Graph/Edge/EdgeCategory.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Models/Graph/Node/Node.cs b/RelationshipAnalysis/Models/Graph/Node/Node.cs index 2e4f19d..6101f37 100644 --- a/RelationshipAnalysis/Models/Graph/Node/Node.cs +++ b/RelationshipAnalysis/Models/Graph/Node/Node.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Models/Graph/Node/NodeAttribute.cs b/RelationshipAnalysis/Models/Graph/Node/NodeAttribute.cs index d8e4d43..30aedcc 100644 --- a/RelationshipAnalysis/Models/Graph/Node/NodeAttribute.cs +++ b/RelationshipAnalysis/Models/Graph/Node/NodeAttribute.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Models/Graph/Node/NodeCategory.cs b/RelationshipAnalysis/Models/Graph/Node/NodeCategory.cs index 8959912..d930951 100644 --- a/RelationshipAnalysis/Models/Graph/Node/NodeCategory.cs +++ b/RelationshipAnalysis/Models/Graph/Node/NodeCategory.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; diff --git a/RelationshipAnalysis/Program.cs b/RelationshipAnalysis/Program.cs index b34d1d9..f1415c4 100644 --- a/RelationshipAnalysis/Program.cs +++ b/RelationshipAnalysis/Program.cs @@ -1,11 +1,6 @@ using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Context; using RelationshipAnalysis.Middlewares; @@ -124,7 +119,6 @@ .AddKeyedSingleton("edge") .AddKeyedSingleton("node") .AddKeyedSingleton("edge"); - builder.Services.Configure(builder.Configuration.GetSection("Jwt")); @@ -152,10 +146,7 @@ OnMessageReceived = context => { var cookie = context.Request.Cookies[jwtSettings.CookieName]; - if (!string.IsNullOrEmpty(cookie)) - { - context.Token = cookie; - } + if (!string.IsNullOrEmpty(cookie)) context.Token = cookie; return Task.CompletedTask; } }; @@ -180,7 +171,7 @@ namespace RelationshipAnalysis { - public partial class Program + public class Program { } } \ No newline at end of file diff --git a/RelationshipAnalysis/RelationshipAnalysis.csproj b/RelationshipAnalysis/RelationshipAnalysis.csproj index 94c8444..24b75e9 100644 --- a/RelationshipAnalysis/RelationshipAnalysis.csproj +++ b/RelationshipAnalysis/RelationshipAnalysis.csproj @@ -1,11 +1,9 @@ - net8.0 enable enable - @@ -24,21 +22,11 @@ - + + - - - - - ..\..\..\..\.nuget\packages\nsubstitute\5.1.0\lib\net6.0\NSubstitute.dll - - - ..\RelationshipAnalysis.Integration.Test\bin\Debug\net8.0\RelationshipAnalysis.dll - - - - + \ No newline at end of file diff --git a/RelationshipAnalysis/Resources.resx b/RelationshipAnalysis/Resources.resx index f60f93f..a5029c7 100644 --- a/RelationshipAnalysis/Resources.resx +++ b/RelationshipAnalysis/Resources.resx @@ -81,7 +81,8 @@ User Deleted successfully! - diff --git a/RelationshipAnalysis/Services/AuthServices/Abstraction/ICookieSetter.cs b/RelationshipAnalysis/Services/AuthServices/Abstraction/ICookieSetter.cs index ab66184..77a21f7 100644 --- a/RelationshipAnalysis/Services/AuthServices/Abstraction/ICookieSetter.cs +++ b/RelationshipAnalysis/Services/AuthServices/Abstraction/ICookieSetter.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Http; - -namespace RelationshipAnalysis.Services.AuthServices.Abstraction; +namespace RelationshipAnalysis.Services.AuthServices.Abstraction; public interface ICookieSetter { diff --git a/RelationshipAnalysis/Services/AuthServices/Abstraction/ILoginService.cs b/RelationshipAnalysis/Services/AuthServices/Abstraction/ILoginService.cs index d56a059..fe3935c 100644 --- a/RelationshipAnalysis/Services/AuthServices/Abstraction/ILoginService.cs +++ b/RelationshipAnalysis/Services/AuthServices/Abstraction/ILoginService.cs @@ -1,7 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Auth; +using RelationshipAnalysis.Dto; using LoginDto = RelationshipAnalysis.Dto.Auth.LoginDto; namespace RelationshipAnalysis.Services.AuthServices.Abstraction; diff --git a/RelationshipAnalysis/Services/AuthServices/CookieSetter.cs b/RelationshipAnalysis/Services/AuthServices/CookieSetter.cs index be59829..6e6987b 100644 --- a/RelationshipAnalysis/Services/AuthServices/CookieSetter.cs +++ b/RelationshipAnalysis/Services/AuthServices/CookieSetter.cs @@ -1,6 +1,4 @@ -using System; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Options; +using Microsoft.Extensions.Options; using RelationshipAnalysis.Services.AuthServices.Abstraction; using RelationshipAnalysis.Settings.JWT; diff --git a/RelationshipAnalysis/Services/AuthServices/CustomPasswordHasher.cs b/RelationshipAnalysis/Services/AuthServices/CustomPasswordHasher.cs index 732a6fc..77648cf 100644 --- a/RelationshipAnalysis/Services/AuthServices/CustomPasswordHasher.cs +++ b/RelationshipAnalysis/Services/AuthServices/CustomPasswordHasher.cs @@ -1,5 +1,4 @@ -using System; -using System.Security.Cryptography; +using System.Security.Cryptography; using System.Text; using RelationshipAnalysis.Services.AuthServices.Abstraction; diff --git a/RelationshipAnalysis/Services/AuthServices/JwtTokenGenerator.cs b/RelationshipAnalysis/Services/AuthServices/JwtTokenGenerator.cs index 6783f83..a9da7e6 100644 --- a/RelationshipAnalysis/Services/AuthServices/JwtTokenGenerator.cs +++ b/RelationshipAnalysis/Services/AuthServices/JwtTokenGenerator.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Microsoft.Extensions.Options; diff --git a/RelationshipAnalysis/Services/AuthServices/LoginService.cs b/RelationshipAnalysis/Services/AuthServices/LoginService.cs index 13f0c98..286208b 100644 --- a/RelationshipAnalysis/Services/AuthServices/LoginService.cs +++ b/RelationshipAnalysis/Services/AuthServices/LoginService.cs @@ -1,8 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.EntityFrameworkCore; -using RelationshipAnalysis.Context; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Auth; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Services.Abstraction; @@ -25,7 +21,7 @@ public async Task> LoginAsync(LoginDto loginModel, Ht if (user == null || !passwordVerifier.VerifyPasswordHash(loginModel.Password, user.PasswordHash)) return messageResponseCreator.Create(StatusCodeType.Unauthorized, Resources.LoginFailedMessage); - + var token = jwtTokenGenerator.GenerateJwtToken(user); cookieSetter.SetCookie(response, token); diff --git a/RelationshipAnalysis/Services/CRUD/Permissions/Abstraction/IPermissionsReceiver.cs b/RelationshipAnalysis/Services/CRUD/Permissions/Abstraction/IPermissionsReceiver.cs index 4f67ab9..0641fb8 100644 --- a/RelationshipAnalysis/Services/CRUD/Permissions/Abstraction/IPermissionsReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/Permissions/Abstraction/IPermissionsReceiver.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.Permissions.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.Permissions.Abstraction; public interface IPermissionsReceiver { diff --git a/RelationshipAnalysis/Services/CRUD/Permissions/PermissionsReceiver.cs b/RelationshipAnalysis/Services/CRUD/Permissions/PermissionsReceiver.cs index 34efd4d..f189a1e 100644 --- a/RelationshipAnalysis/Services/CRUD/Permissions/PermissionsReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/Permissions/PermissionsReceiver.cs @@ -1,8 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Newtonsoft.Json; -using RelationshipAnalysis.Models.Auth; +using Newtonsoft.Json; using RelationshipAnalysis.Services.CRUD.Permissions.Abstraction; using RelationshipAnalysis.Services.CRUD.Role.Abstraction; diff --git a/RelationshipAnalysis/Services/CRUD/Role/Abstraction/IRoleReceiver.cs b/RelationshipAnalysis/Services/CRUD/Role/Abstraction/IRoleReceiver.cs index 84d326e..03f595c 100644 --- a/RelationshipAnalysis/Services/CRUD/Role/Abstraction/IRoleReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/Role/Abstraction/IRoleReceiver.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - namespace RelationshipAnalysis.Services.CRUD.Role.Abstraction; public interface IRoleReceiver diff --git a/RelationshipAnalysis/Services/CRUD/Role/RoleReceiver.cs b/RelationshipAnalysis/Services/CRUD/Role/RoleReceiver.cs index 5ba2ec4..b8ba1ea 100644 --- a/RelationshipAnalysis/Services/CRUD/Role/RoleReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/Role/RoleReceiver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.Role.Abstraction; diff --git a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserAdder.cs b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserAdder.cs index fb3496e..f57a0e7 100644 --- a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserAdder.cs +++ b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserAdder.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; public interface IUserAdder { diff --git a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserDeleter.cs b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserDeleter.cs index c9eea8f..d3aeb43 100644 --- a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserDeleter.cs +++ b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserDeleter.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; public interface IUserDeleter { diff --git a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserReceiver.cs b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserReceiver.cs index dd3a330..b183dd6 100644 --- a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserReceiver.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; using System.Security.Claims; -using System.Threading.Tasks; namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; diff --git a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserUpdater.cs b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserUpdater.cs index 427365b..93d54d1 100644 --- a/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserUpdater.cs +++ b/RelationshipAnalysis/Services/CRUD/User/Abstraction/IUserUpdater.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.User.Abstraction; public interface IUserUpdater { diff --git a/RelationshipAnalysis/Services/CRUD/User/UserAdder.cs b/RelationshipAnalysis/Services/CRUD/User/UserAdder.cs index 2d264d8..b4e8a89 100644 --- a/RelationshipAnalysis/Services/CRUD/User/UserAdder.cs +++ b/RelationshipAnalysis/Services/CRUD/User/UserAdder.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.User.Abstraction; namespace RelationshipAnalysis.Services.CRUD.User; diff --git a/RelationshipAnalysis/Services/CRUD/User/UserDeleter.cs b/RelationshipAnalysis/Services/CRUD/User/UserDeleter.cs index 26288de..efa7c4a 100644 --- a/RelationshipAnalysis/Services/CRUD/User/UserDeleter.cs +++ b/RelationshipAnalysis/Services/CRUD/User/UserDeleter.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.User.Abstraction; namespace RelationshipAnalysis.Services.CRUD.User; diff --git a/RelationshipAnalysis/Services/CRUD/User/UserReceiver.cs b/RelationshipAnalysis/Services/CRUD/User/UserReceiver.cs index eb6f68e..bc62f79 100644 --- a/RelationshipAnalysis/Services/CRUD/User/UserReceiver.cs +++ b/RelationshipAnalysis/Services/CRUD/User/UserReceiver.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; using System.Security.Claims; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.User.Abstraction; @@ -45,8 +40,8 @@ public async Task ReceiveAllUserCountAsync() .Include(u => u.UserRoles) .ThenInclude(ur => ur.Role) .SingleOrDefaultAsync(u => u.Username == username); - - + + return user; } diff --git a/RelationshipAnalysis/Services/CRUD/User/UserUpdater.cs b/RelationshipAnalysis/Services/CRUD/User/UserUpdater.cs index 73e8d71..c123d9f 100644 --- a/RelationshipAnalysis/Services/CRUD/User/UserUpdater.cs +++ b/RelationshipAnalysis/Services/CRUD/User/UserUpdater.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.User.Abstraction; namespace RelationshipAnalysis.Services.CRUD.User; diff --git a/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesAdder.cs b/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesAdder.cs index f5cfdbf..6dcabd3 100644 --- a/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesAdder.cs +++ b/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesAdder.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; public interface IUserRolesAdder { diff --git a/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesRemover.cs b/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesRemover.cs index 3167c3c..4be9734 100644 --- a/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesRemover.cs +++ b/RelationshipAnalysis/Services/CRUD/UserRole/Abstraction/IUserRolesRemover.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; +namespace RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; public interface IUserRolesRemover { diff --git a/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesAdder.cs b/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesAdder.cs index f2cbce1..5c6d63a 100644 --- a/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesAdder.cs +++ b/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesAdder.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; namespace RelationshipAnalysis.Services.CRUD.UserRole; diff --git a/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesRemover.cs b/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesRemover.cs index cfd2c86..cdb0675 100644 --- a/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesRemover.cs +++ b/RelationshipAnalysis/Services/CRUD/UserRole/UserRolesRemover.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IAttributesReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IAttributesReceiver.cs index 8d143ca..b57c5ac 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/IAttributesReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IAttributesReceiver.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface IAttributesReceiver diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvProcessorService.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvProcessorService.cs index dedd2ae..1f182ce 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvProcessorService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvProcessorService.cs @@ -1,7 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; - namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface ICsvProcessorService diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvValidatorService.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvValidatorService.cs index ee46705..ff63f28 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvValidatorService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICsvValidatorService.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Http; using RelationshipAnalysis.Dto; namespace RelationshipAnalysis.Services.GraphServices.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs index 2bd0085..03b62b9 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Dto; namespace RelationshipAnalysis.Services.GraphServices.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/CsvProcessorService.cs b/RelationshipAnalysis/Services/GraphServices/CsvProcessorService.cs index 4e5e928..068b7b6 100644 --- a/RelationshipAnalysis/Services/GraphServices/CsvProcessorService.cs +++ b/RelationshipAnalysis/Services/GraphServices/CsvProcessorService.cs @@ -1,11 +1,7 @@ -using System.Collections.Generic; using System.Dynamic; using System.Globalization; -using System.IO; -using System.Threading.Tasks; using CsvHelper; using CsvHelper.Configuration; -using Microsoft.AspNetCore.Http; using RelationshipAnalysis.Services.GraphServices.Abstraction; namespace RelationshipAnalysis.Services.GraphServices; diff --git a/RelationshipAnalysis/Services/GraphServices/CsvValidatorService.cs b/RelationshipAnalysis/Services/GraphServices/CsvValidatorService.cs index 403a837..5737287 100644 --- a/RelationshipAnalysis/Services/GraphServices/CsvValidatorService.cs +++ b/RelationshipAnalysis/Services/GraphServices/CsvValidatorService.cs @@ -1,10 +1,7 @@ using System.Globalization; -using System.IO; -using System.Linq; using AngleSharp.Text; using CsvHelper; using CsvHelper.Configuration; -using Microsoft.AspNetCore.Http; using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; @@ -35,6 +32,4 @@ public ActionResponse Validate(IFormFile file, params string[] uniqu return responseCreator.Create(StatusCodeType.Success, Resources.ValidFileMessage); } - - } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IContextEdgesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IContextEdgesAdditionService.cs index 6b0f61e..d2c2798 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IContextEdgesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IContextEdgesAdditionService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ICreateEdgeCategoryService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ICreateEdgeCategoryService.cs index 92f7520..ab24c13 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ICreateEdgeCategoryService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ICreateEdgeCategoryService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeCategoryReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeCategoryReceiver.cs index 55bb0b1..64eb7d2 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeCategoryReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeCategoryReceiver.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; +namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; public interface IEdgeCategoryReceiver { diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeValueAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeValueAdditionService.cs index 18aca1c..24e0133 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeValueAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgeValueAdditionService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgesAdditionService.cs index 2956fe4..e5aa493 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/IEdgesAdditionService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ISingleEdgeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ISingleEdgeAdditionService.cs index fc37bc8..755da4d 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ISingleEdgeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/Abstraction/ISingleEdgeAdditionService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; namespace RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/ContextEdgesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/ContextEdgesAdditionService.cs index b07f21d..b755a38 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/ContextEdgesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/ContextEdgesAdditionService.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; @@ -12,9 +9,12 @@ namespace RelationshipAnalysis.Services.GraphServices.Edge; -public class ContextEdgesAdditionService(IMessageResponseCreator responseCreator, ISingleEdgeAdditionService singleEdgeAdditionService) : IContextEdgesAdditionService +public class ContextEdgesAdditionService( + IMessageResponseCreator responseCreator, + ISingleEdgeAdditionService singleEdgeAdditionService) : IContextEdgesAdditionService { - public async Task> AddToContext(ApplicationDbContext context, EdgeCategory edgeCategory, NodeCategory sourceCategory, + public async Task> AddToContext(ApplicationDbContext context, EdgeCategory edgeCategory, + NodeCategory sourceCategory, NodeCategory targetCategory, List objects, UploadEdgeDto uploadEdgeDto) { await using (var transaction = await context.Database.BeginTransactionAsync()) @@ -24,8 +24,10 @@ public async Task> AddToContext(ApplicationDbContext foreach (var obj in objects) { var dictObject = (IDictionary)obj; - await singleEdgeAdditionService.AddSingleEdge(context, dictObject, uploadEdgeDto.UniqueKeyHeaderName, - uploadEdgeDto.SourceNodeHeaderName, uploadEdgeDto.TargetNodeHeaderName, edgeCategory.EdgeCategoryId, + await singleEdgeAdditionService.AddSingleEdge(context, dictObject, + uploadEdgeDto.UniqueKeyHeaderName, + uploadEdgeDto.SourceNodeHeaderName, uploadEdgeDto.TargetNodeHeaderName, + edgeCategory.EdgeCategoryId, sourceCategory.NodeCategoryId, targetCategory.NodeCategoryId); } @@ -39,6 +41,5 @@ await singleEdgeAdditionService.AddSingleEdge(context, dictObject, uploadEdgeDto } return responseCreator.Create(StatusCodeType.Success, Resources.SuccessfulNodeAdditionMessage); - } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/CreateEdgeCategoryService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/CreateEdgeCategoryService.cs index dfadbe4..31e0df8 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/CreateEdgeCategoryService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/CreateEdgeCategoryService.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; using RelationshipAnalysis.Enums; @@ -12,13 +8,15 @@ namespace RelationshipAnalysis.Services.GraphServices.Edge; -public class CreateEdgeCategoryService(IServiceProvider serviceProvider, IMessageResponseCreator responseCreator) : ICreateEdgeCategoryService +public class CreateEdgeCategoryService(IServiceProvider serviceProvider, IMessageResponseCreator responseCreator) + : ICreateEdgeCategoryService { public async Task> CreateEdgeCategory(CreateEdgeCategoryDto createEdgeCategoryDto) { - if (createEdgeCategoryDto is null) return responseCreator.Create(StatusCodeType.BadRequest, Resources.NullDtoErrorMessage); + if (createEdgeCategoryDto is null) + return responseCreator.Create(StatusCodeType.BadRequest, Resources.NullDtoErrorMessage); if (IsNotUniqueCategoryName(createEdgeCategoryDto)) - return responseCreator.Create(StatusCodeType.BadRequest,Resources.NotUniqueCategoryNameErrorMessage); + return responseCreator.Create(StatusCodeType.BadRequest, Resources.NotUniqueCategoryNameErrorMessage); await AddCategory(createEdgeCategoryDto); return responseCreator.Create(StatusCodeType.Success, Resources.SuccessfulCreateCategory); } @@ -41,5 +39,4 @@ private bool IsNotUniqueCategoryName(CreateEdgeCategoryDto dto) var context = scope.ServiceProvider.GetRequiredService(); return context.EdgeCategories.Any(c => c.EdgeCategoryName == dto.EdgeCategoryName); } - } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeAttributesReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeAttributesReceiver.cs index 9511747..8d07b54 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeAttributesReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeAttributesReceiver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.GraphServices.Abstraction; @@ -13,7 +8,6 @@ public class EdgeAttributesReceiver(IServiceProvider serviceProvider) : IAttribu { public async Task> GetAllAttributes(string name) { - using var scope = serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryReceiver.cs index c6df1d5..2ee14c6 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryReceiver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs index 23ea32c..8ae1ed3 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; @@ -19,28 +14,25 @@ public Task>> GetInfo(int edgeId) var result = new Dictionary(); var selectedEdge = context.Edges.SingleOrDefault(e => e.EdgeId == edgeId); - if (selectedEdge == null) - { - return NotFoundResult(); - } + if (selectedEdge == null) return NotFoundResult(); selectedEdge.EdgeValues.ToList().ForEach(v => result.Add(v.EdgeAttribute.EdgeAttributeName, v.ValueData)); return SuccessResult(result); } private async Task>> NotFoundResult() { - return new ActionResponse>() + return new ActionResponse> { StatusCode = StatusCodeType.NotFound }; } - + private async Task>> SuccessResult(Dictionary result) { - return new ActionResponse>() + return new ActionResponse> { StatusCode = StatusCodeType.Success, - Data = result + Data = result }; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeValueAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeValueAdditionService.cs index 3e5eeb2..690d8f3 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeValueAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeValueAdditionService.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Models.Graph.Edge; @@ -10,9 +7,9 @@ namespace RelationshipAnalysis.Services.GraphServices.Edge; public class EdgeValueAdditionService : IEdgeValueAdditionService { - public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair kvp, Models.Graph.Edge.Edge newEdge) + public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair kvp, + Models.Graph.Edge.Edge newEdge) { - var newEdgeAttribute = await context.EdgeAttributes.SingleOrDefaultAsync(na => na.EdgeAttributeName == kvp.Key); if (newEdgeAttribute == null) diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgesAdditionService.cs index 5a7e964..05418b2 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgesAdditionService.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Edge; @@ -12,7 +9,6 @@ using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; using IEdgesAdditionService = RelationshipAnalysis.Services.GraphServices.Edge.Abstraction.IEdgesAdditionService; -using ISingleEdgeAdditionService = RelationshipAnalysis.Services.GraphServices.Edge.Abstraction.ISingleEdgeAdditionService; namespace RelationshipAnalysis.Services.GraphServices.Edge; @@ -31,41 +27,32 @@ public async Task> AddEdges(UploadEdgeDto uploadEdgeD var targetCategory = await GetTargetCategory(uploadEdgeDto, context); var sourceCategory = await GetSourceCategory(uploadEdgeDto, context); var edgeCategory = await GetEdgeCategory(uploadEdgeDto, context); - + var nullCheckResponse = CheckForNullValues(edgeCategory, sourceCategory, targetCategory); - if (nullCheckResponse.StatusCode == StatusCodeType.BadRequest) - { - return nullCheckResponse; - } + if (nullCheckResponse.StatusCode == StatusCodeType.BadRequest) return nullCheckResponse; - var validationResult = csvValidatorService.Validate(uploadEdgeDto.File, uploadEdgeDto.UniqueKeyHeaderName, uploadEdgeDto.SourceNodeHeaderName, uploadEdgeDto.TargetNodeHeaderName); - if (validationResult.StatusCode == StatusCodeType.BadRequest) - { - return validationResult; - } + var validationResult = csvValidatorService.Validate(uploadEdgeDto.File, uploadEdgeDto.UniqueKeyHeaderName, + uploadEdgeDto.SourceNodeHeaderName, uploadEdgeDto.TargetNodeHeaderName); + if (validationResult.StatusCode == StatusCodeType.BadRequest) return validationResult; var objects = await csvProcessorService.ProcessCsvAsync(uploadEdgeDto.File); - return await contextEdgesAdditionService.AddToContext(context, edgeCategory, sourceCategory, targetCategory, objects, + return await contextEdgesAdditionService.AddToContext(context, edgeCategory, sourceCategory, targetCategory, + objects, uploadEdgeDto); } - private ActionResponse CheckForNullValues(EdgeCategory? edgeCategory, NodeCategory? sourceCategory, NodeCategory? targetCategory) + private ActionResponse CheckForNullValues(EdgeCategory? edgeCategory, NodeCategory? sourceCategory, + NodeCategory? targetCategory) { if (edgeCategory == null) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidEdgeCategory); - } if (sourceCategory == null) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidSourceNodeCategory); - } if (targetCategory == null) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidTargetNodeCategory); - } return responseCreator.Create(StatusCodeType.Success, string.Empty); } diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/SingleEdgeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Edge/SingleEdgeAdditionService.cs index 47ed261..4c906dd 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/SingleEdgeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/SingleEdgeAdditionService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.GraphServices.Edge.Abstraction; @@ -16,39 +13,23 @@ public async Task AddSingleEdge(ApplicationDbContext context, IDictionary GetNewEdge(ApplicationDbContext context, int edgeCategoryId, string uniqueHeaderName, Models.Graph.Node.Node source, Models.Graph.Node.Node target, IDictionary record) + private async Task GetNewEdge(ApplicationDbContext context, int edgeCategoryId, + string uniqueHeaderName, Models.Graph.Node.Node source, Models.Graph.Node.Node target, + IDictionary record) { var newEdge = await context.Edges.SingleOrDefaultAsync(e => e.EdgeCategoryId == edgeCategoryId @@ -81,7 +63,8 @@ public async Task AddSingleEdge(ApplicationDbContext context, IDictionary GetTargetNode(ApplicationDbContext context, IDictionary record, string uniqueTargetHeaderName, + private async Task GetTargetNode(ApplicationDbContext context, + IDictionary record, string uniqueTargetHeaderName, int targetNodeCategoryId) { var target = @@ -90,7 +73,8 @@ await context.Nodes.SingleOrDefaultAsync(n => n.NodeUniqueString == (string)reco return target; } - private async Task GetSourceNode(ApplicationDbContext context, IDictionary record, string uniqueSourceHeaderName, + private async Task GetSourceNode(ApplicationDbContext context, + IDictionary record, string uniqueSourceHeaderName, int sourceNodeCategoryId) { var source = diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs index 4b9e1d9..9bdca46 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph; namespace RelationshipAnalysis.Services.GraphServices.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphDtoCreator.cs b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphDtoCreator.cs index 7390e21..42d3c0b 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphDtoCreator.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphDtoCreator.cs @@ -1,11 +1,8 @@ -using System.Collections.Generic; using RelationshipAnalysis.Dto.Graph; namespace RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; public interface IGraphDtoCreator { - GraphDto CreateResultGraphDto(List contextNodes, List contextEdges); - } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphReceiver.cs index 8c900b0..538553c 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IGraphReceiver.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto.Graph; namespace RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs index d709f8f..2f6a862 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs @@ -1,24 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto.Graph; -using RelationshipAnalysis.Models.Graph; using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; namespace RelationshipAnalysis.Services.GraphServices; -public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator) : IExpansionGraphReceiver +public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator) + : IExpansionGraphReceiver { - public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, string edgeCategoryName) + public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, + string edgeCategoryName) { using var scope = serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - + var inputNodes = await GetInputNodes(context, sourceCategoryName); var outputNodes = await GetOutputNodes(context, targetCategoryName); var validEdges = await GetValidEdges(nodeId, context, edgeCategoryName, inputNodes, outputNodes); @@ -26,10 +22,10 @@ public async Task GetExpansionGraph(int nodeId, string sourceCategoryN return graphDtoCreator.CreateResultGraphDto(inputNodes.Union(outputNodes).ToList(), validEdges); } - private async Task> GetValidEdges(int nodeId, ApplicationDbContext context, string edgeCategoryName, List inputNodes, + private async Task> GetValidEdges(int nodeId, ApplicationDbContext context, + string edgeCategoryName, List inputNodes, List outputNodes) { - var validEdges = await context.Edges.Where(e => (e.EdgeSourceNodeId == nodeId || e.EdgeDestinationNodeId == nodeId) && e.EdgeCategory.EdgeCategoryName == edgeCategoryName && @@ -38,14 +34,16 @@ public async Task GetExpansionGraph(int nodeId, string sourceCategoryN return validEdges; } - private async Task> GetOutputNodes(ApplicationDbContext context, string targetCategoryName) + private async Task> GetOutputNodes(ApplicationDbContext context, + string targetCategoryName) { var outputNodes = await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == targetCategoryName).ToListAsync(); return outputNodes; } - private async Task> GetInputNodes(ApplicationDbContext context, string sourceCategoryName) + private async Task> GetInputNodes(ApplicationDbContext context, + string sourceCategoryName) { var inputNodes = await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == sourceCategoryName).ToListAsync(); diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/GraphDtoCreator.cs b/RelationshipAnalysis/Services/GraphServices/Graph/GraphDtoCreator.cs index f3469f5..0efc6ba 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/GraphDtoCreator.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/GraphDtoCreator.cs @@ -1,18 +1,14 @@ -using System; -using System.Collections.Generic; using RelationshipAnalysis.Dto.Graph; using RelationshipAnalysis.Dto.Graph.Edge; using RelationshipAnalysis.Dto.Graph.Node; -using RelationshipAnalysis.Services.GraphServices.Abstraction; -using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; using IGraphDtoCreator = RelationshipAnalysis.Services.GraphServices.Graph.Abstraction.IGraphDtoCreator; namespace RelationshipAnalysis.Services.GraphServices.Graph; public class GraphDtoCreator : IGraphDtoCreator { - - public GraphDto CreateResultGraphDto(List contextNodes, List contextEdges) + public GraphDto CreateResultGraphDto(List contextNodes, + List contextEdges) { if (contextEdges == null || contextNodes == null) throw new ArgumentNullException(); var resultGraphDto = new GraphDto(); diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/GraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/GraphReceiver.cs index fa6d7dd..70563ae 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/GraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/GraphReceiver.cs @@ -1,10 +1,6 @@ -using System; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto.Graph; -using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; using IGraphDtoCreator = RelationshipAnalysis.Services.GraphServices.Graph.Abstraction.IGraphDtoCreator; @@ -22,5 +18,4 @@ public async Task GetGraph() return graphDtoCreator.CreateResultGraphDto(contextNodes, contextEdges); } - } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/GraphSearcherService.cs b/RelationshipAnalysis/Services/GraphServices/Graph/GraphSearcherService.cs index 99d7d68..90b36a6 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/GraphSearcherService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/GraphSearcherService.cs @@ -1,10 +1,7 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph; using RelationshipAnalysis.Enums; -using RelationshipAnalysis.Models.Graph.Edge; -using RelationshipAnalysis.Models.Graph.Node; using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; using ApplicationDbContext = RelationshipAnalysis.Context.ApplicationDbContext; @@ -28,15 +25,12 @@ public async Task> Search(SearchGraphDto searchGraphDto var edgeAttributes = await edgeCategoryReceiver.GetAllAttributes(searchGraphDto.EdgeCategoryName); var validation = await AreClausesValid(searchGraphDto, sourceAttributes, targetAttributes, edgeAttributes); - if (validation.StatusCode != StatusCodeType.Success) - { - return validation; - } + if (validation.StatusCode != StatusCodeType.Success) return validation; var sourceNodes = await context.Nodes - .Where(n => searchGraphDto.SourceCategoryName == (n.NodeCategory.NodeCategoryName)).ToListAsync(); + .Where(n => searchGraphDto.SourceCategoryName == n.NodeCategory.NodeCategoryName).ToListAsync(); var targetNodes = await context.Nodes - .Where(n => searchGraphDto.TargetCategoryName == (n.NodeCategory.NodeCategoryName)).ToListAsync(); + .Where(n => searchGraphDto.TargetCategoryName == n.NodeCategory.NodeCategoryName).ToListAsync(); sourceNodes = sourceNodes.Where(sn => IsNodeValid(sn, searchGraphDto.SourceCategoryClauses)).ToList(); targetNodes = targetNodes.Where(tn => IsNodeValid(tn, searchGraphDto.TargetCategoryClauses)).ToList(); @@ -91,10 +85,10 @@ private bool IsEdgeValid(Models.Graph.Edge.Edge edge, Dictionary var edges = await context.Edges.Include(e => e.EdgeValues) .ThenInclude(ev => ev.EdgeAttribute) - .Where(e => edgeCategory == (e.EdgeCategory.EdgeCategoryName) && + .Where(e => edgeCategory == e.EdgeCategory.EdgeCategoryName && sourceNodeIds.Contains(e.EdgeSourceNodeId) && targetNodeIds.Contains(e.EdgeDestinationNodeId)) - .ToListAsync(); + .ToListAsync(); return edges; } @@ -103,26 +97,20 @@ private async Task> AreClausesValid(SearchGraphDto sear List edgeAttributes) { if (!searchGraphDto.SourceCategoryClauses.Keys.All(item => sourceAttributes.Contains(item))) - { return NotFoundResult(Resources.InvalidClauseInSourceCategory); - } if (!searchGraphDto.TargetCategoryClauses.Keys.All(item => targetAttributes.Contains(item))) - { return NotFoundResult(Resources.InvalidClauseInDestinationCategory); - } if (!searchGraphDto.EdgeCategoryClauses.Keys.All(item => edgeAttributes.Contains(item))) - { return NotFoundResult(Resources.InvalidClauseInDestinationCategory); - } return SuccessResult(); } private ActionResponse SuccessResult() { - return new ActionResponse() + return new ActionResponse { StatusCode = StatusCodeType.Success, Data = null @@ -131,10 +119,10 @@ private ActionResponse SuccessResult() private ActionResponse NotFoundResult(string message) { - return new ActionResponse() + return new ActionResponse { StatusCode = StatusCodeType.NotFound, - Data = new GraphDto() + Data = new GraphDto { Message = message } diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/IContextNodesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/IContextNodesAdditionService.cs index 2fc3f1f..e10ff7c 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/IContextNodesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/IContextNodesAdditionService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Graph.Node; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ICreateNodeCategoryService.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ICreateNodeCategoryService.cs index f905872..e6e0888 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ICreateNodeCategoryService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ICreateNodeCategoryService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Node; namespace RelationshipAnalysis.Services.GraphServices.Node.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeCategoryReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeCategoryReceiver.cs index b2feef6..d3a6bc4 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeCategoryReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeCategoryReceiver.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace RelationshipAnalysis.Services.GraphServices.Node.Abstraction; +namespace RelationshipAnalysis.Services.GraphServices.Node.Abstraction; public interface INodeCategoryReceiver { diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeValueAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeValueAdditionService.cs index 51b8602..3e1cd06 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeValueAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodeValueAdditionService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; namespace RelationshipAnalysis.Services.GraphServices.Node.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodesAdditionService.cs index d9b468a..a19e85c 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/INodesAdditionService.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Node; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ISingleNodeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ISingleNodeAdditionService.cs index dac897d..245f5ce 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ISingleNodeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/Abstraction/ISingleNodeAdditionService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; namespace RelationshipAnalysis.Services.GraphServices.Node.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/ContextNodesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/ContextNodesAdditionService.cs index b2aa1e8..e1ace10 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/ContextNodesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/ContextNodesAdditionService.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; @@ -10,10 +7,12 @@ namespace RelationshipAnalysis.Services.GraphServices.Node; -public class ContextNodesAdditionService(IMessageResponseCreator responseCreator, -ISingleNodeAdditionService singleNodeAdditionService) : IContextNodesAdditionService +public class ContextNodesAdditionService( + IMessageResponseCreator responseCreator, + ISingleNodeAdditionService singleNodeAdditionService) : IContextNodesAdditionService { - public async Task> AddToContext(string uniqueKeyHeaderName, ApplicationDbContext context, List objects, NodeCategory nodeCategory) + public async Task> AddToContext(string uniqueKeyHeaderName, ApplicationDbContext context, + List objects, NodeCategory nodeCategory) { await using (var transaction = await context.Database.BeginTransactionAsync()) { diff --git a/RelationshipAnalysis/Services/GraphServices/Node/CreateNodeCategoryService.cs b/RelationshipAnalysis/Services/GraphServices/Node/CreateNodeCategoryService.cs index bef52ef..51de42d 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/CreateNodeCategoryService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/CreateNodeCategoryService.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Node; using RelationshipAnalysis.Enums; @@ -12,22 +8,20 @@ namespace RelationshipAnalysis.Services.GraphServices.Node; -public class CreateNodeCategoryService(IServiceProvider serviceProvider, IMessageResponseCreator responseCreator) : ICreateNodeCategoryService +public class CreateNodeCategoryService(IServiceProvider serviceProvider, IMessageResponseCreator responseCreator) + : ICreateNodeCategoryService { public async Task> CreateNodeCategory(CreateNodeCategoryDto createNodeCategoryDto) { if (createNodeCategoryDto is null) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.NullDtoErrorMessage); - } if (IsNotUniqueCategoryName(createNodeCategoryDto)) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.NotUniqueCategoryNameErrorMessage); - } - + await AddCategory(createNodeCategoryDto); return responseCreator.Create(StatusCodeType.Success, Resources.SuccessfulCreateCategory); } + private async Task AddCategory(CreateNodeCategoryDto createNodeCategoryDto) { using var scope = serviceProvider.CreateScope(); diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeAttributesReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeAttributesReceiver.cs index eb12c52..238d5f6 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodeAttributesReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeAttributesReceiver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.GraphServices.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryReceiver.cs index e9c4dc8..e1d9013 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryReceiver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Services.GraphServices.Node.Abstraction; diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs index c78a3a6..12416c0 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; @@ -20,28 +14,25 @@ public Task>> GetInfo(int nodeId) var result = new Dictionary(); var selectedNode = context.Nodes.SingleOrDefault(n => n.NodeId == nodeId); - if (selectedNode == null) - { - return NotFoundResult(); - } + if (selectedNode == null) return NotFoundResult(); selectedNode.Values.ToList().ForEach(v => result.Add(v.NodeAttribute.NodeAttributeName, v.ValueData)); return SuccessResult(result); } private async Task>> NotFoundResult() { - return new ActionResponse>() + return new ActionResponse> { StatusCode = StatusCodeType.NotFound }; } - + private async Task>> SuccessResult(Dictionary result) { - return new ActionResponse>() + return new ActionResponse> { StatusCode = StatusCodeType.Success, - Data = result + Data = result }; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeValueAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeValueAdditionService.cs index 7f60532..d732287 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodeValueAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeValueAdditionService.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Models.Graph.Node; @@ -10,8 +7,8 @@ namespace RelationshipAnalysis.Services.GraphServices.Node; public class NodeValueAdditionService : INodeValueAdditionService { - - public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair kvp, Models.Graph.Node.Node newNode) + public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair kvp, + Models.Graph.Node.Node newNode) { var newNodeAttribute = await GetNewNodeAttribute(context, kvp); @@ -30,7 +27,8 @@ public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair GetNodeValue(ApplicationDbContext context, Models.Graph.Node.Node newNode, NodeAttribute newNodeAttribute) + private async Task GetNodeValue(ApplicationDbContext context, Models.Graph.Node.Node newNode, + NodeAttribute newNodeAttribute) { var value = await context.NodeValues.SingleOrDefaultAsync(nv => nv.NodeAttributeId == newNodeAttribute.NodeAttributeId && @@ -38,7 +36,8 @@ public async Task AddKvpToValues(ApplicationDbContext context, KeyValuePair GetNewNodeAttribute(ApplicationDbContext context, KeyValuePair kvp) + private async Task GetNewNodeAttribute(ApplicationDbContext context, + KeyValuePair kvp) { var newNodeAttribute = await context.NodeAttributes.SingleOrDefaultAsync(na => na.NodeAttributeName == kvp.Key); diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodesAdditionService.cs index c7db6ac..380807a 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodesAdditionService.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph.Node; @@ -10,7 +7,6 @@ using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Node.Abstraction; using INodesAdditionService = RelationshipAnalysis.Services.GraphServices.Node.Abstraction.INodesAdditionService; -using ISingleNodeAdditionService = RelationshipAnalysis.Services.GraphServices.Node.Abstraction.ISingleNodeAdditionService; namespace RelationshipAnalysis.Services.GraphServices.Node; @@ -30,20 +26,15 @@ public async Task> AddNodes(UploadNodeDto uploadNodeD nc.NodeCategoryName == uploadNodeDto.NodeCategoryName); if (nodeCategory == null) - { return responseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidNodeCategory); - } var validationResult = csvValidatorService.Validate(uploadNodeDto.File, uploadNodeDto.UniqueKeyHeaderName); - - if (validationResult.StatusCode == StatusCodeType.BadRequest) - { - return validationResult; - } + + if (validationResult.StatusCode == StatusCodeType.BadRequest) return validationResult; var objects = await csvProcessorService.ProcessCsvAsync(uploadNodeDto.File); - return await contextAdditionService.AddToContext(uploadNodeDto.UniqueKeyHeaderName, context, objects, nodeCategory); + return await contextAdditionService.AddToContext(uploadNodeDto.UniqueKeyHeaderName, context, objects, + nodeCategory); } - } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Node/SingleNodeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Node/SingleNodeAdditionService.cs index 166b733..75bdb3e 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/SingleNodeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/SingleNodeAdditionService.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Context; -using RelationshipAnalysis.Models.Graph.Node; using RelationshipAnalysis.Services.GraphServices.Node.Abstraction; namespace RelationshipAnalysis.Services.GraphServices.Node; @@ -14,33 +10,21 @@ public class SingleNodeAdditionService(INodeValueAdditionService nodeValueAdditi public async Task AddSingleNode(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, int nodeCategoryId) { - if (((string)record[uniqueHeaderName]).IsNullOrEmpty()) - { - throw new Exception(Resources.FailedAddRecordsMessage); - } + if (((string)record[uniqueHeaderName]).IsNullOrEmpty()) throw new Exception(Resources.FailedAddRecordsMessage); var newNode = await GetNewNode(context, record, uniqueHeaderName, nodeCategoryId); - foreach (var kvp in record) - { - try - { - await nodeValueAdditionService.AddKvpToValues(context, kvp, newNode); - } - catch(Exception e) - { - throw; - } - } + foreach (var kvp in record) await nodeValueAdditionService.AddKvpToValues(context, kvp, newNode); } - private async Task GetNewNode(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, + private async Task GetNewNode(ApplicationDbContext context, + IDictionary record, string uniqueHeaderName, int nodeCategoryId) { var newNode = await context.Nodes.SingleOrDefaultAsync(n => n.NodeUniqueString == (string)record[uniqueHeaderName] && n.NodeCategoryId == nodeCategoryId); - + if (newNode == null) { newNode = new Models.Graph.Node.Node @@ -49,7 +33,7 @@ public async Task AddSingleNode(ApplicationDbContext context, IDictionary Create(StatusCodeType statusCodeType, string message) { - return new ActionResponse() + return new ActionResponse { StatusCode = statusCodeType, Data = new MessageDto(message) diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserDtoCreator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserDtoCreator.cs index 57db847..f366e9b 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserDtoCreator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserDtoCreator.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto.Panel.Admin; +using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.AllUserService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserService.cs index 1dd9510..3c2b919 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserService.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.Admin; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; using GetAllUsersDto = RelationshipAnalysis.Dto.Panel.Admin.GetAllUsersDto; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserServiceValidator.cs index defd073..c92504a 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/Abstraction/IAllUserServiceValidator.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreator.cs index c703690..d722a42 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserDtoCreator.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using AutoMapper; +using AutoMapper; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; @@ -25,7 +23,7 @@ public async Task Create(List users) userOutputs.Add(data); } - return new GetAllUsersDto() + return new GetAllUsersDto { Users = userOutputs, AllUserCount = await userReceiver.ReceiveAllUserCountAsync() diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserService.cs index 99857d2..b04965a 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; @@ -17,8 +15,8 @@ public async Task> GetAllUser(List users) { var validateResult = await validator.Validate(users); if (validateResult.StatusCode != StatusCodeType.Success) return validateResult; - - + + var userOutPuts = await allUserDtoCreator.Create(users); diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidator.cs index 382aa30..ba39e68 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/AllUserService/AllUserServiceValidator.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.IdentityModel.Tokens; +using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Enums; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateService.cs index 81c401e..2d1619e 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.Admin; +using RelationshipAnalysis.Dto; using CreateUserDto = RelationshipAnalysis.Dto.Panel.Admin.CreateUserDto; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.CreateUserService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateServiceValidator.cs index 460ffee..e031534 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/Abstraction/IUserCreateServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.CreateUserService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateService.cs index 1d56887..df653ff 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Services.CRUD.Role.Abstraction; @@ -31,6 +30,6 @@ private async Task AddUser(CreateUserDto createUserDto) var user = mapper.Map(createUserDto); await userAdder.AddUserAsync(user); var roles = await roleReceiver.ReceiveRolesListAsync(createUserDto.Roles); - await userRolesAdder.AddUserRoles(roles , user); + await userRolesAdder.AddUserRoles(roles, user); } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateServiceValidator.cs index ea03afb..f323029 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/CreateUserService/UserCreateServiceValidator.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.IdentityModel.Tokens; +using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.Admin; @@ -22,26 +18,22 @@ public Task> Validate(CreateUserDto createUserDto) var context = scope.ServiceProvider.GetRequiredService(); if (context.Users.Select(x => x.Username).ToList().Contains(createUserDto.Username)) - { - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.UsernameExistsMessage)); - } - + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.UsernameExistsMessage)); + if (context.Users.Select(x => x.Email).ToList().Contains(createUserDto.Email)) - { - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmailExistsMessage)); - } + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.EmailExistsMessage)); if (createUserDto.Roles.IsNullOrEmpty()) - { - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmptyRolesMessage)); - } + return Task.FromResult( + messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmptyRolesMessage)); var invalidRoles = createUserDto.Roles.FindAll(r => !context.Roles.Select(role => role.Name) .Contains(r)); if (invalidRoles.Any()) - { - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidRolesListMessage)); - } + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.InvalidRolesListMessage)); return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, Resources.SucceddfulCreateUser)); } diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteService.cs index 50076f3..19ddd23 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteServiceValidator.cs index 09071be..659a4cf 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/Abstraction/IUserDeleteServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteService.cs index 402e429..a4812b3 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteService.cs @@ -1,8 +1,6 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; -using RelationshipAnalysis.Services.Abstraction; using RelationshipAnalysis.Services.CRUD.User.Abstraction; using RelationshipAnalysis.Services.Panel.AdminPanelServices.UserDeleteService.Abstraction; @@ -17,7 +15,7 @@ public async Task> DeleteUser(User user) { var validateResult = await validator.Validate(user); if (validateResult.StatusCode != StatusCodeType.Success) return validateResult; - + await userDeleter.DeleteUserAsync(user); return validateResult; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceValidator.cs index d8d95cf..6795bb4 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserDeleteService/UserDeleteServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; using RelationshipAnalysis.Services.Abstraction; @@ -12,10 +11,10 @@ public class UserDeleteServiceValidator(IMessageResponseCreator messageResponseC public Task> Validate(User user) { if (user is null) - { - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); - } - - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, Resources.SuccessfulDeleteUserMessage)); + return Task.FromResult( + messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); + + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, + Resources.SuccessfulDeleteUserMessage)); } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesService.cs index 3546791..c50cd88 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesServiceValidator.cs index d09980c..f66f1af 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/Abstraction/IUserUpdateRolesServiceValidator.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesService.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesService.cs index b309655..eea2e46 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesService.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesService.cs @@ -1,9 +1,6 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; -using RelationshipAnalysis.Services.Abstraction; using RelationshipAnalysis.Services.CRUD.Role.Abstraction; using RelationshipAnalysis.Services.CRUD.UserRole.Abstraction; using RelationshipAnalysis.Services.Panel.AdminPanelServices.UserUpdateRolesService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidator.cs b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidator.cs index 9389caa..c1d2b8f 100644 --- a/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/AdminPanelServices/UserUpdateRolesService/UserUpdateRolesServiceValidator.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.IdentityModel.Tokens; +using Microsoft.IdentityModel.Tokens; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Enums; @@ -20,15 +15,18 @@ public class UserUpdateRolesServiceValidator( public Task> Validate(User user, List newRoles) { if (newRoles.IsNullOrEmpty()) - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmptyRolesMessage)); + return Task.FromResult( + messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmptyRolesMessage)); using var scope = serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); var invalidRoles = newRoles.FindAll(r => !context.Roles.Select(role => role.Name) .Contains(r)); if (invalidRoles.Any()) - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.InvalidRolesListMessage)); - - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, Resources.SuccessfulUpdateRolesMessage)); + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.InvalidRolesListMessage)); + + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, + Resources.SuccessfulUpdateRolesMessage)); } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/Abstraction/ILogoutService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/Abstraction/ILogoutService.cs index 86c8d3d..e1f222d 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/Abstraction/ILogoutService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/Abstraction/ILogoutService.cs @@ -1,5 +1,3 @@ -using Microsoft.AspNetCore.Http; - namespace RelationshipAnalysis.Services.Panel.UserPanelServices.LogoutService.Abstraction; public interface ILogoutService diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/LogoutService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/LogoutService.cs index aa4fb06..8afe221 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/LogoutService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/LogoutService/LogoutService.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Http; using RelationshipAnalysis.Services.Panel.UserPanelServices.LogoutService.Abstraction; namespace RelationshipAnalysis.Services.Panel.UserPanelServices.LogoutService; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/Abstraction/IPermissionService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/Abstraction/IPermissionService.cs index 6f81f19..9b1feec 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/Abstraction/IPermissionService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/Abstraction/IPermissionService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.User; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Models.Auth; using PermissionDto = RelationshipAnalysis.Dto.Panel.User.PermissionDto; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/PermissionService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/PermissionService.cs index a1daefa..9e7ee93 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/PermissionService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/PermissionsService/PermissionService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoService.cs index 3a7bc87..2f68f1c 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; using UserOutputInfoDto = RelationshipAnalysis.Dto.Panel.User.UserOutputInfoDto; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoServiceValidator.cs index 58c6838..f50cdeb 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserInfoServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserOutputInfoDtoCreator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserOutputInfoDtoCreator.cs index 93d0659..6580bfc 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserOutputInfoDtoCreator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/Abstraction/IUserOutputInfoDtoCreator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto.Panel.User; +using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; namespace RelationshipAnalysis.Services.Panel.UserPanelServices.UserInfoService.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoService.cs index eae0f1c..4e9c80d 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoService.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; @@ -18,7 +17,7 @@ public async Task> GetUser(User user) return validateResult; validateResult.Data = await userOutputInfoDtoCreator.Create(user); - + return validateResult; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceValidator.cs index 01efaa8..83893d7 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserInfoServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreator.cs index 03ef2c7..90ee542 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserInfoService/UserOutputInfoDtoCreator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using AutoMapper; +using AutoMapper; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; using RelationshipAnalysis.Services.CRUD.Role.Abstraction; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoService.cs index 11f8402..7657193 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoService.cs @@ -1,7 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; using UserUpdateInfoDto = RelationshipAnalysis.Dto.Panel.User.UserUpdateInfoDto; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoServiceValidator.cs index f1984e6..be53e4f 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/Abstraction/IUserUpdateInfoServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoService.cs index 08a5592..bf59888 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; using AutoMapper; -using Microsoft.AspNetCore.Http; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; @@ -21,7 +19,7 @@ public async Task> UpdateUserAsync(User user, UserUpd var validateResult = await validator.Validate(user, userUpdateInfoDto); if (validateResult.StatusCode != StatusCodeType.Success) return validateResult; - + await UpdateInfo(user, userUpdateInfoDto); return validateResult; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidator.cs index 270df43..1342aeb 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdateInfoService/UserUpdateInfoServiceValidator.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using RelationshipAnalysis.Context; +using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; @@ -18,17 +14,22 @@ public class UserUpdateInfoServiceValidator( { public Task> Validate(User user, UserUpdateInfoDto userUpdateInfoDto) { - if (user == null) return Task.FromResult(messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); + if (user == null) + return Task.FromResult( + messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); if (!IsUsernameUnique(user.Username, userUpdateInfoDto.Username)) - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.UsernameExistsMessage)); + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.UsernameExistsMessage)); if (!IsEmailUnique(user.Email, userUpdateInfoDto.Email)) - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.EmailExistsMessage)); - - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, Resources.SuccessfulUpdateUserMessage)); + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.EmailExistsMessage)); + + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, + Resources.SuccessfulUpdateUserMessage)); } - + private bool IsUsernameUnique(string currentValue, string newValue) { if (currentValue == newValue) return true; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordService.cs index f58203f..04223be 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto; -using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; using UserPasswordInfoDto = RelationshipAnalysis.Dto.Panel.User.UserPasswordInfoDto; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordServiceValidator.cs index 50ee11f..ebccf6e 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/Abstraction/IUserUpdatePasswordServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Models.Auth; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordService.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordService.cs index c3a79e3..d0df8b3 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordService.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordService.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; @@ -19,7 +18,7 @@ public async Task> UpdatePasswordAsync(User user, Use var validateResult = await validator.Validate(user, passwordInfoDto); if (validateResult.StatusCode != StatusCodeType.Success) return validateResult; - + await UpdatePassword(user, passwordInfoDto); return validateResult; diff --git a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidator.cs b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidator.cs index 328ca55..6de0f48 100644 --- a/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidator.cs +++ b/RelationshipAnalysis/Services/Panel/UserPanelServices/UserUpdatePasswordService/UserUpdatePasswordServiceValidator.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Panel.User; using RelationshipAnalysis.Enums; using RelationshipAnalysis.Models.Auth; @@ -15,9 +14,13 @@ public class UserUpdatePasswordServiceValidator( { public Task> Validate(User user, UserPasswordInfoDto passwordInfoDto) { - if (user is null) return Task.FromResult(messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); + if (user is null) + return Task.FromResult( + messageResponseCreator.Create(StatusCodeType.NotFound, Resources.UserNotFoundMessage)); if (!passwordVerifier.VerifyPasswordHash(passwordInfoDto.OldPassword, user.PasswordHash)) - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, Resources.WrongOldPasswordMessage)); - return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, Resources.SuccessfulUpdateUserMessage)); + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.BadRequest, + Resources.WrongOldPasswordMessage)); + return Task.FromResult(messageResponseCreator.Create(StatusCodeType.Success, + Resources.SuccessfulUpdateUserMessage)); } } \ No newline at end of file diff --git a/RelationshipAnalysis/appsettings.json b/RelationshipAnalysis/appsettings.json index 4995c24..0de36ab 100644 --- a/RelationshipAnalysis/appsettings.json +++ b/RelationshipAnalysis/appsettings.json @@ -1,7 +1,7 @@ { "DefaultPassword": "admin", "Jwt": { - "CookieName" : "jwt", + "CookieName": "jwt", "Key": "kajbdiuhdqhpjQE89HBSDJIABFCIWSGF89GW3EJFBWEIUBCZNMXCJNLZDKNJKSNJKFBIGW3EASHHDUIASZGCUI", "ExpireMinutes": 60 }, From 70d178b522ea68e51fd15f5cba18f4367ee9ffeb Mon Sep 17 00:00:00 2001 From: SwimmingRieux <141845753+SwimmingRieux@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:07:00 +0330 Subject: [PATCH 2/2] Expansion refactor (#61) * merge * refactor and tdd for expansion services --- .../Edge/EdgeCategoryNameValidatorTests.cs | 73 +++++++++++ .../ExpansionCategoriesValidatorTests.cs | 105 ++++++++++++++++ .../Graph/ExpansionGraphReceiverTests.cs | 118 ++++++++++++++++++ .../Node/NodeCategoryNameValidatorTests.cs | 73 +++++++++++ RelationshipAnalysis/Program.cs | 3 + .../Abstraction/ICategoryNameValidator.cs | 6 + .../Edge/EdgeCategoryNameValidator.cs | 17 +++ .../GraphServices/Edge/EdgeInfoReceiver.cs | 2 +- .../IExpansionCategoriesValidator.cs | 12 ++ .../Abstraction/IExpansionGraphReceiver.cs | 2 +- .../Graph/ExpansionCategoriesValidator.cs | 45 +++++++ .../Graph/ExpansionGraphReceiver.cs | 76 +++++------ .../Node/NodeCategoryNameValidator.cs | 17 +++ .../GraphServices/Node/NodeInfoReceiver.cs | 2 +- 14 files changed, 511 insertions(+), 40 deletions(-) create mode 100644 RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgeCategoryNameValidatorTests.cs create mode 100644 RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionCategoriesValidatorTests.cs create mode 100644 RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionGraphReceiverTests.cs create mode 100644 RelationshipAnalysis.Test/Services/GraphServices/Node/NodeCategoryNameValidatorTests.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Abstraction/ICategoryNameValidator.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryNameValidator.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionCategoriesValidator.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Graph/ExpansionCategoriesValidator.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryNameValidator.cs diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgeCategoryNameValidatorTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgeCategoryNameValidatorTests.cs new file mode 100644 index 0000000..329001b --- /dev/null +++ b/RelationshipAnalysis.Test/Services/GraphServices/Edge/EdgeCategoryNameValidatorTests.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Models.Graph.Edge; +using RelationshipAnalysis.Services.GraphServices.Edge; +using Xunit; + +namespace RelationshipAnalysis.Test.Services.GraphServices.Edge +{ + public class EdgeCategoryNameValidatorTests + { + private readonly ServiceProvider _serviceProvider; + private readonly EdgeCategoryNameValidator _sut; + + public EdgeCategoryNameValidatorTests() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "TestEdgeDb") + .Options; + + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _sut = new EdgeCategoryNameValidator(_serviceProvider); + } + + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.EdgeCategories.AddRange(new List + { + new EdgeCategory { EdgeCategoryName = "EdgeCategory1" }, + new EdgeCategory { EdgeCategoryName = "EdgeCategory2" } + }); + context.SaveChanges(); + } + + [Fact] + public async Task Validate_ShouldReturnTrue_WhenCategoryExists() + { + // Arrange + SeedDatabase(); + var categoryName = "EdgeCategory1"; + + // Act + var result = await _sut.Validate(categoryName); + + // Assert + Assert.True(result); + } + + [Fact] + public async Task Validate_ShouldReturnFalse_WhenCategoryDoesNotExist() + { + // Arrange + SeedDatabase(); + var categoryName = "NonExistentEdgeCategory"; + + // Act + var result = await _sut.Validate(categoryName); + + // Assert + Assert.False(result); + } + } +} diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionCategoriesValidatorTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionCategoriesValidatorTests.cs new file mode 100644 index 0000000..1ee34c0 --- /dev/null +++ b/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionCategoriesValidatorTests.cs @@ -0,0 +1,105 @@ +using System.Threading.Tasks; +using NSubstitute; +using Xunit; +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Services.GraphServices.Graph; +using RelationshipAnalysis.Services.GraphServices.Abstraction; +using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; + +namespace RelationshipAnalysis.Test.Services.GraphServices.Graph +{ + public class ExpansionCategoriesValidatorTests + { + private readonly ICategoryNameValidator _nodeCategoryValidator; + private readonly ICategoryNameValidator _edgeCategoryValidator; + private readonly ExpansionCategoriesValidator _sut; + + public ExpansionCategoriesValidatorTests() + { + _nodeCategoryValidator = Substitute.For(); + _edgeCategoryValidator = Substitute.For(); + + _sut = new ExpansionCategoriesValidator(_nodeCategoryValidator, _edgeCategoryValidator); + } + + [Fact] + public async Task ValidateCategories_ShouldReturnInvalidSourceCategory_WhenSourceCategoryIsInvalid() + { + // Arrange + var sourceCategoryName = "InvalidSource"; + var targetCategoryName = "ValidTarget"; + var edgeCategoryName = "ValidEdge"; + + _nodeCategoryValidator.Validate(sourceCategoryName).Returns(Task.FromResult(false)); + _nodeCategoryValidator.Validate(targetCategoryName).Returns(Task.FromResult(true)); + _edgeCategoryValidator.Validate(edgeCategoryName).Returns(Task.FromResult(true)); + + // Act + var result = await _sut.ValidateCategories(sourceCategoryName, targetCategoryName, edgeCategoryName); + + // Assert + Assert.False(result.isValid); + Assert.Equal(Resources.InvalidSourceNodeCategory, result.graphDto.Message); + } + + [Fact] + public async Task ValidateCategories_ShouldReturnInvalidTargetCategory_WhenTargetCategoryIsInvalid() + { + // Arrange + var sourceCategoryName = "ValidSource"; + var targetCategoryName = "InvalidTarget"; + var edgeCategoryName = "ValidEdge"; + + _nodeCategoryValidator.Validate(sourceCategoryName).Returns(Task.FromResult(true)); + _nodeCategoryValidator.Validate(targetCategoryName).Returns(Task.FromResult(false)); + _edgeCategoryValidator.Validate(edgeCategoryName).Returns(Task.FromResult(true)); + + // Act + var result = await _sut.ValidateCategories(sourceCategoryName, targetCategoryName, edgeCategoryName); + + // Assert + Assert.False(result.isValid); + Assert.Equal(Resources.InvalidTargetNodeCategory, result.graphDto.Message); + } + + [Fact] + public async Task ValidateCategories_ShouldReturnInvalidEdgeCategory_WhenEdgeCategoryIsInvalid() + { + // Arrange + var sourceCategoryName = "ValidSource"; + var targetCategoryName = "ValidTarget"; + var edgeCategoryName = "InvalidEdge"; + + _nodeCategoryValidator.Validate(sourceCategoryName).Returns(Task.FromResult(true)); + _nodeCategoryValidator.Validate(targetCategoryName).Returns(Task.FromResult(true)); + _edgeCategoryValidator.Validate(edgeCategoryName).Returns(Task.FromResult(false)); + + // Act + var result = await _sut.ValidateCategories(sourceCategoryName, targetCategoryName, edgeCategoryName); + + // Assert + Assert.False(result.isValid); + Assert.Equal(Resources.InvalidEdgeCategory, result.graphDto.Message); + } + + [Fact] + public async Task ValidateCategories_ShouldReturnValidResult_WhenAllCategoriesAreValid() + { + // Arrange + var sourceCategoryName = "ValidSource"; + var targetCategoryName = "ValidTarget"; + var edgeCategoryName = "ValidEdge"; + + _nodeCategoryValidator.Validate(sourceCategoryName).Returns(Task.FromResult(true)); + _nodeCategoryValidator.Validate(targetCategoryName).Returns(Task.FromResult(true)); + _edgeCategoryValidator.Validate(edgeCategoryName).Returns(Task.FromResult(true)); + + // Act + var result = await _sut.ValidateCategories(sourceCategoryName, targetCategoryName, edgeCategoryName); + + // Assert + Assert.True(result.isValid); + Assert.Null(result.graphDto); + } + } +} diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionGraphReceiverTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionGraphReceiverTests.cs new file mode 100644 index 0000000..777c06b --- /dev/null +++ b/RelationshipAnalysis.Test/Services/GraphServices/Graph/ExpansionGraphReceiverTests.cs @@ -0,0 +1,118 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Models.Graph.Edge; +using RelationshipAnalysis.Models.Graph.Node; +using RelationshipAnalysis.Services.GraphServices.Graph; +using Moq; +using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; + +namespace RelationshipAnalysis.Test.Services.GraphServices.Graph; + +public class ExpansionGraphReceiverTests +{ + private readonly IServiceProvider _serviceProvider; + private readonly ExpansionGraphReceiver _sut; + private readonly Mock _graphDtoCreatorMock; + private readonly Mock _expansionCategoriesValidatorMock; + + private readonly Models.Graph.Node.Node _node1; + private readonly Models.Graph.Node.Node _node2; + private readonly Models.Graph.Edge.Edge _edge1; + private readonly NodeCategory _sourceCategory; + private readonly NodeCategory _targetCategory; + private readonly EdgeCategory _edgeCategory; + + public ExpansionGraphReceiverTests() + { + + _sourceCategory = new() { NodeCategoryId = 1, NodeCategoryName = "SourceCategory" }; + _targetCategory = new() { NodeCategoryId = 2, NodeCategoryName = "TargetCategory" }; + _edgeCategory = new() { EdgeCategoryId = 2, EdgeCategoryName = "EdgeCategory" }; + _node1 = new() { NodeId = 1, NodeUniqueString = "1", NodeCategoryId = 1}; + _node2 = new() { NodeId = 2, NodeUniqueString = "2", NodeCategoryId = 2}; + _edge1 = new() { EdgeId = 1, EdgeUniqueString = "1", EdgeSourceNodeId = 1, EdgeDestinationNodeId = 2, EdgeCategoryId = 2 }; + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .UseLazyLoadingProxies() + .Options; + + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _graphDtoCreatorMock = new Mock(); + _expansionCategoriesValidatorMock = new Mock(); + + _sut = new ExpansionGraphReceiver(_serviceProvider, _graphDtoCreatorMock.Object, _expansionCategoriesValidatorMock.Object); + } + + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.EdgeCategories.AddRange(new List { _edgeCategory }); + context.NodeCategories.AddRange(new List { _sourceCategory, _targetCategory }); + context.Nodes.AddRange(new List { _node1, _node2 }); + context.Edges.AddRange(new List { _edge1 }); + context.SaveChanges(); + } + + [Fact] + public async Task GetExpansionGraph_ShouldReturnGraphDto_WhenCategoriesAreValid() + { + // Arrange + SeedDatabase(); + _expansionCategoriesValidatorMock.Setup(v => v.ValidateCategories(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync((true, new GraphDto())); + + _graphDtoCreatorMock.Setup(c => c.CreateResultGraphDto(It.IsAny>(), It.IsAny>())) + .Returns(new GraphDto()); + + // Act + var result = await _sut.GetExpansionGraph(1, "SourceCategory", "TargetCategory", "EdgeCategory"); + + // Assert + Assert.NotNull(result); + _expansionCategoriesValidatorMock.Verify(v => v.ValidateCategories(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + _graphDtoCreatorMock.Verify(c => c.CreateResultGraphDto(It.IsAny>(), It.IsAny>()), Times.Once); + } + + [Fact] + public async Task GetExpansionGraph_ShouldReturnInvalidGraphDto_WhenCategoriesAreInvalid() + { + // Arrange + _expansionCategoriesValidatorMock.Setup(v => v.ValidateCategories(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync((false, new GraphDto())); + + // Act + var result = await _sut.GetExpansionGraph(1, "InvalidSourceCategory", "InvalidTargetCategory", "InvalidEdgeCategory"); + + // Assert + Assert.NotNull(result); + _expansionCategoriesValidatorMock.Verify(v => v.ValidateCategories(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + _graphDtoCreatorMock.Verify(c => c.CreateResultGraphDto(It.IsAny>(), It.IsAny>()), Times.Never); + } + + [Fact] + public async Task GetExpansionGraph_ShouldReturnEmptyGraphDto_WhenThereAreNoValidEdges() + { + // Arrange + SeedDatabase(); + _expansionCategoriesValidatorMock.Setup(v => v.ValidateCategories(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync((true, new GraphDto())); + + _graphDtoCreatorMock.Setup(c => c.CreateResultGraphDto(It.IsAny>(), It.IsAny>())) + .Returns(new GraphDto()); + + // Act + var result = await _sut.GetExpansionGraph(999, "SourceCategory", "TargetCategory", "EdgeCategory"); + + // Assert + Assert.NotNull(result); + _graphDtoCreatorMock.Verify(c => c.CreateResultGraphDto(It.Is>(nodes => nodes.Count == 0), It.Is>(edges => edges.Count == 0)), Times.Once); + } +} diff --git a/RelationshipAnalysis.Test/Services/GraphServices/Node/NodeCategoryNameValidatorTests.cs b/RelationshipAnalysis.Test/Services/GraphServices/Node/NodeCategoryNameValidatorTests.cs new file mode 100644 index 0000000..1baffe9 --- /dev/null +++ b/RelationshipAnalysis.Test/Services/GraphServices/Node/NodeCategoryNameValidatorTests.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Models.Graph.Node; +using RelationshipAnalysis.Services.GraphServices.Node; +using Xunit; + +namespace RelationshipAnalysis.Test.Services.GraphServices.Node +{ + public class NodeCategoryNameValidatorTests + { + private readonly ServiceProvider _serviceProvider; + private readonly NodeCategoryNameValidator _sut; + + public NodeCategoryNameValidatorTests() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "TestNodeDb") + .Options; + + serviceCollection.AddScoped(_ => new ApplicationDbContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _sut = new NodeCategoryNameValidator(_serviceProvider); + } + + private void SeedDatabase() + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.NodeCategories.AddRange(new List + { + new NodeCategory { NodeCategoryName = "Category1" }, + new NodeCategory { NodeCategoryName = "Category2" } + }); + context.SaveChanges(); + } + + [Fact] + public async Task Validate_ShouldReturnTrue_WhenCategoryExists() + { + // Arrange + SeedDatabase(); + var categoryName = "Category1"; + + // Act + var result = await _sut.Validate(categoryName); + + // Assert + Assert.True(result); + } + + [Fact] + public async Task Validate_ShouldReturnFalse_WhenCategoryDoesNotExist() + { + // Arrange + SeedDatabase(); + var categoryName = "NonExistentCategory"; + + // Act + var result = await _sut.Validate(categoryName); + + // Assert + Assert.False(result); + } + } +} diff --git a/RelationshipAnalysis/Program.cs b/RelationshipAnalysis/Program.cs index f1415c4..67d8dda 100644 --- a/RelationshipAnalysis/Program.cs +++ b/RelationshipAnalysis/Program.cs @@ -115,6 +115,9 @@ .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() + .AddKeyedSingleton("node") + .AddKeyedSingleton("edge") .AddKeyedSingleton("node") .AddKeyedSingleton("edge") .AddKeyedSingleton("node") diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/ICategoryNameValidator.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICategoryNameValidator.cs new file mode 100644 index 0000000..92c52f7 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/ICategoryNameValidator.cs @@ -0,0 +1,6 @@ +namespace RelationshipAnalysis.Services.GraphServices.Abstraction; + +public interface ICategoryNameValidator +{ + public Task Validate(string categoryName); +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryNameValidator.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryNameValidator.cs new file mode 100644 index 0000000..1993951 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeCategoryNameValidator.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices.Edge; + +public class EdgeCategoryNameValidator(IServiceProvider serviceProvider) : ICategoryNameValidator +{ + public async Task Validate(string categoryName) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var categoryNames = await context.EdgeCategories.Select(ec => ec.EdgeCategoryName).ToListAsync(); + if (categoryNames.Contains(categoryName)) return true; + return false; + } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs index 8ae1ed3..49bc729 100644 --- a/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Edge/EdgeInfoReceiver.cs @@ -3,7 +3,7 @@ using RelationshipAnalysis.Enums; using RelationshipAnalysis.Services.GraphServices.Abstraction; -namespace RelationshipAnalysis.Services.GraphServices; +namespace RelationshipAnalysis.Services.GraphServices.Edge; public class EdgeInfoReceiver(IServiceProvider serviceProvider) : IInfoReceiver { diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionCategoriesValidator.cs b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionCategoriesValidator.cs new file mode 100644 index 0000000..268c076 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionCategoriesValidator.cs @@ -0,0 +1,12 @@ +using RelationshipAnalysis.Dto.Graph; + +namespace RelationshipAnalysis.Services.GraphServices.Graph.Abstraction +{ + public interface IExpansionCategoriesValidator + { + Task<(bool isValid, GraphDto graphDto)> ValidateCategories( + string sourceCategoryName, + string targetCategoryName, + string edgeCategoryName); + } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs index 9bdca46..a36c2eb 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/Abstraction/IExpansionGraphReceiver.cs @@ -1,6 +1,6 @@ using RelationshipAnalysis.Dto.Graph; -namespace RelationshipAnalysis.Services.GraphServices.Abstraction; +namespace RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; public interface IExpansionGraphReceiver { diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionCategoriesValidator.cs b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionCategoriesValidator.cs new file mode 100644 index 0000000..0fe4110 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionCategoriesValidator.cs @@ -0,0 +1,45 @@ +using System.Threading.Tasks; +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Services.GraphServices.Abstraction; +using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices.Graph +{ + public class ExpansionCategoriesValidator( + [FromKeyedServices("node")] ICategoryNameValidator nodeCategoryValidator, + [FromKeyedServices("edge")] ICategoryNameValidator edgeCategoryValidator) + : IExpansionCategoriesValidator + { + public async Task<(bool isValid, GraphDto graphDto)> ValidateCategories( + string sourceCategoryName, + string targetCategoryName, + string edgeCategoryName) + { + if (!await nodeCategoryValidator.Validate(sourceCategoryName)) + { + return (false, new GraphDto + { + Message = Resources.InvalidSourceNodeCategory + }); + } + + if (!await nodeCategoryValidator.Validate(targetCategoryName)) + { + return (false, new GraphDto + { + Message = Resources.InvalidTargetNodeCategory + }); + } + + if (!await edgeCategoryValidator.Validate(edgeCategoryName)) + { + return (false, new GraphDto + { + Message = Resources.InvalidEdgeCategory + }); + } + + return (true, null); + } + } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs index 2f6a862..abf5047 100644 --- a/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Graph/ExpansionGraphReceiver.cs @@ -4,49 +4,51 @@ using RelationshipAnalysis.Services.GraphServices.Abstraction; using RelationshipAnalysis.Services.GraphServices.Graph.Abstraction; -namespace RelationshipAnalysis.Services.GraphServices; -public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator) - : IExpansionGraphReceiver +namespace RelationshipAnalysis.Services.GraphServices.Graph { - public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, - string edgeCategoryName) + public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator, + IExpansionCategoriesValidator expansionCategoriesValidator) : IExpansionGraphReceiver { - using var scope = serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - var inputNodes = await GetInputNodes(context, sourceCategoryName); - var outputNodes = await GetOutputNodes(context, targetCategoryName); - var validEdges = await GetValidEdges(nodeId, context, edgeCategoryName, inputNodes, outputNodes); + public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, string edgeCategoryName) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); - return graphDtoCreator.CreateResultGraphDto(inputNodes.Union(outputNodes).ToList(), validEdges); - } - private async Task> GetValidEdges(int nodeId, ApplicationDbContext context, - string edgeCategoryName, List inputNodes, - List outputNodes) - { - var validEdges = await context.Edges.Where(e => - (e.EdgeSourceNodeId == nodeId || e.EdgeDestinationNodeId == nodeId) && - e.EdgeCategory.EdgeCategoryName == edgeCategoryName && - inputNodes.Contains(e.NodeSource) && - outputNodes.Contains(e.NodeDestination)).ToListAsync(); - return validEdges; - } + var (isValid, graphDto) = await expansionCategoriesValidator.ValidateCategories(sourceCategoryName, targetCategoryName, edgeCategoryName); + if (!isValid) + { + return graphDto; + } - private async Task> GetOutputNodes(ApplicationDbContext context, - string targetCategoryName) - { - var outputNodes = - await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == targetCategoryName).ToListAsync(); - return outputNodes; - } + var allEdges = await context.Edges.ToListAsync(); + var validEdges = GetValidEdges(nodeId, allEdges, edgeCategoryName, sourceCategoryName, targetCategoryName); + var validNodes = GetValidNodes(validEdges); - private async Task> GetInputNodes(ApplicationDbContext context, - string sourceCategoryName) - { - var inputNodes = - await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == sourceCategoryName).ToListAsync(); - return inputNodes; + return graphDtoCreator.CreateResultGraphDto(validNodes, validEdges); + } + + private List GetValidNodes(List validEdges) + { + var validNodes = new HashSet(); + validEdges.ForEach(e => validNodes.Add(e.NodeSource)); + validEdges.ForEach(e => validNodes.Add(e.NodeDestination)); + return validNodes.ToList(); + } + + private List GetValidEdges(int nodeId, List edges, + string edgeCategoryName, string sourceCategory, string targetCategory) + { + var categoryEdges = edges.FindAll(e => e.EdgeCategory.EdgeCategoryName == edgeCategoryName); + var inEdges = categoryEdges.FindAll(e => + e.EdgeDestinationNodeId == nodeId && e.NodeSource.NodeCategory.NodeCategoryName == sourceCategory); + var outEdges = categoryEdges.FindAll(e => + e.EdgeSourceNodeId == nodeId && + e.NodeDestination.NodeCategory.NodeCategoryName == targetCategory); + var resultEdges = inEdges.Union(outEdges).ToList(); + return resultEdges; + } } -} \ No newline at end of file +} diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryNameValidator.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryNameValidator.cs new file mode 100644 index 0000000..477d03f --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeCategoryNameValidator.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices.Node; + +public class NodeCategoryNameValidator(IServiceProvider serviceProvider) : ICategoryNameValidator +{ + public async Task Validate(string categoryName) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var categoryNames = await context.NodeCategories.Select(nc => nc.NodeCategoryName).ToListAsync(); + if (categoryNames.Contains(categoryName)) return true; + return false; + } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs index 12416c0..217b1eb 100644 --- a/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Node/NodeInfoReceiver.cs @@ -3,7 +3,7 @@ using RelationshipAnalysis.Enums; using RelationshipAnalysis.Services.GraphServices.Abstraction; -namespace RelationshipAnalysis.Services.GraphServices; +namespace RelationshipAnalysis.Services.GraphServices.Node; public class NodeInfoReceiver(IServiceProvider serviceProvider) : IInfoReceiver {