-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor(*): services and tests (#54)
* Folders & Reformat! * Add MessageResponseCreator class. * Add CRUD classes. * add tests and refactor graph dto creator * fixed messages functions for create node categories * fix response messages and create an interface * add tests for nodes addition services and refactor * fix response messages in EdgesAdditionService.cs * add ContextEdgesAdditionService.cs * add EdgeValueAdditionService.cs * add ContextEdgesAdditionService.cs * fix tests for edges addition classes * Refactor & DI. * Merge Graph refactor. * Fix namespace * Fix refactor * fix bugs and refactor --------- Co-authored-by: Mohammad Saleh Mahdinejad <[email protected]>
- Loading branch information
1 parent
861bdad
commit ff8b1a4
Showing
216 changed files
with
3,588 additions
and
2,944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using RelationshipAnalysis.Context; | ||
using RelationshipAnalysis.Models.Auth; | ||
using RelationshipAnalysis.Services.UserPanelServices.Abstraction.AuthServices; | ||
using RelationshipAnalysis.Services.AuthServices; | ||
|
||
namespace RelationAnalysis.Migrations; | ||
|
||
public class InitialRecordsCreator(ApplicationDbContext context, IConfiguration configuration) | ||
{ | ||
public async Task AddInitialRecords() | ||
{ | ||
var roles = new List<Role>() | ||
var roles = new List<Role> | ||
{ | ||
new Role() | ||
new() | ||
{ | ||
Name = "Admin", | ||
Permissions = | ||
"[\"/api/Admin\",\"/api/Auth\", \"/api/User\", \"/api/Edge\", \"/api/Graph\", \"/api/Node\"]", | ||
Id = 1 | ||
}, | ||
new Role() | ||
new() | ||
{ | ||
Name = "DataAdmin", | ||
Permissions = "[\"/api/Auth\", \"/api/User\", \"/api/Edge\", \"/api/Graph\", \"/api/Node\"]", | ||
Id = 2 | ||
}, | ||
new Role() | ||
new() | ||
{ | ||
Name = "DataAnalyst", | ||
Permissions = "[\"/api/Auth\", \"/api/User\", \"/api/Edge\", \"/api/Graph\", \"/api/Node\"]", | ||
Id = 3 | ||
} | ||
}; | ||
var userRoles = new List<UserRole>() | ||
var userRoles = new List<UserRole> | ||
{ | ||
new UserRole() | ||
new() | ||
{ | ||
UserId = 1, | ||
RoleId = 1 | ||
}, | ||
new UserRole() | ||
new() | ||
{ | ||
UserId = 1, | ||
RoleId = 2 | ||
}, | ||
new UserRole() | ||
new() | ||
{ | ||
UserId = 1, | ||
RoleId = 3 | ||
} | ||
}; | ||
var users = new List<User>() | ||
var users = new List<User> | ||
{ | ||
new User() | ||
new() | ||
{ | ||
Username = "admin", | ||
PasswordHash = new CustomPasswordHasher() | ||
.HashPassword(configuration.GetValue<string>("DefaultPassword")), | ||
FirstName = "FirstName", | ||
LastName = "LastName", | ||
Email = "[email protected]", | ||
Id = 1, | ||
Id = 1 | ||
} | ||
}; | ||
try | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Json; | ||
using System.Text.Json; | ||
using System.Text; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
using Newtonsoft.Json; | ||
using NSubstitute; | ||
using RelationshipAnalysis.Dto; | ||
using RelationshipAnalysis.Dto.Graph; | ||
using RelationshipAnalysis.Dto.Graph.Edge; | ||
using RelationshipAnalysis.Dto.Graph.Node; | ||
using RelationshipAnalysis.Models.Auth; | ||
using RelationshipAnalysis.Models.Graph; | ||
using RelationshipAnalysis.Services.UserPanelServices.Abstraction.AuthServices; | ||
using RelationshipAnalysis.Models.Graph.Edge; | ||
using RelationshipAnalysis.Models.Graph.Node; | ||
using RelationshipAnalysis.Services.AuthServices; | ||
using RelationshipAnalysis.Settings.JWT; | ||
using JsonSerializer = System.Text.Json.JsonSerializer; | ||
|
||
namespace RelationshipAnalysis.Integration.Test.Controllers; | ||
namespace RelationshipAnalysis.Integration.Test.Controllers.Graph; | ||
|
||
public class GraphControllerTests : IClassFixture<CustomWebApplicationFactory<Program>> | ||
{ | ||
|
||
private readonly HttpClient _client; | ||
private readonly JwtSettings _jwtSettings; | ||
|
||
|
@@ -48,14 +43,13 @@ public async Task GetGraph_ShouldReturnGraph_WhenUserIsAuthorized() | |
FirstName = "Admin", | ||
LastName = "User", | ||
Email = "[email protected]", | ||
UserRoles = new List<UserRole>() { new UserRole() { Role = new Role() { Name = "admin" } } } | ||
|
||
UserRoles = new List<UserRole> { new() { Role = new Role { Name = "admin" } } } | ||
}; | ||
|
||
var token = new JwtTokenGenerator(mockJwtSettings.Object).GenerateJwtToken(user); | ||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
|
||
|
||
var nodeCategory1 = new NodeCategory | ||
{ | ||
NodeCategoryId = 1, | ||
|
@@ -66,8 +60,8 @@ public async Task GetGraph_ShouldReturnGraph_WhenUserIsAuthorized() | |
NodeCategoryId = 2, | ||
NodeCategoryName = "Person" | ||
}; | ||
var node1 = new Node | ||
|
||
var node1 = new Node | ||
{ | ||
NodeId = 1, | ||
NodeUniqueString = "Node1", | ||
|
@@ -90,21 +84,20 @@ public async Task GetGraph_ShouldReturnGraph_WhenUserIsAuthorized() | |
}; | ||
|
||
|
||
|
||
var expectedNodes = new List<NodeDto>() | ||
var expectedNodes = new List<NodeDto> | ||
{ | ||
new NodeDto() | ||
new() | ||
{ | ||
id = node1.NodeId.ToString(), | ||
label = $"{node1.NodeCategory.NodeCategoryName}/{node1.NodeUniqueString}" | ||
}, | ||
new NodeDto() | ||
new() | ||
{ | ||
id = node2.NodeId.ToString(), | ||
label = $"{node2.NodeCategory.NodeCategoryName}/{node2.NodeUniqueString}" | ||
} | ||
}; | ||
|
||
var edge = new Edge | ||
{ | ||
EdgeId = 1, | ||
|
@@ -116,25 +109,24 @@ public async Task GetGraph_ShouldReturnGraph_WhenUserIsAuthorized() | |
}; | ||
|
||
|
||
var expectedEdges = new List<EdgeDto>() | ||
var expectedEdges = new List<EdgeDto> | ||
{ | ||
new EdgeDto() | ||
new() | ||
{ | ||
id = edge.EdgeId.ToString(), | ||
source = node1.NodeId.ToString(), | ||
target = node2.NodeId.ToString() | ||
} | ||
}; | ||
|
||
|
||
// Act | ||
var response = await _client.SendAsync(request); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
var responseData = await response.Content.ReadFromJsonAsync<GraphDto>(); | ||
Assert.Equivalent(responseData.nodes, expectedNodes); | ||
Assert.Equivalent(responseData.edges, expectedEdges); | ||
|
||
Assert.Equivalent(responseData.Nodes, expectedNodes); | ||
Assert.Equivalent(responseData.Edges, expectedEdges); | ||
} | ||
} |
Oops, something went wrong.