From 62fc96c0ab55f0f4d6645ed6db28faea89fa52ab Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Sat, 24 Aug 2024 04:18:43 -0700 Subject: [PATCH 01/14] refactor: refactor graph and related services --- mohaymen-codestar-Team02/Dto/GetGraphDto.cs | 9 ------- .../Services/DisplayData/DisplayService.cs | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) delete mode 100644 mohaymen-codestar-Team02/Dto/GetGraphDto.cs diff --git a/mohaymen-codestar-Team02/Dto/GetGraphDto.cs b/mohaymen-codestar-Team02/Dto/GetGraphDto.cs deleted file mode 100644 index 40dade6..0000000 --- a/mohaymen-codestar-Team02/Dto/GetGraphDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace mohaymen_codestar_Team02.Dto; - -public class GetGraphDto -{ - public string databaseName; - public string sourceEdgeIdentifierFieldName; - public string destinationEdgeIdentifierFieldName; - public string vertexIdentifierFieldName; -} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs b/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs index 8caa7c0..3fd2481 100644 --- a/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs +++ b/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs @@ -16,6 +16,30 @@ public DisplayService(DataContext context) _context = context; } + public List GetVertices(string databaseName, string vertexIdentifierFieldName) + { + var dataSet = _context.DataSets.Include(ds => ds.VertexEntity) + .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); + + var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) + .GroupBy(v => v.ObjectId); + + List vertices = new List(); + foreach (var record in vertexRecords) + { + var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; + Vertex v = new Vertex() + { + Id = record.Key, + Value = value + }; + vertices.Add(v); + } + + return vertices; + } + public (List vertices, List edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { @@ -100,6 +124,8 @@ public DisplayService(DataContext context) return (vertices, edges); } + + /* public void GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, From 050e7f4ec1af1b3a97096eb4743393c2376ac8dc Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Sat, 24 Aug 2024 04:27:02 -0700 Subject: [PATCH 02/14] refactore: some refactor on displaying service --- .../Services/EdgeService.cs | 17 +++++++++++++++++ .../Services/GraphService.cs | 13 +++++++++++++ .../Services/IEdgeService.cs | 10 ++++++++++ .../Services/IGraphService.cs | 11 +++++++++++ .../Services/IVertexService.cs | 10 ++++++++++ .../Services/VertexService.cs | 17 +++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 mohaymen-codestar-Team02/Services/EdgeService.cs create mode 100644 mohaymen-codestar-Team02/Services/GraphService.cs create mode 100644 mohaymen-codestar-Team02/Services/IEdgeService.cs create mode 100644 mohaymen-codestar-Team02/Services/IGraphService.cs create mode 100644 mohaymen-codestar-Team02/Services/IVertexService.cs create mode 100644 mohaymen-codestar-Team02/Services/VertexService.cs diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs new file mode 100644 index 0000000..ff4e320 --- /dev/null +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -0,0 +1,17 @@ +using mohaymen_codestar_Team02.Dto.GraphDTO; +using QuikGraph; + +namespace mohaymen_codestar_Team02.Services; + +public class EdgeService : IEdgeService +{ + public List> GetAllEdges(string datasetName) + { + throw new NotImplementedException(); + } + + public DetailDto GetEdgeDetails(string objId) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService.cs new file mode 100644 index 0000000..399f5c3 --- /dev/null +++ b/mohaymen-codestar-Team02/Services/GraphService.cs @@ -0,0 +1,13 @@ +using mohaymen_codestar_Team02.Models; +using QuikGraph; + +namespace mohaymen_codestar_Team02.Services; + +public class GraphService : IGraphService +{ + public (List vertices, List> edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IEdgeService.cs b/mohaymen-codestar-Team02/Services/IEdgeService.cs new file mode 100644 index 0000000..322b966 --- /dev/null +++ b/mohaymen-codestar-Team02/Services/IEdgeService.cs @@ -0,0 +1,10 @@ +using mohaymen_codestar_Team02.Dto.GraphDTO; +using QuikGraph; + +namespace mohaymen_codestar_Team02.Services; + +public interface IEdgeService +{ + List> GetAllEdges(string datasetName); + DetailDto GetEdgeDetails(string objId); +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IGraphService.cs b/mohaymen-codestar-Team02/Services/IGraphService.cs new file mode 100644 index 0000000..a4099fb --- /dev/null +++ b/mohaymen-codestar-Team02/Services/IGraphService.cs @@ -0,0 +1,11 @@ +using mohaymen_codestar_Team02.Models; +using QuikGraph; + +namespace mohaymen_codestar_Team02.Services; + +public interface IGraphService +{ + (List vertices, List> edges) GetGraph(string databaseName, + string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/IVertexService.cs new file mode 100644 index 0000000..a7000eb --- /dev/null +++ b/mohaymen-codestar-Team02/Services/IVertexService.cs @@ -0,0 +1,10 @@ +using mohaymen_codestar_Team02.Dto.GraphDTO; +using mohaymen_codestar_Team02.Models; + +namespace mohaymen_codestar_Team02.Services; + +public interface IVertexService +{ + List GetAllVertices(string datasetName); + DetailDto GetVertexDetails(string objId); +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs new file mode 100644 index 0000000..431a6ce --- /dev/null +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -0,0 +1,17 @@ +using mohaymen_codestar_Team02.Dto.GraphDTO; +using mohaymen_codestar_Team02.Models; + +namespace mohaymen_codestar_Team02.Services; + +public class VertexService : IVertexService +{ + public List GetAllVertices(string datasetName) + { + throw new NotImplementedException(); + } + + public DetailDto GetVertexDetails(string objId) + { + throw new NotImplementedException(); + } +} \ No newline at end of file From 107ac3e5e81703a3a15de8bbb0771ab83102eb9a Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Sat, 24 Aug 2024 16:29:02 +0330 Subject: [PATCH 03/14] feat: add the getDataOf vertex and edge --- .../Controllers/DataAdminController.cs | 25 ++++--- .../Dto/GraphDTO/DetailDto.cs | 3 +- .../Dto/StoreDataDto/StoreDataDto.cs | 1 - .../DataAdminService/DataAdminService.cs | 54 +++++++------- .../DataAdminService/IDataAdminService.cs | 3 + .../Services/EdgeService.cs | 18 ++++- .../Services/IVertexService.cs | 2 +- .../Services/VertexService.cs | 22 +++++- .../DataAdminService/DataAdminServiceTest.cs | 6 +- .../Servies/EdgeServiceTest.cs | 70 +++++++++++++++++++ .../Servies/VertexServiceTest.cs | 69 ++++++++++++++++++ 11 files changed, 226 insertions(+), 47 deletions(-) create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 189ab09..3b659be 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Dto.StoreDataDto; @@ -15,8 +16,8 @@ public class DataAdminController : ControllerBase private readonly IFileReader _fileReader; private readonly IDisplayDataService _dataService; - public DataAdminController(IDataAdminService dataAdminService, IFileReader fileReader, - IDisplayDataService dataService) + public DataAdminController(IDataAdminService dataAdminService, + IFileReader fileReader) { _dataAdminService = dataAdminService; _fileReader = fileReader; @@ -48,25 +49,27 @@ public void GetDataSetsList() [HttpGet("DataSets/{dataSetName}")] public async Task DisplayDataSetAsGraph(string dataSetName, - [FromQuery] string sourceEdgeIdentifierFieldName, [FromQuery] string destinationEdgeIdentifierFieldName, + [FromQuery] string sourceEdgeIdentifierFieldName, [FromQuery] string destinationEdgeIdentifierFieldName, [FromQuery] string vertexIdentifierFieldName) { ServiceResponse response = - await _dataAdminService.DisplayGeraphData(dataSetName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); + await _dataAdminService.DisplayGeraphData(dataSetName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); response.Data.GraphName = dataSetName; return StatusCode((int)response.Type, response); } - [HttpGet("DataSets/{dataSetName}/Vertices/{vertexId}")] - public async Task DisplayVertexDetails(string datasetName, int vertexId) + [HttpGet("DataSets/Vertices/{vertexId}")] + public async Task DisplayVertexDetails(string objectId) { - return BadRequest(); - } + var respond = _dataAdminService.GetVertexDetail(objectId); + return StatusCode((int)respond.Type, respond); } - [HttpGet("DataSets/{dataSetName}/Edges/{edgeId}")] - public async Task DisplayEdgeDetails(string datasetName, int edgeId) + [HttpGet("DataSets/Edges/{edgeId}")] + public async Task DisplayEdgeDetails(string objectId) { - return BadRequest(); + var respond = _dataAdminService.GetEdgeDetail(objectId); + return StatusCode((int)respond.Type, respond); } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs b/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs index 400a15d..eeb6b0b 100644 --- a/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs +++ b/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs @@ -2,5 +2,6 @@ namespace mohaymen_codestar_Team02.Dto.GraphDTO; public class DetailDto { - public Dictionary AttributeValue { get; init; } + public Dictionary? AttributeValue { get; set; } = new Dictionary(); + } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs b/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs index 052bb7b..9024b8c 100644 --- a/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs +++ b/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs @@ -4,7 +4,6 @@ public class StoreDataDto { public IFormFile EdgeFile { get; set; } public IFormFile VertexFile { get; set; } - public string FileType { get; set; } public string DataName { get; set; } public string CreatorUserName { get; set; } diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index fc9936d..df688db 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -8,11 +8,17 @@ namespace mohaymen_codestar_Team02.Services.DataAdminService; public class DataAdminService : IDataAdminService { - private readonly IStorHandler storHandler; + private readonly IEdgeService _edgeService; + private readonly IVertexService _vertexService; + private readonly IStorHandler _storHandler; private readonly IDisplayDataService _displayDataService; - public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDataService) + + public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDataService, IEdgeService edgeService, + IVertexService vertexService) { - this.storHandler = storHandler; + _vertexService = vertexService; + _edgeService = edgeService; + _storHandler = storHandler; _displayDataService = displayDataService; } @@ -26,16 +32,16 @@ public async Task> StoreData(string? edgeFile, string? v return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, Data.Resources.InvalidInpute); - var dataGroupId = await storHandler.StoreDataSet(graphName, userName); + var dataGroupId = await _storHandler.StoreDataSet(graphName, userName); if (dataGroupId == -1) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, Data.Resources.InvalidInpute); - if (!await storHandler.EdageStorer.StoreFileData(edgeEntityName, edgeFile, dataGroupId)) + if (!await _storHandler.EdageStorer.StoreFileData(edgeEntityName, edgeFile, dataGroupId)) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, Data.Resources.InvalidInpute); - if (!await storHandler.VertexStorer.StoreFileData(vertexEntityName, vertexFile, dataGroupId)) + if (!await _storHandler.VertexStorer.StoreFileData(vertexEntityName, vertexFile, dataGroupId)) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, Data.Resources.InvalidInpute); @@ -47,35 +53,18 @@ public async Task> StoreData(string? edgeFile, string? v } } - public Task> DisplayDataSetAsGraph(string dataSetName, string vertexFieldName, string sourceField, string targetField) - { - throw new NotImplementedException(); - } - - public Task> DisplayGraph() - { - throw new NotImplementedException(); - } - public Task> DisplayDataSet() { throw new NotImplementedException(); } - /* - public Task> DisplayGraph(string databaseName, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) - { - var graph = _displayDataService.GetGraph2(databaseName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, - vertexIdentifierFieldName); - return new Task>() - } -*/ - public async Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, + public async Task> DisplayGeraphData(string databaseName, + string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { - var graph = _displayDataService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, + var graph = _displayDataService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); var dto = new DisplayGraphDto() @@ -86,8 +75,15 @@ public async Task> DisplayGeraphData(string dat return new ServiceResponse(dto, ApiResponseType.Success, ""); } - public Task>> DisplayEdgeData() + public ServiceResponse GetVertexDetail(string objectId) { - throw new NotImplementedException(); + return new ServiceResponse(_vertexService.GetVertexDetails(objectId), ApiResponseType.Success, + string.Empty); + } + + public ServiceResponse GetEdgeDetail(string objectId) + { + return new ServiceResponse(_edgeService.GetEdgeDetails(objectId), ApiResponseType.Success, + string.Empty); } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs index d3e9175..f2e95fd 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs @@ -12,4 +12,7 @@ Task> StoreData(string? edgeFile, string? vertexFile, st Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); + + ServiceResponse GetVertexDetail(string objectId); + ServiceResponse GetEdgeDetail(string objectId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs index ff4e320..1f1a692 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -1,3 +1,4 @@ +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; using QuikGraph; @@ -5,6 +6,13 @@ namespace mohaymen_codestar_Team02.Services; public class EdgeService : IEdgeService { + private IServiceProvider _serviceProvider; + + public EdgeService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public List> GetAllEdges(string datasetName) { throw new NotImplementedException(); @@ -12,6 +20,14 @@ public List> GetAllEdges(string datasetName) public DetailDto GetEdgeDetails(string objId) { - throw new NotImplementedException(); + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var validValue = context.EdgeValues.Where(value => value.ObjectId.ToLower() == objId.ToLower()).ToList(); + var result = new DetailDto(); + foreach (var value in validValue) + { + result.AttributeValue[context.EdgeAttributes.Find(value.EdgeAttributeId).Name] = value.StringValue; + } + return result; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/IVertexService.cs index a7000eb..07d43bf 100644 --- a/mohaymen-codestar-Team02/Services/IVertexService.cs +++ b/mohaymen-codestar-Team02/Services/IVertexService.cs @@ -6,5 +6,5 @@ namespace mohaymen_codestar_Team02.Services; public interface IVertexService { List GetAllVertices(string datasetName); - DetailDto GetVertexDetails(string objId); + DetailDto GetVertexDetails(string objId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index 431a6ce..34572db 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -1,3 +1,5 @@ +using Microsoft.EntityFrameworkCore; +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; @@ -5,12 +7,28 @@ namespace mohaymen_codestar_Team02.Services; public class VertexService : IVertexService { - public List GetAllVertices(string datasetName) + private IServiceProvider _serviceProvider; + + public VertexService(IServiceProvider serviceProvider) { - throw new NotImplementedException(); + _serviceProvider = serviceProvider; } public DetailDto GetVertexDetails(string objId) + { + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var validValue = context.VertexValues.Where(value => value.ObjectId.ToLower() == objId.ToLower()).ToList(); + var result = new DetailDto(); + foreach (var value in validValue) + { + result.AttributeValue[context.VertexAttributes.Find(value.VertexAttributeId).Name] = value.StringValue; + } + + return result; + } + + public List GetAllVertices(string datasetName) { throw new NotImplementedException(); } diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index c07ee82..e1ff86f 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -10,13 +10,17 @@ public class DataAdminServiceTest private readonly IStorHandler _storHandler; private readonly IDisplayDataService _displayDataService; private readonly mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService _sut; + private readonly IEdgeService _edgeService; + private readonly IVertexService _vertexService; public DataAdminServiceTest() { + _vertexService = Substitute.For(); + _edgeService = Substitute.For(); _storHandler = Substitute.For(); _displayDataService = Substitute.For(); _sut = new mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService(_storHandler, - _displayDataService); + _displayDataService, _edgeService, _vertexService); _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs new file mode 100644 index 0000000..577a390 --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs @@ -0,0 +1,70 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Protocols; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class EdgeServiceTest +{ + private IServiceProvider _serviceProvider; + private EdgeService _sut; + + public EdgeServiceTest() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new EdgeService(_serviceProvider); + } + + [Fact] + public void GetEdgeDetails_ReturnsCorrectDetails() + { + //Arange + var objectId1 = "object1"; + var objectId2 = "object2"; + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + var att1 = new EdgeAttribute("att1", 1); + var att2 = new EdgeAttribute("att2", 2); + att1.Id = 1; + att2.Id = 2; + + List att = new List() { att1, att2 }; + + foreach (var attribute in att) + { + mockContext.Add(attribute); + } + + var val1 = new EdgeValue("val1", 1, objectId2); + var val2 = new EdgeValue("val2", 1, objectId1); + var val3 = new EdgeValue("val3", 2, objectId1); + var val4 = new EdgeValue("val4", 2, objectId2); + List vertexValues = new List() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) + { + mockContext.Add(value); + } + + mockContext.SaveChanges(); + var expected = new Dictionary(); + expected[att1.Name] = val2.StringValue; + expected[att2.Name] = val3.StringValue; + //Action + var result = _sut.GetEdgeDetails(objectId1); + //assert + Assert.Equal(result.AttributeValue, expected); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs new file mode 100644 index 0000000..68e389f --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs @@ -0,0 +1,69 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Protocols; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class VertexServiceTest +{ + private IServiceProvider _serviceProvider; + private VertexService _sut; + + public VertexServiceTest() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new VertexService(_serviceProvider); + } + + [Fact] + public void GetVertexDetails_ReturnsCorrectDetails() + { + //Arange + var objectId1 = "object1"; + var objectId2 = "object2"; + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + var att1 = new VertexAttribute("att1", 1); + var att2 = new VertexAttribute("att2", 2); + att1.Id = 1; + att2.Id = 2; + + List att = new List() { att1, att2 }; + + foreach (var attribute in att) + { + mockContext.Add(attribute); + } + + var val1 = new VertexValue("val1", 1, objectId2); + var val2 = new VertexValue("val2", 1, objectId1); + var val3 = new VertexValue("val3", 2, objectId1); + var val4 = new VertexValue("val4", 2, objectId2); + List vertexValues = new List() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) + { + mockContext.Add(value); + } + + mockContext.SaveChanges(); + var expected = new Dictionary(); + expected[att1.Name] = val2.StringValue; + expected[att2.Name] = val3.StringValue; + //Action + var result = _sut.GetVertexDetails(objectId1); + //assert + Assert.Equal(result.AttributeValue, expected); + } +} \ No newline at end of file From af7351e5222016716cd1f9e9bd5a59a0f75f9398 Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Sat, 24 Aug 2024 16:49:06 +0330 Subject: [PATCH 04/14] fix: fix the dont need to get userNAme --- .../Controllers/DataAdminController.cs | 10 ++++---- .../Dto/StoreDataDto/StoreDataDto.cs | 2 -- .../DataAdminService/DataAdminService.cs | 23 +++++++++++++++++-- .../DataAdminService/IDataAdminService.cs | 2 +- .../initialProgram/InitialServices.cs | 7 +++--- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 3b659be..d76afe3 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -32,8 +32,7 @@ public async Task StoreNewDataSet([FromForm] StoreDataDto storeDa var edgeFile = _fileReader.Read(storeDataDto.EdgeFile); var vertexFile = _fileReader.Read(storeDataDto.VertexFile); var response = await _dataAdminService.StoreData(edgeFile, vertexFile, storeDataDto.DataName, - Path.GetFileName(storeDataDto.EdgeFile.FileName), Path.GetFileName(storeDataDto.VertexFile.FileName), - storeDataDto.CreatorUserName); + Path.GetFileName(storeDataDto.EdgeFile.FileName), Path.GetFileName(storeDataDto.VertexFile.FileName)); return StatusCode((int)response.Type, response); } catch (FormatException e) @@ -60,13 +59,14 @@ await _dataAdminService.DisplayGeraphData(dataSetName, sourceEdgeIdentifierField } - [HttpGet("DataSets/Vertices/{vertexId}")] + [HttpGet("DataSets/Vertices/{objectId}")] public async Task DisplayVertexDetails(string objectId) { var respond = _dataAdminService.GetVertexDetail(objectId); - return StatusCode((int)respond.Type, respond); } + return StatusCode((int)respond.Type, respond); + } - [HttpGet("DataSets/Edges/{edgeId}")] + [HttpGet("DataSets/Edges/{objectId}")] public async Task DisplayEdgeDetails(string objectId) { var respond = _dataAdminService.GetEdgeDetail(objectId); diff --git a/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs b/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs index 9024b8c..3b953af 100644 --- a/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs +++ b/mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs @@ -5,6 +5,4 @@ public class StoreDataDto public IFormFile EdgeFile { get; set; } public IFormFile VertexFile { get; set; } public string DataName { get; set; } - - public string CreatorUserName { get; set; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index df688db..35d4961 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -1,6 +1,8 @@ +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Services.CookieService; using mohaymen_codestar_Team02.Services.StoreData.Abstraction; namespace mohaymen_codestar_Team02.Services.DataAdminService; @@ -8,14 +10,23 @@ namespace mohaymen_codestar_Team02.Services.DataAdminService; public class DataAdminService : IDataAdminService { + private readonly ITokenService _tokenService; + private readonly ICookieService _cookieService; private readonly IEdgeService _edgeService; private readonly IVertexService _vertexService; private readonly IStorHandler _storHandler; private readonly IDisplayDataService _displayDataService; - public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDataService, IEdgeService edgeService, + public DataAdminService( + ITokenService tokenService, + ICookieService cookieService, + IStorHandler storHandler, + IDisplayDataService displayDataService, + IEdgeService edgeService, IVertexService vertexService) { + _tokenService = tokenService; + _cookieService = cookieService; _vertexService = vertexService; _edgeService = edgeService; _storHandler = storHandler; @@ -23,10 +34,18 @@ public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDat } public async Task> StoreData(string? edgeFile, string? vertexFile, string graphName - , string? edgeEntityName, string vertexEntityName, string userName) + , string? edgeEntityName, string vertexEntityName) { try { + var token = _cookieService.GetCookieValue(); + if (string.IsNullOrEmpty(token)) + { + return new ServiceResponse(null, ApiResponseType.Unauthorized, + Resources.UnauthorizedMessage); + } + + var userName = _tokenService.GetUserNameFromToken(); if (string.IsNullOrEmpty(edgeEntityName) || string.IsNullOrEmpty(graphName) || string.IsNullOrEmpty(vertexEntityName)) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs index f2e95fd..7c0876c 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs @@ -6,7 +6,7 @@ namespace mohaymen_codestar_Team02.Services.DataAdminService; public interface IDataAdminService { Task> StoreData(string? edgeFile, string? vertexFile, string graphName - , string? edgeEntityName, string vertexEntityName, string userName); + , string? edgeEntityName, string vertexEntityName); Task> DisplayDataSet(); diff --git a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs index 8e7d04f..88cfe8f 100644 --- a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs +++ b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs @@ -58,8 +58,9 @@ public static void ConfigureServices(IServiceCollection services, WebApplication .AddScoped() .AddScoped() .AddScoped() - .AddScoped(); - + .AddScoped() + .AddScoped() + .AddScoped(); services.AddAutoMapper(typeof(AutoMapperProfile)); services.AddAuthorization(); @@ -202,7 +203,7 @@ public void SeadAdmin() r.RoleType.ToLower().Equals(RoleType.SystemAdmin.ToString().ToLower())); var userRole = new UserRole() - { RoleId = role.RoleId, UserId = admin.UserId, Role = role, User = admin }; + { RoleId = role.RoleId, UserId = admin.UserId, Role = role, User = admin }; _context.UserRoles.Add(userRole); _context.Users.Add(admin); From 45a5fa6d451014149e070bf2461b08dcf5a67f7d Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Sat, 24 Aug 2024 17:02:11 +0330 Subject: [PATCH 05/14] fix: add todo for permission --- .../Controllers/DataAdminController.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index d76afe3..88673ad 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -14,7 +14,6 @@ public class DataAdminController : ControllerBase { private readonly IDataAdminService _dataAdminService; private readonly IFileReader _fileReader; - private readonly IDisplayDataService _dataService; public DataAdminController(IDataAdminService dataAdminService, IFileReader fileReader) @@ -27,6 +26,7 @@ public DataAdminController(IDataAdminService dataAdminService, [HttpPost("DataSets")] public async Task StoreNewDataSet([FromForm] StoreDataDto storeDataDto) { + //Todo SystemAdmin and DataAdmin try { var edgeFile = _fileReader.Read(storeDataDto.EdgeFile); @@ -44,6 +44,7 @@ public async Task StoreNewDataSet([FromForm] StoreDataDto storeDa [HttpGet("DataSets")] public void GetDataSetsList() { + //Todo all Of Them } [HttpGet("DataSets/{dataSetName}")] @@ -51,6 +52,7 @@ public async Task DisplayDataSetAsGraph(string dataSetName, [FromQuery] string sourceEdgeIdentifierFieldName, [FromQuery] string destinationEdgeIdentifierFieldName, [FromQuery] string vertexIdentifierFieldName) { + //Todo all Of Them ServiceResponse response = await _dataAdminService.DisplayGeraphData(dataSetName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); @@ -62,6 +64,8 @@ await _dataAdminService.DisplayGeraphData(dataSetName, sourceEdgeIdentifierField [HttpGet("DataSets/Vertices/{objectId}")] public async Task DisplayVertexDetails(string objectId) { + //Todo all Of Them + var respond = _dataAdminService.GetVertexDetail(objectId); return StatusCode((int)respond.Type, respond); } @@ -69,6 +73,7 @@ public async Task DisplayVertexDetails(string objectId) [HttpGet("DataSets/Edges/{objectId}")] public async Task DisplayEdgeDetails(string objectId) { + //Todo all Of Them var respond = _dataAdminService.GetEdgeDetail(objectId); return StatusCode((int)respond.Type, respond); } From 718932046410f85ca9db19a137aeecd34b66c38c Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 00:00:02 -0700 Subject: [PATCH 06/14] refactor: some refactor on getGraph and its tests --- .../Controllers/DataAdminController.cs | 7 +- .../Mapper/AutoMapperProfile.cs | 13 ++ mohaymen-codestar-Team02/Models/DataGroup.cs | 11 +- .../Models/EdgeEAV/EdgeEntity.cs | 1 + .../Models/VertexEAV/VertexEntity.cs | 1 + .../DataAdminService/DataAdminService.cs | 49 +++--- .../DataAdminService/IDataAdminService.cs | 3 +- .../Services/EdgeService.cs | 104 ++++++++++++- .../Services/GraphService.cs | 16 +- .../Services/IEdgeService.cs | 5 +- .../Services/IGraphService.cs | 2 +- .../Services/IVertexService.cs | 2 +- .../Services/VertexService.cs | 35 ++++- .../initialProgram/InitialServices.cs | 2 +- .../DataAdminService/DataAdminServiceTest.cs | 142 +++++++++++++++++- .../mohaymen-codestar-Team02_XUnitTest.csproj | 18 +-- 16 files changed, 358 insertions(+), 53 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 189ab09..945fc37 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -41,9 +41,12 @@ public async Task StoreNewDataSet([FromForm] StoreDataDto storeDa } } - [HttpGet("DataSets")] - public void GetDataSetsList() + [HttpGet("DataSets/jkdjf{username}")] + public IActionResult GetDataSetsList(string username) { + var response = _dataAdminService.DisplayDataSet(username); + return StatusCode((int)response.Type, response); + } [HttpGet("DataSets/{dataSetName}")] diff --git a/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs b/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs index cd6750e..55fe910 100644 --- a/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs +++ b/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs @@ -1,9 +1,12 @@ using AutoMapper; +using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.Role; using mohaymen_codestar_Team02.Dto.User; using mohaymen_codestar_Team02.Dto.UserDtos; using mohaymen_codestar_Team02.Dto.UserRole; using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; namespace mohaymen_codestar_Team02.Mapper; @@ -17,5 +20,15 @@ public AutoMapperProfile() CreateMap(); CreateMap(); CreateMap(); + CreateMap() + .ForMember(dest => dest.EdgeEntity, opt => + opt.MapFrom(src => src.EdgeEntity)) + .ForMember(dest => dest.VertexEntity, opt => + opt.MapFrom(src => src.VertexEntity)); + CreateMap() + .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)); + CreateMap(); + CreateMap(); + } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Models/DataGroup.cs b/mohaymen-codestar-Team02/Models/DataGroup.cs index bf6a0b4..9868b74 100644 --- a/mohaymen-codestar-Team02/Models/DataGroup.cs +++ b/mohaymen-codestar-Team02/Models/DataGroup.cs @@ -13,15 +13,20 @@ public DataGroup(string name, long userId) Name = name; UserId = userId; } + + public DataGroup() { } [Key] public long DataGroupId { get; set; } public string Name { get; set; } public DateTime CreateAt { get; set; } = DateTime.UtcNow; public DateTime UpdateAt { get; set; } = DateTime.UtcNow; - - public virtual EdgeEntity EdgeEntity { get; set; } - public virtual VertexEntity VertexEntity { get; set; } + + + public virtual long EdgeEntityId { get; set; } + [ForeignKey("EdgeEntityId")] public virtual EdgeEntity EdgeEntity { get; set; } + public virtual long VertexEntityId { get; set; } + [ForeignKey("VertexEntityId")] public virtual VertexEntity VertexEntity { get; set; } public long UserId { get; set; } diff --git a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs index 80c4e93..3a8e641 100644 --- a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs +++ b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs @@ -6,6 +6,7 @@ namespace mohaymen_codestar_Team02.Models.EdgeEAV; public class EdgeEntity { + public EdgeEntity(){} public EdgeEntity(string name, long dataGroupId) { Regex regex = diff --git a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs index 8c9b459..4cbd302 100644 --- a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs +++ b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs @@ -7,6 +7,7 @@ namespace mohaymen_codestar_Team02.Models.VertexEAV; public class VertexEntity { + public VertexEntity() {} public VertexEntity(string name, long dataGroupId) { var regex = diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index fc9936d..0a2ec44 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -1,6 +1,11 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; using mohaymen_codestar_Team02.Services.StoreData.Abstraction; namespace mohaymen_codestar_Team02.Services.DataAdminService; @@ -10,10 +15,14 @@ public class DataAdminService { private readonly IStorHandler storHandler; private readonly IDisplayDataService _displayDataService; - public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDataService) + private readonly IServiceProvider _serviceProvider; + private readonly IMapper _mapper; + public DataAdminService(IStorHandler storHandler, IDisplayDataService displayDataService, IMapper mapper, IServiceProvider serviceProvider) { this.storHandler = storHandler; _displayDataService = displayDataService; + _mapper = mapper; + _serviceProvider = serviceProvider; } public async Task> StoreData(string? edgeFile, string? vertexFile, string graphName @@ -47,30 +56,23 @@ public async Task> StoreData(string? edgeFile, string? v } } - public Task> DisplayDataSetAsGraph(string dataSetName, string vertexFieldName, string sourceField, string targetField) + public ServiceResponse> DisplayDataSet(string username) { - throw new NotImplementedException(); - } - - public Task> DisplayGraph() - { - throw new NotImplementedException(); - } + + var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); - public Task> DisplayDataSet() - { - throw new NotImplementedException(); - } + + var datasets = context.DataSets + .Include(ds => ds.VertexEntity) + .Include(ds => ds.EdgeEntity) + .Include(ds => ds.User) + .Where(ds=>ds.User.Username==username) + .ToList(); - /* - public Task> DisplayGraph(string databaseName, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) - { - var graph = _displayDataService.GetGraph2(databaseName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, - vertexIdentifierFieldName); - return new Task>() + var dataGroupDtos = datasets.Select(ds => _mapper.Map(ds)).ToList(); + return new ServiceResponse>(dataGroupDtos, ApiResponseType.Success, ""); } -*/ public async Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) @@ -85,9 +87,4 @@ public async Task> DisplayGeraphData(string dat }; return new ServiceResponse(dto, ApiResponseType.Success, ""); } - - public Task>> DisplayEdgeData() - { - throw new NotImplementedException(); - } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs index d3e9175..f34868c 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs @@ -1,3 +1,4 @@ +using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; @@ -8,7 +9,7 @@ public interface IDataAdminService Task> StoreData(string? edgeFile, string? vertexFile, string graphName , string? edgeEntityName, string vertexEntityName, string userName); - Task> DisplayDataSet(); + ServiceResponse> DisplayDataSet(string username); Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs index ff4e320..4518599 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -1,13 +1,113 @@ +using System.Linq; +using Microsoft.EntityFrameworkCore; +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; +using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; using QuikGraph; namespace mohaymen_codestar_Team02.Services; public class EdgeService : IEdgeService { - public List> GetAllEdges(string datasetName) + private readonly IServiceProvider _serviceProvider; + + public EdgeService(IServiceProvider serviceProvider) { - throw new NotImplementedException(); + _serviceProvider = serviceProvider; + } + + public List GetAllEdges(string databaseName, string vertexIdentifierFieldName, string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName) + { + + var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var dataSet = context.DataSets.Include(ds => ds.VertexEntity) + .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); + + var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) + .GroupBy(v => v.ObjectId); + + var edgeRecords = dataSet.EdgeEntity.EdgeAttributes.Select(ea => ea.EdgeValues).SelectMany(v => v) + .GroupBy(v => v.ObjectId); + + List edges = new List(); + foreach (var record in edgeRecords) + { + + GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, out var sourceValue, out var destinationValue); + + GetSourcesAndDestinations(vertexIdentifierFieldName, vertexRecords, sourceValue, destinationValue, out var sources, out var destinations); + + foreach (var source in sources) + { + foreach (var des in destinations) + { + Edge edge = new Edge() + { + Id = record.Key, + Source = source.Id, + Target = des.Id + }; + edges.Add(edge); + } + } + } + + return edges; + } + + private void GetSourcesAndDestinations(string vertexIdentifierFieldName, IEnumerable> vertexRecords, + string sourceValue, string destinationValue, out List sources, out List destinations) + { + sources = new List(); + destinations = new List(); + + foreach (var record1 in vertexRecords) + { + foreach (var item in record1) + { + if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == sourceValue) + { + Vertex vertex = new Vertex() + { + Id = record1.Key + }; + sources.Add(vertex); + } + + if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == destinationValue) + { + Vertex vertex = new Vertex() + { + Id = record1.Key + }; + destinations.Add(vertex); + } + } + } + } + + private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName, IGrouping record, out string sourceValue, out string destinationValue) + { + sourceValue = string.Empty; + destinationValue = string.Empty; + foreach (var item in record) + { + if (item.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) + { + sourceValue = item.StringValue; + } + + if (item.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) + { + destinationValue = item.StringValue; + } + } } public DetailDto GetEdgeDetails(string objId) diff --git a/mohaymen-codestar-Team02/Services/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService.cs index 399f5c3..ef2cf80 100644 --- a/mohaymen-codestar-Team02/Services/GraphService.cs +++ b/mohaymen-codestar-Team02/Services/GraphService.cs @@ -5,9 +5,21 @@ namespace mohaymen_codestar_Team02.Services; public class GraphService : IGraphService { - public (List vertices, List> edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, + private readonly IVertexService _vertexService; + private readonly IEdgeService _edgeService; + + public GraphService(IVertexService vertexService, IEdgeService edgeService) + { + _vertexService = vertexService; + _edgeService = edgeService; + } + + public (List vertices, List edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { - throw new NotImplementedException(); + var vertices = _vertexService.GetAllVertices(databaseName, vertexIdentifierFieldName); + var edges = _edgeService.GetAllEdges(databaseName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName); + return (vertices, edges); } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IEdgeService.cs b/mohaymen-codestar-Team02/Services/IEdgeService.cs index 322b966..23dfc85 100644 --- a/mohaymen-codestar-Team02/Services/IEdgeService.cs +++ b/mohaymen-codestar-Team02/Services/IEdgeService.cs @@ -1,10 +1,13 @@ using mohaymen_codestar_Team02.Dto.GraphDTO; +using mohaymen_codestar_Team02.Models; using QuikGraph; namespace mohaymen_codestar_Team02.Services; public interface IEdgeService { - List> GetAllEdges(string datasetName); + public List GetAllEdges(string databaseName, string vertexIdentifierFieldName, + string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName); DetailDto GetEdgeDetails(string objId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IGraphService.cs b/mohaymen-codestar-Team02/Services/IGraphService.cs index a4099fb..2611a7d 100644 --- a/mohaymen-codestar-Team02/Services/IGraphService.cs +++ b/mohaymen-codestar-Team02/Services/IGraphService.cs @@ -5,7 +5,7 @@ namespace mohaymen_codestar_Team02.Services; public interface IGraphService { - (List vertices, List> edges) GetGraph(string databaseName, + (List vertices, List edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/IVertexService.cs index a7000eb..6c49638 100644 --- a/mohaymen-codestar-Team02/Services/IVertexService.cs +++ b/mohaymen-codestar-Team02/Services/IVertexService.cs @@ -5,6 +5,6 @@ namespace mohaymen_codestar_Team02.Services; public interface IVertexService { - List GetAllVertices(string datasetName); + public List GetAllVertices(string datasetName, string vertexIdentifierFieldName); DetailDto GetVertexDetails(string objId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index 431a6ce..7d90e14 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -1,3 +1,6 @@ +using System.Linq; +using Microsoft.EntityFrameworkCore; +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; @@ -5,9 +8,37 @@ namespace mohaymen_codestar_Team02.Services; public class VertexService : IVertexService { - public List GetAllVertices(string datasetName) + private readonly IServiceProvider _serviceProvider; + + public VertexService(IServiceProvider serviceProvider) { - throw new NotImplementedException(); + _serviceProvider = serviceProvider; + } + + public List GetAllVertices(string datasetName, string vertexIdentifierFieldName) + { + var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var dataSet = context.DataSets.Include(ds => ds.VertexEntity) + .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(datasetName.ToLower())); + + var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) + .GroupBy(v => v.ObjectId); + + List vertices = new List(); + foreach (var record in vertexRecords) + { + var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; + Vertex v = new Vertex() + { + Id = record.Key, + Value = value + }; + vertices.Add(v); + } + + return vertices; } public DetailDto GetVertexDetails(string objId) diff --git a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs index 8e7d04f..4bc7182 100644 --- a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs +++ b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs @@ -59,7 +59,7 @@ public static void ConfigureServices(IServiceCollection services, WebApplication .AddScoped() .AddScoped() .AddScoped(); - + services.AddAutoMapper(typeof(AutoMapperProfile)); services.AddAuthorization(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index c07ee82..9b22710 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -1,4 +1,13 @@ +using System.Runtime.InteropServices.JavaScript; +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; using mohaymen_codestar_Team02.Services; using mohaymen_codestar_Team02.Services.StoreData.Abstraction; using NSubstitute; @@ -9,14 +18,30 @@ public class DataAdminServiceTest { private readonly IStorHandler _storHandler; private readonly IDisplayDataService _displayDataService; - private readonly mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService _sut; + private readonly IMapper _mapper; + private readonly mohaymen_codestar_Team02.Services.DataAdminService.IDataAdminService _sut; + private readonly IServiceProvider _serviceProvider; + private DataContext _dataContext; public DataAdminServiceTest() { _storHandler = Substitute.For(); _displayDataService = Substitute.For(); + _mapper = Substitute.For(); + + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _sut = new mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService(_storHandler, - _displayDataService); + _displayDataService, _mapper, _serviceProvider); _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } @@ -78,4 +103,117 @@ public async Task StoreData_ReturnsSuccess_WhenInputAreValid() // Assert Assert.Equal(ApiResponseType.Success, result.Type); } + + [Fact] + public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() + { + using var scope = _serviceProvider.CreateScope(); + _dataContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + var username = "username1"; + var datasetName1 = "Dataset1"; + var datasetName2 = "Dataset2"; + var vertexEntityName1 = "Account1"; + var EdgeEntityName1 = "Transaction1"; + var vertexEntityName2 = "Account2"; + var EdgeEntityName2 = "Transaction2"; + + var GetDataGroupDtos = new List() + { + new GetDataGroupDto() + { + Name = datasetName1, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new GetVertexEntityDto() + { + Name = vertexEntityName1 + }, + EdgeEntity = new GetEdgeEntityDto() + { + Name = EdgeEntityName1 + } + }, + new GetDataGroupDto() + { + Name = datasetName2, + + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new GetVertexEntityDto() + { + Name = vertexEntityName2 + }, + EdgeEntity = new GetEdgeEntityDto() + { + Name = EdgeEntityName2 + } + } + }; + + var expected = new ServiceResponse>(GetDataGroupDtos, ApiResponseType.Success, ""); + + var user = new User() + { + UserId = 1, + Username = username, + DataSets = new List() + { + new DataGroup + { + Name = datasetName1, + UserId = 1, + DataGroupId = 1, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new VertexEntity(vertexEntityName1, 1), + EdgeEntity = new EdgeEntity(EdgeEntityName1, 1) + }, + new DataGroup + { + Name = datasetName2, + UserId = 1, + DataGroupId = 2, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new VertexEntity(vertexEntityName2, 2), + EdgeEntity = new EdgeEntity(EdgeEntityName2, 2) + } + }, + PasswordHash = new byte[]{}, + Salt = new byte[]{} + }; + + _dataContext.Users.Add(user); + _dataContext.SaveChanges(); + + + _mapper.Map(Arg.Is(dg => dg.Name == datasetName1)) + .Returns(new GetDataGroupDto + { + Name = datasetName1, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new GetVertexEntityDto { Name = vertexEntityName1 }, + EdgeEntity = new GetEdgeEntityDto { Name = EdgeEntityName1 } + }); + + _mapper.Map(Arg.Is(dg => dg.Name == datasetName2)) + .Returns(new GetDataGroupDto + { + Name = datasetName2, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new GetVertexEntityDto { Name = vertexEntityName2 }, + EdgeEntity = new GetEdgeEntityDto { Name = EdgeEntityName2 } + }); + + // Act + var actual = _sut.DisplayDataSet(username); + + // Assert + Assert.Equivalent(expected, actual); + } + } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj b/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj index 01d4505..591ffad 100644 --- a/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj +++ b/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj @@ -11,25 +11,25 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + - + - + From 265a7d5d61ad817e8cee961f402f015f337d157c Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 00:03:33 -0700 Subject: [PATCH 07/14] refactor: some refactor on tests --- .../Dto/GetDataGroupDto.cs | 15 +++ .../Dto/GetEdgeEntityDto.cs | 6 + .../Dto/GetVertexEntityDto.cs | 6 + .../Servies/EdgeServiceTest1.cs | 113 ++++++++++++++++++ .../Servies/GraphServiceTest1.cs | 63 ++++++++++ .../Servies/VertexServiceTest1.cs | 83 +++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs create mode 100644 mohaymen-codestar-Team02/Dto/GetEdgeEntityDto.cs create mode 100644 mohaymen-codestar-Team02/Dto/GetVertexEntityDto.cs create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest1.cs create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest1.cs diff --git a/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs b/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs new file mode 100644 index 0000000..ec784a7 --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs @@ -0,0 +1,15 @@ +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; + +namespace mohaymen_codestar_Team02.Dto; + +public class GetDataGroupDto +{ + public string Name { get; set; } + + public DateTime CreateAt { get; set; } = DateTime.UtcNow; + public DateTime UpdateAt { get; set; } = DateTime.UtcNow; + + public virtual GetEdgeEntityDto EdgeEntity { get; set; } + public virtual GetVertexEntityDto VertexEntity { get; set; } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GetEdgeEntityDto.cs b/mohaymen-codestar-Team02/Dto/GetEdgeEntityDto.cs new file mode 100644 index 0000000..e8e11ec --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GetEdgeEntityDto.cs @@ -0,0 +1,6 @@ +namespace mohaymen_codestar_Team02.Dto; + +public class GetEdgeEntityDto +{ + public string Name { get; set; } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GetVertexEntityDto.cs b/mohaymen-codestar-Team02/Dto/GetVertexEntityDto.cs new file mode 100644 index 0000000..2efc85c --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GetVertexEntityDto.cs @@ -0,0 +1,6 @@ +namespace mohaymen_codestar_Team02.Dto; + +public class GetVertexEntityDto +{ + public string Name { get; set; } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs new file mode 100644 index 0000000..e73250a --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs @@ -0,0 +1,113 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +public class EdgeServiceTest +{ + private IEdgeService _sut; + private DataContext _dataContext; + private ServiceProvider _serviceProvider; + + public EdgeServiceTest() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _sut = new EdgeService(_serviceProvider); + } + + [Fact] + public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifiersName() + { + using var scope = _serviceProvider.CreateScope(); + _dataContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + string datasetName = "DataSet1"; + string vertexIdentifierFieldName = "CardID"; + string sourceEdgeIdentifierFieldName = "SourceAcount"; + string destinationEdgeIdentifierFieldName = "DestiantionAccount"; + + var expected = new List() + { + new Edge() + { + Id = "id1", + Source = "id2", + Target = "id3" + }, + new Edge() + { + Id = "id2", + Source = "id4", + Target = "id5" + } + }; + + var dataset = new DataGroup("Dataset1", 1) + { + Name = "DataSet1", + EdgeEntity = new EdgeEntity("Transaction", 1) + { + EdgeAttributes = new List + { + new EdgeAttribute("SourceAcount", 1) + { + EdgeValues = new List + { + new EdgeValue("value1", 1, "id1") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1)}, + new EdgeValue("value2", 1, "id2") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1)}, + + } + }, + new EdgeAttribute("DestiantionAccount", 2) + { + EdgeValues = new List + { + new EdgeValue("value3", 2, "id1") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1)}, + new EdgeValue("value3", 2, "id2") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1)}, + } + } + } + }, + VertexEntity = new VertexEntity("Account", 1) + { + VertexAttributes = new List + { + new VertexAttribute("CardID", 1) + { + VertexValues = new List + { + new VertexValue("value1", 1, "id2"){ VertexAttribute = new VertexAttribute("CardID", 1)}, + new VertexValue("value3", 1, "id3") { VertexAttribute = new VertexAttribute("CardID", 1)}, + new VertexValue("value2", 1, "id4") { VertexAttribute = new VertexAttribute("CardID", 1)}, + new VertexValue("value3", 1, "id5") { VertexAttribute = new VertexAttribute("CardID", 1)} + } + } + } + } + }; + + _dataContext.DataSets.Add(dataset); + _dataContext.SaveChanges(); + + + // Act + var actual = _sut.GetAllEdges(datasetName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName); + + // Assert + Assert.Equivalent(expected, actual); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest1.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest1.cs new file mode 100644 index 0000000..04f6b4a --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest1.cs @@ -0,0 +1,63 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class GraphServiceTest +{ + private IGraphService _sut; + private readonly IVertexService _vertexService; + private readonly IEdgeService _edgeService; + + public GraphServiceTest(IVertexService vertexService, IEdgeService edgeService) + { + _vertexService = vertexService; + _edgeService = edgeService; + _sut = new GraphService(vertexService, edgeService); + } + + [Fact] + public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetNameAndIdentifiers() + { + // Arrange + var datasetName = "datasetName1"; + var sourceEdgeIdentifierFieldName = "AccountID"; + var destinationEdgeIdentifierFieldName = "SourceAcount"; + var vertexIdentifierFieldName = "DestiantionAccount"; + + var expectedVertex = new List() + { + new Vertex(){ + Id = "id1", + Value = "value1" + }, + new Vertex(){ + Id = "id2", + Value = "value2" + } + }; + + var expectedEdge = new List() + { + new Edge(){ + Id = "id1", + Source = "id1", + Target = "id2" + } + }; + + // Act + var actual = _sut.GetGraph(datasetName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, + vertexIdentifierFieldName); + var actualVertex = actual.vertices; + var actualEdge = actual.edges; + + // Assert + Assert.Equivalent(expectedVertex, actualVertex); + Assert.Equivalent(expectedEdge, actualEdge); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest1.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest1.cs new file mode 100644 index 0000000..769e503 --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest1.cs @@ -0,0 +1,83 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class VertexServiceTest +{ + private IVertexService _sut; + private DataContext _dataContext; + private ServiceProvider _serviceProvider; + + public VertexServiceTest() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + + _sut = new VertexService(_serviceProvider); + } + + [Fact] + public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() + { + using var scope = _serviceProvider.CreateScope(); + _dataContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + string datasetName = "DataSet1"; + string vertexIdentifierFieldName = "CardID"; + + var dataset = new DataGroup(datasetName, 1) + { + VertexEntity = new VertexEntity("Account", 1) + { + VertexAttributes = new List + { + new VertexAttribute("CardID", 1) + { + VertexValues = new List + { + new VertexValue("value1", 1, "id1"){ VertexAttribute = new VertexAttribute("CardID", 1)}, + new VertexValue("value2", 1, "id2") { VertexAttribute = new VertexAttribute("CardID", 1)} + } + } + } + } + }; + + _dataContext.DataSets.Add(dataset); + _dataContext.SaveChanges(); + + List expected = new List() + { + new Vertex() + { + Id = "id1", + Value = "value1" + }, + new Vertex() + { + Id = "id2", + Value = "value2" + } + }; + + + // Act + var actual = _sut.GetAllVertices(datasetName, vertexIdentifierFieldName); + + // Assert + Assert.Equivalent(expected, actual); + } +} \ No newline at end of file From 58a4f9651194249619116f6797544ed320a155e0 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 00:30:45 -0700 Subject: [PATCH 08/14] refactor: some refactor --- .../Servies/EdgeServiceTest.cs | 70 +++++++++++++++++++ .../Servies/EdgeServiceTest1.cs | 4 +- .../Servies/VertexServiceTest2.cs | 69 ++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs create mode 100644 mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest2.cs diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs new file mode 100644 index 0000000..577a390 --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs @@ -0,0 +1,70 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Protocols; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class EdgeServiceTest +{ + private IServiceProvider _serviceProvider; + private EdgeService _sut; + + public EdgeServiceTest() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new EdgeService(_serviceProvider); + } + + [Fact] + public void GetEdgeDetails_ReturnsCorrectDetails() + { + //Arange + var objectId1 = "object1"; + var objectId2 = "object2"; + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + var att1 = new EdgeAttribute("att1", 1); + var att2 = new EdgeAttribute("att2", 2); + att1.Id = 1; + att2.Id = 2; + + List att = new List() { att1, att2 }; + + foreach (var attribute in att) + { + mockContext.Add(attribute); + } + + var val1 = new EdgeValue("val1", 1, objectId2); + var val2 = new EdgeValue("val2", 1, objectId1); + var val3 = new EdgeValue("val3", 2, objectId1); + var val4 = new EdgeValue("val4", 2, objectId2); + List vertexValues = new List() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) + { + mockContext.Add(value); + } + + mockContext.SaveChanges(); + var expected = new Dictionary(); + expected[att1.Name] = val2.StringValue; + expected[att2.Name] = val3.StringValue; + //Action + var result = _sut.GetEdgeDetails(objectId1); + //assert + Assert.Equal(result.AttributeValue, expected); + } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs index e73250a..be862eb 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest1.cs @@ -6,13 +6,13 @@ using mohaymen_codestar_Team02.Models.VertexEAV; using mohaymen_codestar_Team02.Services; -public class EdgeServiceTest +public class EdgeServiceTest1 { private IEdgeService _sut; private DataContext _dataContext; private ServiceProvider _serviceProvider; - public EdgeServiceTest() + public EdgeServiceTest1() { var serviceCollection = new ServiceCollection(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest2.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest2.cs new file mode 100644 index 0000000..955822b --- /dev/null +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest2.cs @@ -0,0 +1,69 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Protocols; +using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Models.VertexEAV; +using mohaymen_codestar_Team02.Services; + +namespace mohaymen_codestar_Team02_XUnitTest.Servies; + +public class VertexServiceTest2 +{ + private IServiceProvider _serviceProvider; + private VertexService _sut; + + public VertexServiceTest2() + { + var serviceCollection = new ServiceCollection(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + serviceCollection.AddScoped(_ => new DataContext(options)); + + _serviceProvider = serviceCollection.BuildServiceProvider(); + _sut = new VertexService(_serviceProvider); + } + + [Fact] + public void GetVertexDetails_ReturnsCorrectDetails() + { + //Arange + var objectId1 = "object1"; + var objectId2 = "object2"; + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + var att1 = new VertexAttribute("att1", 1); + var att2 = new VertexAttribute("att2", 2); + att1.Id = 1; + att2.Id = 2; + + List att = new List() { att1, att2 }; + + foreach (var attribute in att) + { + mockContext.Add(attribute); + } + + var val1 = new VertexValue("val1", 1, objectId2); + var val2 = new VertexValue("val2", 1, objectId1); + var val3 = new VertexValue("val3", 2, objectId1); + var val4 = new VertexValue("val4", 2, objectId2); + List vertexValues = new List() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) + { + mockContext.Add(value); + } + + mockContext.SaveChanges(); + var expected = new Dictionary(); + expected[att1.Name] = val2.StringValue; + expected[att2.Name] = val3.StringValue; + //Action + var result = _sut.GetVertexDetails(objectId1); + //assert + Assert.Equal(result.AttributeValue, expected); + } +} \ No newline at end of file From 0790776d5d7cf56de3529a2436ba183e30c8d788 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 03:10:20 -0700 Subject: [PATCH 09/14] refactor: some refactor on services related to creating graph --- .../Controllers/DataAdminController.cs | 4 ++- .../Data/Resources.Designer.cs | 10 ++++++++ mohaymen-codestar-Team02/Data/Resources.resx | 3 +++ .../DataAdminService/DataAdminService.cs | 8 +++--- .../Services/VertexService.cs | 7 +++--- .../initialProgram/InitialServices.cs | 3 ++- .../DataAdminService/DataAdminServiceTest.cs | 4 ++- .../Servies/GraphServiceTest.cs | 25 +++++++++++-------- .../Servies/VertexServiceTest.cs | 6 ++--- 9 files changed, 48 insertions(+), 22 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index fdf3655..efaabb2 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -14,12 +14,14 @@ public class DataAdminController : ControllerBase { private readonly IDataAdminService _dataAdminService; private readonly IFileReader _fileReader; + private readonly IGraphService _graphService; public DataAdminController(IDataAdminService dataAdminService, - IFileReader fileReader) + IFileReader fileReader, IGraphService graphService) { _dataAdminService = dataAdminService; _fileReader = fileReader; + _graphService = graphService; _dataAdminService = dataAdminService; } diff --git a/mohaymen-codestar-Team02/Data/Resources.Designer.cs b/mohaymen-codestar-Team02/Data/Resources.Designer.cs index ccdea07..a1fb0c3 100644 --- a/mohaymen-codestar-Team02/Data/Resources.Designer.cs +++ b/mohaymen-codestar-Team02/Data/Resources.Designer.cs @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -86,6 +87,15 @@ internal static string DontHaveThisRole { } } + /// + /// Looks up a localized string similar to GraphFetchedSuccessfully. + /// + internal static string GraphFetchedSuccessfully { + get { + return ResourceManager.GetString("GraphFetchedSuccessfully", resourceCulture); + } + } + /// /// Looks up a localized string similar to InvalidInput. /// diff --git a/mohaymen-codestar-Team02/Data/Resources.resx b/mohaymen-codestar-Team02/Data/Resources.resx index 1c7cdba..ad0844b 100644 --- a/mohaymen-codestar-Team02/Data/Resources.resx +++ b/mohaymen-codestar-Team02/Data/Resources.resx @@ -88,4 +88,7 @@ Roles Retrieved Successfully + + GraphFetchedSuccessfully + \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index 5adfee7..9d1cd18 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -20,6 +20,7 @@ public class DataAdminService private readonly IDisplayDataService _displayDataService; private readonly IServiceProvider _serviceProvider; private readonly IMapper _mapper; + private readonly IGraphService _graphService; public DataAdminService( IServiceProvider serviceProvider, @@ -28,7 +29,7 @@ public DataAdminService( IStorHandler storHandler, IDisplayDataService displayDataService, IEdgeService edgeService, - IVertexService vertexService, IMapper mapper) + IVertexService vertexService, IMapper mapper, IGraphService graphService) { _tokenService = tokenService; _cookieService = cookieService; @@ -37,6 +38,7 @@ public DataAdminService( _storHandler = storHandler; _displayDataService = displayDataService; _mapper = mapper; + _graphService = graphService; _serviceProvider = serviceProvider; } @@ -106,7 +108,7 @@ public async Task> DisplayGeraphData(string dat string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { - var graph = _displayDataService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, + var graph = _graphService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); @@ -115,7 +117,7 @@ public async Task> DisplayGeraphData(string dat Vertices = graph.vertices, Edges = graph.edges, }; - return new ServiceResponse(dto, ApiResponseType.Success, ""); + return new ServiceResponse(dto, ApiResponseType.Success, Resources.GraphFetchedSuccessfully); } public ServiceResponse GetVertexDetail(string objectId) diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index baa7234..d5357db 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -17,11 +17,12 @@ public VertexService(IServiceProvider serviceProvider) public List GetAllVertices(string datasetName, string vertexIdentifierFieldName) { - var scope = _serviceProvider.CreateScope(); + using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); + var dataSet = context.DataSets.Include(ds => ds.VertexEntity) - .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) - .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(datasetName.ToLower())); + .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues) + .FirstOrDefault(ds => ds.Name.ToLower().Equals(datasetName.ToLower())); var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); diff --git a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs index 88cfe8f..3601a19 100644 --- a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs +++ b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs @@ -60,7 +60,8 @@ public static void ConfigureServices(IServiceCollection services, WebApplication .AddScoped() .AddScoped() .AddScoped() - .AddScoped(); + .AddScoped() + .AddScoped(); services.AddAutoMapper(typeof(AutoMapperProfile)); services.AddAuthorization(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index cc6c061..26df94b 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -27,9 +27,11 @@ public class DataAdminServiceTest private readonly IVertexService _vertexService; private readonly ITokenService _tokenService; private readonly ICookieService _cookieService; + private readonly IGraphService _graphService; public DataAdminServiceTest() { + _graphService = Substitute.For(); _cookieService = Substitute.For(); _tokenService = Substitute.For(); _vertexService = Substitute.For(); @@ -50,7 +52,7 @@ public DataAdminServiceTest() _sut = new mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService(_serviceProvider, _tokenService, - _cookieService, _storHandler, _displayDataService, _edgeService, _vertexService, _mapper); + _cookieService, _storHandler, _displayDataService, _edgeService, _vertexService, _mapper, _graphService); _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs index 04f6b4a..362c73a 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs @@ -4,20 +4,22 @@ using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Models; using mohaymen_codestar_Team02.Services; +using NSubstitute; +using QuikGraph; namespace mohaymen_codestar_Team02_XUnitTest.Servies; public class GraphServiceTest { - private IGraphService _sut; + private GraphService _sut; private readonly IVertexService _vertexService; private readonly IEdgeService _edgeService; - public GraphServiceTest(IVertexService vertexService, IEdgeService edgeService) + public GraphServiceTest() { - _vertexService = vertexService; - _edgeService = edgeService; - _sut = new GraphService(vertexService, edgeService); + _vertexService = Substitute.For(); + _edgeService = Substitute.For(); + _sut = new GraphService(_vertexService, _edgeService); } [Fact] @@ -50,14 +52,17 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN } }; + var expected = (expectedVertex, expectedEdge); + + _vertexService.GetAllVertices(datasetName, vertexIdentifierFieldName).Returns(expectedVertex); + _edgeService.GetAllEdges(datasetName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName).Returns(expectedEdge); + // Act var actual = _sut.GetGraph(datasetName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); - var actualVertex = actual.vertices; - var actualEdge = actual.edges; - + // Assert - Assert.Equivalent(expectedVertex, actualVertex); - Assert.Equivalent(expectedEdge, actualEdge); + Assert.Equivalent(expected, actual); } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs index 193ca8d..aa4ba46 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs @@ -72,7 +72,7 @@ public void GetVertexDetails_ReturnsCorrectDetails() public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() { using var scope = _serviceProvider.CreateScope(); - var _dataContext = scope.ServiceProvider.GetRequiredService(); + var mockContext = scope.ServiceProvider.GetRequiredService(); // Arrange string datasetName = "DataSet1"; @@ -96,8 +96,8 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() } }; - _dataContext.DataSets.Add(dataset); - _dataContext.SaveChanges(); + mockContext.DataSets.Add(dataset); + mockContext.SaveChanges(); List expected = new List() { From 466b5ef4ea8a3ffa4ea83c9d2483dcd1035b6aef Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 03:15:44 -0700 Subject: [PATCH 10/14] refactor: refactor on getDatasetLists --- .../Controllers/DataAdminController.cs | 6 +++--- .../Services/DataAdminService/DataAdminService.cs | 9 +-------- .../Services/DataAdminService/IDataAdminService.cs | 2 +- .../Servies/DataAdminService/DataAdminServiceTest.cs | 2 +- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index efaabb2..5858be8 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -43,10 +43,10 @@ public async Task StoreNewDataSet([FromForm] StoreDataDto storeDa } } - [HttpGet("DataSets/{username}")] - public IActionResult GetDataSetsList(string username) + [HttpGet("DataSets")] + public IActionResult GetDataSetsList() { - var response = _dataAdminService.DisplayDataSet(username); + var response = _dataAdminService.DisplayDataSet(); return StatusCode((int)response.Type, response); //Todo all Of Them diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index 9d1cd18..8d5d6e3 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -81,7 +81,7 @@ public async Task> StoreData(string? edgeFile, string? v } } - public ServiceResponse> DisplayDataSet(string username) + public ServiceResponse> DisplayDataSet() { var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -91,18 +91,11 @@ public ServiceResponse> DisplayDataSet(string username) .Include(ds => ds.VertexEntity) .Include(ds => ds.EdgeEntity) .Include(ds => ds.User) - .Where(ds => ds.User.Username == username) .ToList(); var dataGroupDtos = datasets.Select(ds => _mapper.Map(ds)).ToList(); return new ServiceResponse>(dataGroupDtos, ApiResponseType.Success, ""); } - - public Task> DisplayDataSet() - { - throw new NotImplementedException(); - } - public async Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs index b222f01..03f994c 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs @@ -9,7 +9,7 @@ public interface IDataAdminService Task> StoreData(string? edgeFile, string? vertexFile, string graphName , string? edgeEntityName, string vertexEntityName); - ServiceResponse> DisplayDataSet(string username); + ServiceResponse> DisplayDataSet(); Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index 26df94b..7dfe794 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -221,7 +221,7 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() }); // Act - var actual = _sut.DisplayDataSet(username); + var actual = _sut.DisplayDataSet(); // Assert Assert.Equivalent(expected, actual); From 908a6603031076e00a8645f3d409c25dd08ee59b Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Mon, 26 Aug 2024 15:43:51 +0330 Subject: [PATCH 11/14] fix: fix the migration --- .../Dto/InfoDto/InfoDto.cs | 6 + .../20240826115617_fixName.Designer.cs | 418 ++++++++++++++++++ .../Migrations/20240826115617_fixName.cs | 38 ++ .../Migrations/DataContextModelSnapshot.cs | 12 +- mohaymen-codestar-Team02/Models/DataGroup.cs | 14 +- .../Models/EdgeEAV/EdgeEntity.cs | 2 +- .../Models/VertexEAV/VertexEntity.cs | 2 +- .../Models/newModel/Tables.cs | 10 + .../Services/StoreData/EdgeStorerCsv.cs | 2 +- .../Services/StoreData/VertexStorerCsv.cs | 2 +- .../initialProgram/InitialServices.cs | 1 + 11 files changed, 489 insertions(+), 18 deletions(-) create mode 100644 mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs create mode 100644 mohaymen-codestar-Team02/Migrations/20240826115617_fixName.Designer.cs create mode 100644 mohaymen-codestar-Team02/Migrations/20240826115617_fixName.cs create mode 100644 mohaymen-codestar-Team02/Models/newModel/Tables.cs diff --git a/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs b/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs new file mode 100644 index 0000000..885efc5 --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs @@ -0,0 +1,6 @@ +namespace mohaymen_codestar_Team02.Dto.InfoDto; + +public class InfoDto +{ + +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.Designer.cs b/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.Designer.cs new file mode 100644 index 0000000..95f6161 --- /dev/null +++ b/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.Designer.cs @@ -0,0 +1,418 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using mohaymen_codestar_Team02.Data; + +#nullable disable + +namespace mohaymen_codestar_Team02.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240826115617_fixName")] + partial class fixName + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.DataGroup", b => + { + b.Property("DataGroupId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("DataGroupId")); + + b.Property("CreateAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UpdateAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("DataGroupId"); + + b.HasIndex("UserId"); + + b.ToTable("DataSets"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EdgeEntityId") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("EdgeEntityId"); + + b.ToTable("EdgeAttributes"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", b => + { + b.Property("EdgeEntityId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EdgeEntityId")); + + b.Property("DataGroupId") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("EdgeEntityId"); + + b.HasIndex("DataGroupId") + .IsUnique(); + + b.ToTable("EdgeEntities"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeValue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EdgeAttributeId") + .HasColumnType("bigint"); + + b.Property("ObjectId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StringValue") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("EdgeAttributeId"); + + b.ToTable("EdgeValues"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.Role", b => + { + b.Property("RoleId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("RoleId")); + + b.Property("Permissions") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("RoleType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("RoleId"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.User", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserId")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("bytea"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("bytea"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.HasKey("UserId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("bigint"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("VertexEntityId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VertexEntityId"); + + b.ToTable("VertexAttributes"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", b => + { + b.Property("VertexEntityId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VertexEntityId")); + + b.Property("DataGroupId") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("VertexEntityId"); + + b.HasIndex("DataGroupId") + .IsUnique(); + + b.ToTable("VertexEntities"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexValue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ObjectId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StringValue") + .IsRequired() + .HasColumnType("text"); + + b.Property("VertexAttributeId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VertexAttributeId"); + + b.ToTable("VertexValues"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.DataGroup", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.User", "User") + .WithMany("DataSets") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeAttribute", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", "EdgeEntity") + .WithMany("EdgeAttributes") + .HasForeignKey("EdgeEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EdgeEntity"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.DataGroup", "DataGroup") + .WithOne("EdgeEntity") + .HasForeignKey("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", "DataGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataGroup"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeValue", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeAttribute", "EdgeAttribute") + .WithMany("EdgeValues") + .HasForeignKey("EdgeAttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EdgeAttribute"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.UserRole", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("mohaymen_codestar_Team02.Models.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexAttribute", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", "VertexEntity") + .WithMany("VertexAttributes") + .HasForeignKey("VertexEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("VertexEntity"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.DataGroup", "DataGroup") + .WithOne("VertexEntity") + .HasForeignKey("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", "DataGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataGroup"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexValue", b => + { + b.HasOne("mohaymen_codestar_Team02.Models.VertexEAV.VertexAttribute", "VertexAttribute") + .WithMany("VertexValues") + .HasForeignKey("VertexAttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("VertexAttribute"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.DataGroup", b => + { + b.Navigation("EdgeEntity") + .IsRequired(); + + b.Navigation("VertexEntity") + .IsRequired(); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeAttribute", b => + { + b.Navigation("EdgeValues"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", b => + { + b.Navigation("EdgeAttributes"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.Role", b => + { + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.User", b => + { + b.Navigation("DataSets"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexAttribute", b => + { + b.Navigation("VertexValues"); + }); + + modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", b => + { + b.Navigation("VertexAttributes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.cs b/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.cs new file mode 100644 index 0000000..6d30013 --- /dev/null +++ b/mohaymen-codestar-Team02/Migrations/20240826115617_fixName.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace mohaymen_codestar_Team02.Migrations +{ + /// + public partial class fixName : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "Id", + table: "VertexEntities", + newName: "VertexEntityId"); + + migrationBuilder.RenameColumn( + name: "Id", + table: "EdgeEntities", + newName: "EdgeEntityId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "VertexEntityId", + table: "VertexEntities", + newName: "Id"); + + migrationBuilder.RenameColumn( + name: "EdgeEntityId", + table: "EdgeEntities", + newName: "Id"); + } + } +} diff --git a/mohaymen-codestar-Team02/Migrations/DataContextModelSnapshot.cs b/mohaymen-codestar-Team02/Migrations/DataContextModelSnapshot.cs index 8afc2cd..5b4783a 100644 --- a/mohaymen-codestar-Team02/Migrations/DataContextModelSnapshot.cs +++ b/mohaymen-codestar-Team02/Migrations/DataContextModelSnapshot.cs @@ -77,11 +77,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("mohaymen_codestar_Team02.Models.EdgeEAV.EdgeEntity", b => { - b.Property("Id") + b.Property("EdgeEntityId") .ValueGeneratedOnAdd() .HasColumnType("bigint"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EdgeEntityId")); b.Property("DataGroupId") .HasColumnType("bigint"); @@ -90,7 +90,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.HasKey("Id"); + b.HasKey("EdgeEntityId"); b.HasIndex("DataGroupId") .IsUnique(); @@ -226,11 +226,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("mohaymen_codestar_Team02.Models.VertexEAV.VertexEntity", b => { - b.Property("Id") + b.Property("VertexEntityId") .ValueGeneratedOnAdd() .HasColumnType("bigint"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VertexEntityId")); b.Property("DataGroupId") .HasColumnType("bigint"); @@ -239,7 +239,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.HasKey("Id"); + b.HasKey("VertexEntityId"); b.HasIndex("DataGroupId") .IsUnique(); diff --git a/mohaymen-codestar-Team02/Models/DataGroup.cs b/mohaymen-codestar-Team02/Models/DataGroup.cs index 9868b74..ea1c630 100644 --- a/mohaymen-codestar-Team02/Models/DataGroup.cs +++ b/mohaymen-codestar-Team02/Models/DataGroup.cs @@ -13,20 +13,18 @@ public DataGroup(string name, long userId) Name = name; UserId = userId; } - - public DataGroup() { } + + public DataGroup() + { + } [Key] public long DataGroupId { get; set; } public string Name { get; set; } public DateTime CreateAt { get; set; } = DateTime.UtcNow; public DateTime UpdateAt { get; set; } = DateTime.UtcNow; - - - public virtual long EdgeEntityId { get; set; } - [ForeignKey("EdgeEntityId")] public virtual EdgeEntity EdgeEntity { get; set; } - public virtual long VertexEntityId { get; set; } - [ForeignKey("VertexEntityId")] public virtual VertexEntity VertexEntity { get; set; } + public virtual EdgeEntity EdgeEntity { get; set; } + public virtual VertexEntity VertexEntity { get; set; } public long UserId { get; set; } diff --git a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs index 3a8e641..06137bd 100644 --- a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs +++ b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs @@ -30,7 +30,7 @@ public EdgeEntity(string name, long dataGroupId) } - [Key] public long Id { get; set; } + [Key] public long EdgeEntityId { get; set; } private string _name; public string Name diff --git a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs index 4cbd302..8d3c71e 100644 --- a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs +++ b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs @@ -30,7 +30,7 @@ public VertexEntity(string name, long dataGroupId) } } - [Key] public long Id { get; set; } + [Key] public long VertexEntityId { get; set; } private string _name; public string Name diff --git a/mohaymen-codestar-Team02/Models/newModel/Tables.cs b/mohaymen-codestar-Team02/Models/newModel/Tables.cs new file mode 100644 index 0000000..e0be685 --- /dev/null +++ b/mohaymen-codestar-Team02/Models/newModel/Tables.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace mohaymen_codestar_Team02.Models.newModel; + +public class Tables +{ + [Key] public long Id { get; set; } + public string Name { get; set; } + +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/StoreData/EdgeStorerCsv.cs b/mohaymen-codestar-Team02/Services/StoreData/EdgeStorerCsv.cs index 79f202a..8756df9 100644 --- a/mohaymen-codestar-Team02/Services/StoreData/EdgeStorerCsv.cs +++ b/mohaymen-codestar-Team02/Services/StoreData/EdgeStorerCsv.cs @@ -36,7 +36,7 @@ public async Task StoreFileData(string entityName, string dataFile, long d headers[headers.Length - 1] = lastWodrd.Substring(0, lastWodrd.Length - 1); - foreach (var att in headers) edgeAttributes.Add(new EdgeAttribute(att, edgeEntity.Id)); + foreach (var att in headers) edgeAttributes.Add(new EdgeAttribute(att, edgeEntity.EdgeEntityId)); foreach (var attribute in edgeAttributes) await dataContext.EdgeAttributes.AddAsync(attribute); diff --git a/mohaymen-codestar-Team02/Services/StoreData/VertexStorerCsv.cs b/mohaymen-codestar-Team02/Services/StoreData/VertexStorerCsv.cs index e5a705f..9c2d193 100644 --- a/mohaymen-codestar-Team02/Services/StoreData/VertexStorerCsv.cs +++ b/mohaymen-codestar-Team02/Services/StoreData/VertexStorerCsv.cs @@ -38,7 +38,7 @@ public async Task StoreFileData(string entityName, string dataFile, long d headers[headers.Length - 1] = lastWords.Substring(0, lastWords.Length - 1); } - foreach (var att in headers) edgeAttributes.Add(new VertexAttribute(att, edgeEntity.Id)); + foreach (var att in headers) edgeAttributes.Add(new VertexAttribute(att, edgeEntity.VertexEntityId)); foreach (var attribute in edgeAttributes) await dataContext.VertexAttributes.AddAsync(attribute); diff --git a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs index 3601a19..006543a 100644 --- a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs +++ b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs @@ -40,6 +40,7 @@ public static void ConfigureServices(IServiceCollection services, WebApplication // Configure DbContext and Dependency Injection var cs = builder.Configuration["CONNECTION_STRING"]; + Console.WriteLine("your connection string is ==>"+cs); services.AddDbContext(options => options.UseNpgsql(cs)); From cd53af451634b7e7f1094b2bc3c0e8c1dbac65b5 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Mon, 26 Aug 2024 05:17:06 -0700 Subject: [PATCH 12/14] refactor: some refactor on test --- .../DataAdminService/DataAdminService.cs | 4 +- .../DataAdminService/DataAdminServiceTest.cs | 49 ++++++++----------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index 8d5d6e3..a80b668 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -85,12 +85,10 @@ public ServiceResponse> DisplayDataSet() { var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - - + var datasets = context.DataSets .Include(ds => ds.VertexEntity) .Include(ds => ds.EdgeEntity) - .Include(ds => ds.User) .ToList(); var dataGroupDtos = datasets.Select(ds => _mapper.Map(ds)).ToList(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index 7dfe794..69d0a55 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -164,39 +164,30 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() }; var expected = new ServiceResponse>(GetDataGroupDtos, ApiResponseType.Success, ""); - - var user = new User() + + var dataset1 = new DataGroup { + Name = datasetName1, UserId = 1, - Username = username, - DataSets = new List() - { - new DataGroup - { - Name = datasetName1, - UserId = 1, - DataGroupId = 1, - CreateAt = DateTime.MaxValue, - UpdateAt = DateTime.MaxValue, - VertexEntity = new VertexEntity(vertexEntityName1, 1), - EdgeEntity = new EdgeEntity(EdgeEntityName1, 1) - }, - new DataGroup - { - Name = datasetName2, - UserId = 1, - DataGroupId = 2, - CreateAt = DateTime.MaxValue, - UpdateAt = DateTime.MaxValue, - VertexEntity = new VertexEntity(vertexEntityName2, 2), - EdgeEntity = new EdgeEntity(EdgeEntityName2, 2) - } - }, - PasswordHash = new byte[]{}, - Salt = new byte[]{} + DataGroupId = 1, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new VertexEntity(vertexEntityName1, 1), + EdgeEntity = new EdgeEntity(EdgeEntityName1, 1) + }; + var dataset2 = new DataGroup + { + Name = datasetName2, + UserId = 1, + DataGroupId = 2, + CreateAt = DateTime.MaxValue, + UpdateAt = DateTime.MaxValue, + VertexEntity = new VertexEntity(vertexEntityName2, 2), + EdgeEntity = new EdgeEntity(EdgeEntityName2, 2) }; - _dataContext.Users.Add(user); + _dataContext.DataSets.Add(dataset1); + _dataContext.DataSets.Add(dataset2); _dataContext.SaveChanges(); From c53007c5f2c16a3f0af5451f58207c2f9971fe03 Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Mon, 26 Aug 2024 15:58:14 +0330 Subject: [PATCH 13/14] fix: fix the test --- .../DataAdminService/DataAdminServiceTest.cs | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index 69d0a55..37de1ff 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -39,7 +39,7 @@ public DataAdminServiceTest() _storHandler = Substitute.For(); _displayDataService = Substitute.For(); _mapper = Substitute.For(); - + var serviceCollection = new ServiceCollection(); var options = new DbContextOptionsBuilder() @@ -53,15 +53,44 @@ public DataAdminServiceTest() _sut = new mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService(_serviceProvider, _tokenService, _cookieService, _storHandler, _displayDataService, _edgeService, _vertexService, _mapper, _graphService); - _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); + _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } + private void FixTheReturnOfCookies(string? returnThis) + { + _cookieService.GetCookieValue().Returns(returnThis); + _tokenService.GetUserNameFromToken().Returns(returnThis); + } + + private UserRole AddUserWithRole(string userName, string roleType, long id) + { + using var scope = _serviceProvider.CreateScope(); + var _mockContext = scope.ServiceProvider.GetRequiredService(); + + var user = new User + { + Salt = Array.Empty(), + PasswordHash = Array.Empty(), + Username = userName, + UserId = id + }; + var role = new Role { RoleType = roleType, RoleId = id }; + var userRole = new UserRole { UserId = user.UserId, RoleId = role.RoleId }; + _mockContext.Users.Add(user); + _mockContext.Roles.Add(role); + _mockContext.UserRoles.Add(userRole); + _mockContext.SaveChanges(); + return new UserRole { Role = role, User = user }; + } + [Theory] [InlineData("")] [InlineData(null)] public async Task StoreData_ReturnsBadRequest_WhenNameIsNullOrEmpty(string? name) { + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); //Arrange //Action var result = await _sut.StoreData("sample", "sample", "mahdddd", name, "ma"); @@ -73,7 +102,9 @@ public async Task StoreData_ReturnsBadRequest_WhenNameIsNullOrEmpty(string? name public async Task StoreData_ReturnsBadRequest_WhenCreatingTheDataGroupIsFail() { //Arrange - _storHandler.StoreDataSet("mahdddd", "8").Returns(-1); + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); + _storHandler.StoreDataSet("mahdddd", Arg.Any()).Returns(-1); //Action var result = await _sut.StoreData("sample", "sample", "mahdddd", "name", "ma"); //Assert @@ -84,6 +115,8 @@ public async Task StoreData_ReturnsBadRequest_WhenCreatingTheDataGroupIsFail() public async Task StoreData_ReturnsBadRequest_WhenEdageStorerStoreValuesReturnFalse() { //Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); //Action var result = await _sut.StoreData("sample", "sample", "test", "mahdddd", "mahdddd"); @@ -95,6 +128,8 @@ public async Task StoreData_ReturnsBadRequest_WhenEdageStorerStoreValuesReturnFa public async Task StoreData_ReturnsBadRequest_WhenVertexStorerStoreValuesReturnFalse() { // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); // Act @@ -108,13 +143,15 @@ public async Task StoreData_ReturnsBadRequest_WhenVertexStorerStoreValuesReturnF public async Task StoreData_ReturnsSuccess_WhenInputAreValid() { // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); _storHandler.StoreDataSet(Arg.Any(), Arg.Any()).Returns(9); // Act var result = await _sut.StoreData("sampleEdgeFile", "sampleVertexFile", "testData", "a", "lll"); // Assert Assert.Equal(ApiResponseType.Success, result.Type); } - + [Fact] public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() { @@ -122,6 +159,8 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() _dataContext = scope.ServiceProvider.GetRequiredService(); // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SustemAdmin", 1); var username = "username1"; var datasetName1 = "Dataset1"; var datasetName2 = "Dataset2"; @@ -149,7 +188,7 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() new GetDataGroupDto() { Name = datasetName2, - + CreateAt = DateTime.MaxValue, UpdateAt = DateTime.MaxValue, VertexEntity = new GetVertexEntityDto() @@ -162,7 +201,7 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() } } }; - + var expected = new ServiceResponse>(GetDataGroupDtos, ApiResponseType.Success, ""); var dataset1 = new DataGroup @@ -210,12 +249,11 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() VertexEntity = new GetVertexEntityDto { Name = vertexEntityName2 }, EdgeEntity = new GetEdgeEntityDto { Name = EdgeEntityName2 } }); - + // Act var actual = _sut.DisplayDataSet(); // Assert Assert.Equivalent(expected, actual); } - } \ No newline at end of file From c4918f15769512989555cd2e17e038f7018cb3b5 Mon Sep 17 00:00:00 2001 From: Mahdizahedi2005 Date: Mon, 26 Aug 2024 16:01:08 +0330 Subject: [PATCH 14/14] fix: the format --- mohaymen-codestar-Team02.sln.DotSettings | 2 + .../Controllers/DataAdminController.cs | 2 +- .../Dto/GetDataGroupDto.cs | 4 +- .../Dto/GraphDTO/DetailDto.cs | 3 +- .../Dto/InfoDto/InfoDto.cs | 1 - .../Mapper/AutoMapperProfile.cs | 7 +-- .../Models/EdgeEAV/EdgeEntity.cs | 8 ++- mohaymen-codestar-Team02/Models/Role.cs | 2 +- .../Models/VertexEAV/VertexEntity.cs | 5 +- .../Models/newModel/Tables.cs | 1 - .../DataAdminService/DataAdminService.cs | 38 ++++++------- .../Services/DisplayData/DisplayService.cs | 51 ++++++++--------- .../Services/EdgeService.cs | 56 ++++++++----------- .../Services/IEdgeService.cs | 1 + .../Services/VertexService.cs | 7 +-- .../initialProgram/InitialServices.cs | 4 +- .../DataAdminService/DataAdminServiceTest.cs | 4 +- .../Servies/EdgeServiceTest.cs | 55 ++++++++---------- .../Servies/GraphServiceTest.cs | 13 +++-- .../Servies/VertexServiceTest.cs | 39 ++++++------- .../mohaymen-codestar-Team02_XUnitTest.csproj | 18 +++--- task.txt | 7 +++ 22 files changed, 153 insertions(+), 175 deletions(-) create mode 100644 mohaymen-codestar-Team02.sln.DotSettings create mode 100644 task.txt diff --git a/mohaymen-codestar-Team02.sln.DotSettings b/mohaymen-codestar-Team02.sln.DotSettings new file mode 100644 index 0000000..7ff5b6c --- /dev/null +++ b/mohaymen-codestar-Team02.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 5858be8..5b247b7 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -48,7 +48,7 @@ public IActionResult GetDataSetsList() { var response = _dataAdminService.DisplayDataSet(); return StatusCode((int)response.Type, response); - + //Todo all Of Them } diff --git a/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs b/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs index ec784a7..95d6523 100644 --- a/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs +++ b/mohaymen-codestar-Team02/Dto/GetDataGroupDto.cs @@ -6,10 +6,10 @@ namespace mohaymen_codestar_Team02.Dto; public class GetDataGroupDto { public string Name { get; set; } - + public DateTime CreateAt { get; set; } = DateTime.UtcNow; public DateTime UpdateAt { get; set; } = DateTime.UtcNow; - + public virtual GetEdgeEntityDto EdgeEntity { get; set; } public virtual GetVertexEntityDto VertexEntity { get; set; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs b/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs index eeb6b0b..535f59f 100644 --- a/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs +++ b/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs @@ -2,6 +2,5 @@ namespace mohaymen_codestar_Team02.Dto.GraphDTO; public class DetailDto { - public Dictionary? AttributeValue { get; set; } = new Dictionary(); - + public Dictionary? AttributeValue { get; set; } = new(); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs b/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs index 885efc5..1eb7a52 100644 --- a/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs +++ b/mohaymen-codestar-Team02/Dto/InfoDto/InfoDto.cs @@ -2,5 +2,4 @@ namespace mohaymen_codestar_Team02.Dto.InfoDto; public class InfoDto { - } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs b/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs index 55fe910..9fbcdaa 100644 --- a/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs +++ b/mohaymen-codestar-Team02/Mapper/AutoMapperProfile.cs @@ -21,14 +21,13 @@ public AutoMapperProfile() CreateMap(); CreateMap(); CreateMap() - .ForMember(dest => dest.EdgeEntity, opt => + .ForMember(dest => dest.EdgeEntity, opt => opt.MapFrom(src => src.EdgeEntity)) - .ForMember(dest => dest.VertexEntity, opt => + .ForMember(dest => dest.VertexEntity, opt => opt.MapFrom(src => src.VertexEntity)); CreateMap() - .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)); + .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)); CreateMap(); CreateMap(); - } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs index 06137bd..cdde2a6 100644 --- a/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs +++ b/mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs @@ -6,10 +6,13 @@ namespace mohaymen_codestar_Team02.Models.EdgeEAV; public class EdgeEntity { - public EdgeEntity(){} + public EdgeEntity() + { + } + public EdgeEntity(string name, long dataGroupId) { - Regex regex = + var regex = new Regex( "^[^!]+!Edge![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}!$"); var match = regex.Match(name); @@ -27,7 +30,6 @@ public EdgeEntity(string name, long dataGroupId) { throw new ArgumentException("your name contain !"); } - } [Key] public long EdgeEntityId { get; set; } diff --git a/mohaymen-codestar-Team02/Models/Role.cs b/mohaymen-codestar-Team02/Models/Role.cs index dc387a5..d02a8df 100644 --- a/mohaymen-codestar-Team02/Models/Role.cs +++ b/mohaymen-codestar-Team02/Models/Role.cs @@ -7,5 +7,5 @@ public class Role [Key] public long RoleId { get; set; } [Required] public string RoleType { get; set; } = string.Empty; public virtual ICollection UserRoles { get; set; } = new List(); - public virtual List Permissions { get; set; } = new List(); + public virtual List Permissions { get; set; } = new(); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs index 8d3c71e..5ffce26 100644 --- a/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs +++ b/mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs @@ -7,7 +7,10 @@ namespace mohaymen_codestar_Team02.Models.VertexEAV; public class VertexEntity { - public VertexEntity() {} + public VertexEntity() + { + } + public VertexEntity(string name, long dataGroupId) { var regex = diff --git a/mohaymen-codestar-Team02/Models/newModel/Tables.cs b/mohaymen-codestar-Team02/Models/newModel/Tables.cs index e0be685..ac2fa11 100644 --- a/mohaymen-codestar-Team02/Models/newModel/Tables.cs +++ b/mohaymen-codestar-Team02/Models/newModel/Tables.cs @@ -6,5 +6,4 @@ public class Tables { [Key] public long Id { get; set; } public string Name { get; set; } - } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index a80b668..c52957e 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -49,29 +49,27 @@ public async Task> StoreData(string? edgeFile, string? v { var token = _cookieService.GetCookieValue(); if (string.IsNullOrEmpty(token)) - { return new ServiceResponse(null, ApiResponseType.Unauthorized, Resources.UnauthorizedMessage); - } var userName = _tokenService.GetUserNameFromToken(); if (string.IsNullOrEmpty(edgeEntityName) || string.IsNullOrEmpty(graphName) || string.IsNullOrEmpty(vertexEntityName)) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, - Data.Resources.InvalidInpute); + Resources.InvalidInpute); var dataGroupId = await _storHandler.StoreDataSet(graphName, userName); if (dataGroupId == -1) return new ServiceResponse(string.Empty, ApiResponseType.BadRequest, - Data.Resources.InvalidInpute); + Resources.InvalidInpute); if (!await _storHandler.EdageStorer.StoreFileData(edgeEntityName, edgeFile, dataGroupId)) return new ServiceResponse(string.Empty, - ApiResponseType.BadRequest, Data.Resources.InvalidInpute); + ApiResponseType.BadRequest, Resources.InvalidInpute); if (!await _storHandler.VertexStorer.StoreFileData(vertexEntityName, vertexFile, dataGroupId)) return new ServiceResponse(string.Empty, - ApiResponseType.BadRequest, Data.Resources.InvalidInpute); + ApiResponseType.BadRequest, Resources.InvalidInpute); return new ServiceResponse(null, ApiResponseType.Success, string.Empty); } @@ -85,7 +83,7 @@ public ServiceResponse> DisplayDataSet() { var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - + var datasets = context.DataSets .Include(ds => ds.VertexEntity) .Include(ds => ds.EdgeEntity) @@ -97,7 +95,7 @@ public ServiceResponse> DisplayDataSet() public async Task> DisplayGeraphData(string databaseName, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { var graph = _graphService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, @@ -106,20 +104,20 @@ public async Task> DisplayGeraphData(string dat var dto = new DisplayGraphDto() { Vertices = graph.vertices, - Edges = graph.edges, + Edges = graph.edges }; return new ServiceResponse(dto, ApiResponseType.Success, Resources.GraphFetchedSuccessfully); } - -public ServiceResponse GetVertexDetail(string objectId) -{ - return new ServiceResponse(_vertexService.GetVertexDetails(objectId), ApiResponseType.Success, - string.Empty); -} -public ServiceResponse GetEdgeDetail(string objectId) -{ - return new ServiceResponse(_edgeService.GetEdgeDetails(objectId), ApiResponseType.Success, - string.Empty); -} + public ServiceResponse GetVertexDetail(string objectId) + { + return new ServiceResponse(_vertexService.GetVertexDetails(objectId), ApiResponseType.Success, + string.Empty); + } + + public ServiceResponse GetEdgeDetail(string objectId) + { + return new ServiceResponse(_edgeService.GetEdgeDetails(objectId), ApiResponseType.Success, + string.Empty); + } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs b/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs index 3fd2481..000954a 100644 --- a/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs +++ b/mohaymen-codestar-Team02/Services/DisplayData/DisplayService.cs @@ -20,16 +20,17 @@ public List GetVertices(string databaseName, string vertexIdentifierFiel { var dataSet = _context.DataSets.Include(ds => ds.VertexEntity) .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) - .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues) + .FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List vertices = new List(); + List vertices = new(); foreach (var record in vertexRecords) { var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; - Vertex v = new Vertex() + var v = new Vertex() { Id = record.Key, Value = value @@ -39,22 +40,23 @@ public List GetVertices(string databaseName, string vertexIdentifierFiel return vertices; } - + public (List vertices, List edges) GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { var dataSet = _context.DataSets.Include(ds => ds.VertexEntity) .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) - .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues) + .FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List vertices = new List(); + List vertices = new(); foreach (var record in vertexRecords) { var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; - Vertex v = new Vertex() + var v = new Vertex() { Id = record.Key, Value = value @@ -65,53 +67,46 @@ public List GetVertices(string databaseName, string vertexIdentifierFiel var edgeRecords = dataSet.EdgeEntity.EdgeAttributes.Select(ea => ea.EdgeValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List edges = new List(); + List edges = new(); foreach (var record in edgeRecords) { - string sourceValue = string.Empty; - string destinationValue = string.Empty; + var sourceValue = string.Empty; + var destinationValue = string.Empty; foreach (var item in record) { - if (item.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) - { - sourceValue = item.StringValue; - } - if (item.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) - { - destinationValue = item.StringValue; - } + if (item.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) sourceValue = item.StringValue; + if (item.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) destinationValue = item.StringValue; } - List sources = new List(); - List destinations = new List(); + List sources = new(); + List destinations = new(); foreach (var record1 in vertexRecords) - { foreach (var item in record1) { if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == sourceValue) { - Vertex vertex = new Vertex() + var vertex = new Vertex() { Id = record1.Key }; sources.Add(vertex); } + if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == destinationValue) { - Vertex vertex = new Vertex() + var vertex = new Vertex() { Id = record1.Key }; destinations.Add(vertex); } } - } + foreach (var source in sources) - { foreach (var des in destinations) { - Edge edge = new Edge() + var edge = new Edge() { Id = record.Key, Source = source.Id, @@ -119,13 +114,11 @@ public List GetVertices(string databaseName, string vertexIdentifierFiel }; edges.Add(edge); } - } } return (vertices, edges); } - - + /* public void GetGraph(string databaseName, string sourceEdgeIdentifierFieldName, diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs index a62a0b4..fe92cef 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -1,5 +1,3 @@ - - using Microsoft.EntityFrameworkCore; using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; @@ -13,21 +11,22 @@ namespace mohaymen_codestar_Team02.Services; public class EdgeService : IEdgeService { private readonly IServiceProvider _serviceProvider; - + public EdgeService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } - - public List GetAllEdges(string databaseName, string vertexIdentifierFieldName, string sourceEdgeIdentifierFieldName, + + public List GetAllEdges(string databaseName, string vertexIdentifierFieldName, + string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName) { - var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); var dataSet = context.DataSets.Include(ds => ds.VertexEntity) .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).Include(ds => ds.EdgeEntity) - .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); + .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues) + .FirstOrDefault(ds => ds.Name.ToLower().Equals(databaseName.ToLower())); var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); @@ -35,19 +34,19 @@ public List GetAllEdges(string databaseName, string vertexIdentifierFieldN var edgeRecords = dataSet.EdgeEntity.EdgeAttributes.Select(ea => ea.EdgeValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List edges = new List(); + List edges = new(); foreach (var record in edgeRecords) { + GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, + out var sourceValue, out var destinationValue); + + GetSourcesAndDestinations(vertexIdentifierFieldName, vertexRecords, sourceValue, destinationValue, + out var sources, out var destinations); - GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, out var sourceValue, out var destinationValue); - - GetSourcesAndDestinations(vertexIdentifierFieldName, vertexRecords, sourceValue, destinationValue, out var sources, out var destinations); - foreach (var source in sources) - { foreach (var des in destinations) { - Edge edge = new Edge() + var edge = new Edge() { Id = record.Key, Source = source.Id, @@ -55,25 +54,24 @@ public List GetAllEdges(string databaseName, string vertexIdentifierFieldN }; edges.Add(edge); } - } } return edges; } - private void GetSourcesAndDestinations(string vertexIdentifierFieldName, IEnumerable> vertexRecords, + private void GetSourcesAndDestinations(string vertexIdentifierFieldName, + IEnumerable> vertexRecords, string sourceValue, string destinationValue, out List sources, out List destinations) { sources = new List(); destinations = new List(); - + foreach (var record1 in vertexRecords) - { foreach (var item in record1) { if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == sourceValue) { - Vertex vertex = new Vertex() + var vertex = new Vertex() { Id = record1.Key }; @@ -82,33 +80,27 @@ private void GetSourcesAndDestinations(string vertexIdentifierFieldName, IEnumer if (item.VertexAttribute.Name == vertexIdentifierFieldName && item.StringValue == destinationValue) { - Vertex vertex = new Vertex() + var vertex = new Vertex() { Id = record1.Key }; destinations.Add(vertex); } } - } } private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, IGrouping record, out string sourceValue, out string destinationValue) + string destinationEdgeIdentifierFieldName, IGrouping record, out string sourceValue, + out string destinationValue) { sourceValue = string.Empty; destinationValue = string.Empty; foreach (var item in record) { - if (item.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) - { - sourceValue = item.StringValue; - } + if (item.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) sourceValue = item.StringValue; - if (item.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) - { - destinationValue = item.StringValue; - } - } + if (item.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) destinationValue = item.StringValue; + } } public DetailDto GetEdgeDetails(string objId) @@ -118,9 +110,7 @@ public DetailDto GetEdgeDetails(string objId) var validValue = context.EdgeValues.Where(value => value.ObjectId.ToLower() == objId.ToLower()).ToList(); var result = new DetailDto(); foreach (var value in validValue) - { result.AttributeValue[context.EdgeAttributes.Find(value.EdgeAttributeId).Name] = value.StringValue; - } return result; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IEdgeService.cs b/mohaymen-codestar-Team02/Services/IEdgeService.cs index 23dfc85..e8324b5 100644 --- a/mohaymen-codestar-Team02/Services/IEdgeService.cs +++ b/mohaymen-codestar-Team02/Services/IEdgeService.cs @@ -9,5 +9,6 @@ public interface IEdgeService public List GetAllEdges(string databaseName, string vertexIdentifierFieldName, string sourceEdgeIdentifierFieldName, string destinationEdgeIdentifierFieldName); + DetailDto GetEdgeDetails(string objId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index d5357db..a7d6746 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -1,4 +1,3 @@ - using Microsoft.EntityFrameworkCore; using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Dto.GraphDTO; @@ -27,11 +26,11 @@ public List GetAllVertices(string datasetName, string vertexIdentifierFi var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List vertices = new List(); + List vertices = new(); foreach (var record in vertexRecords) { var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; - Vertex v = new Vertex() + var v = new Vertex() { Id = record.Key, Value = value @@ -49,9 +48,7 @@ public DetailDto GetVertexDetails(string objId) var validValue = context.VertexValues.Where(value => value.ObjectId.ToLower() == objId.ToLower()).ToList(); var result = new DetailDto(); foreach (var value in validValue) - { result.AttributeValue[context.VertexAttributes.Find(value.VertexAttributeId).Name] = value.StringValue; - } return result; } diff --git a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs index 006543a..b16e1d7 100644 --- a/mohaymen-codestar-Team02/initialProgram/InitialServices.cs +++ b/mohaymen-codestar-Team02/initialProgram/InitialServices.cs @@ -40,7 +40,7 @@ public static void ConfigureServices(IServiceCollection services, WebApplication // Configure DbContext and Dependency Injection var cs = builder.Configuration["CONNECTION_STRING"]; - Console.WriteLine("your connection string is ==>"+cs); + Console.WriteLine("your connection string is ==>" + cs); services.AddDbContext(options => options.UseNpgsql(cs)); @@ -205,7 +205,7 @@ public void SeadAdmin() r.RoleType.ToLower().Equals(RoleType.SystemAdmin.ToString().ToLower())); var userRole = new UserRole() - { RoleId = role.RoleId, UserId = admin.UserId, Role = role, User = admin }; + { RoleId = role.RoleId, UserId = admin.UserId, Role = role, User = admin }; _context.UserRoles.Add(userRole); _context.Users.Add(admin); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs index 37de1ff..7544aed 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs @@ -171,7 +171,7 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() var GetDataGroupDtos = new List() { - new GetDataGroupDto() + new() { Name = datasetName1, CreateAt = DateTime.MaxValue, @@ -185,7 +185,7 @@ public void DisplayDataSet_ShouldGetDataSet_WhenGivenCorrectUsername() Name = EdgeEntityName1 } }, - new GetDataGroupDto() + new() { Name = datasetName2, diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs index 26abc1e..dfb7f00 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs @@ -42,22 +42,16 @@ public void GetEdgeDetails_ReturnsCorrectDetails() att1.Id = 1; att2.Id = 2; - List att = new List() { att1, att2 }; + List att = new() { att1, att2 }; - foreach (var attribute in att) - { - mockContext.Add(attribute); - } + foreach (var attribute in att) mockContext.Add(attribute); var val1 = new EdgeValue("val1", 1, objectId2); var val2 = new EdgeValue("val2", 1, objectId1); var val3 = new EdgeValue("val3", 2, objectId1); var val4 = new EdgeValue("val4", 2, objectId2); - List vertexValues = new List() { val1, val2, val3, val4 }; - foreach (var value in vertexValues) - { - mockContext.Add(value); - } + List vertexValues = new() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) mockContext.Add(value); mockContext.SaveChanges(); var expected = new Dictionary(); @@ -68,28 +62,28 @@ public void GetEdgeDetails_ReturnsCorrectDetails() //assert Assert.Equal(result.AttributeValue, expected); } - - [Fact] + + [Fact] public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifiersName() { using var scope = _serviceProvider.CreateScope(); var _dataContext = scope.ServiceProvider.GetRequiredService(); // Arrange - string datasetName = "DataSet1"; - string vertexIdentifierFieldName = "CardID"; - string sourceEdgeIdentifierFieldName = "SourceAcount"; - string destinationEdgeIdentifierFieldName = "DestiantionAccount"; + var datasetName = "DataSet1"; + var vertexIdentifierFieldName = "CardID"; + var sourceEdgeIdentifierFieldName = "SourceAcount"; + var destinationEdgeIdentifierFieldName = "DestiantionAccount"; var expected = new List() { - new Edge() + new() { Id = "id1", Source = "id2", Target = "id3" }, - new Edge() + new() { Id = "id2", Source = "id4", @@ -104,21 +98,20 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie { EdgeAttributes = new List { - new EdgeAttribute("SourceAcount", 1) + new("SourceAcount", 1) { EdgeValues = new List { - new EdgeValue("value1", 1, "id1") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1)}, - new EdgeValue("value2", 1, "id2") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1)}, - + new("value1", 1, "id1") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1) }, + new("value2", 1, "id2") { EdgeAttribute = new EdgeAttribute("SourceAcount", 1) } } }, - new EdgeAttribute("DestiantionAccount", 2) + new("DestiantionAccount", 2) { EdgeValues = new List { - new EdgeValue("value3", 2, "id1") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1)}, - new EdgeValue("value3", 2, "id2") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1)}, + new("value3", 2, "id1") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1) }, + new("value3", 2, "id2") { EdgeAttribute = new EdgeAttribute("DestiantionAccount", 1) } } } } @@ -127,14 +120,14 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie { VertexAttributes = new List { - new VertexAttribute("CardID", 1) + new("CardID", 1) { VertexValues = new List { - new VertexValue("value1", 1, "id2"){ VertexAttribute = new VertexAttribute("CardID", 1)}, - new VertexValue("value3", 1, "id3") { VertexAttribute = new VertexAttribute("CardID", 1)}, - new VertexValue("value2", 1, "id4") { VertexAttribute = new VertexAttribute("CardID", 1)}, - new VertexValue("value3", 1, "id5") { VertexAttribute = new VertexAttribute("CardID", 1)} + new("value1", 1, "id2") { VertexAttribute = new VertexAttribute("CardID", 1) }, + new("value3", 1, "id3") { VertexAttribute = new VertexAttribute("CardID", 1) }, + new("value2", 1, "id4") { VertexAttribute = new VertexAttribute("CardID", 1) }, + new("value3", 1, "id5") { VertexAttribute = new VertexAttribute("CardID", 1) } } } } @@ -144,7 +137,7 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie _dataContext.DataSets.Add(dataset); _dataContext.SaveChanges(); - + // Act var actual = _sut.GetAllEdges(datasetName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs index 362c73a..0b373eb 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs @@ -33,11 +33,13 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN var expectedVertex = new List() { - new Vertex(){ + new() + { Id = "id1", Value = "value1" }, - new Vertex(){ + new() + { Id = "id2", Value = "value2" } @@ -45,7 +47,8 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN var expectedEdge = new List() { - new Edge(){ + new() + { Id = "id1", Source = "id1", Target = "id2" @@ -57,11 +60,11 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN _vertexService.GetAllVertices(datasetName, vertexIdentifierFieldName).Returns(expectedVertex); _edgeService.GetAllEdges(datasetName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName).Returns(expectedEdge); - + // Act var actual = _sut.GetGraph(datasetName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, vertexIdentifierFieldName); - + // Assert Assert.Equivalent(expected, actual); } diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs index aa4ba46..c12dc55 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs @@ -41,22 +41,16 @@ public void GetVertexDetails_ReturnsCorrectDetails() att1.Id = 1; att2.Id = 2; - List att = new List() { att1, att2 }; + List att = new() { att1, att2 }; - foreach (var attribute in att) - { - mockContext.Add(attribute); - } + foreach (var attribute in att) mockContext.Add(attribute); var val1 = new VertexValue("val1", 1, objectId2); var val2 = new VertexValue("val2", 1, objectId1); var val3 = new VertexValue("val3", 2, objectId1); var val4 = new VertexValue("val4", 2, objectId2); - List vertexValues = new List() { val1, val2, val3, val4 }; - foreach (var value in vertexValues) - { - mockContext.Add(value); - } + List vertexValues = new() { val1, val2, val3, val4 }; + foreach (var value in vertexValues) mockContext.Add(value); mockContext.SaveChanges(); var expected = new Dictionary(); @@ -67,7 +61,7 @@ public void GetVertexDetails_ReturnsCorrectDetails() //assert Assert.Equal(result.AttributeValue, expected); } - + [Fact] public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() { @@ -75,8 +69,8 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() var mockContext = scope.ServiceProvider.GetRequiredService(); // Arrange - string datasetName = "DataSet1"; - string vertexIdentifierFieldName = "CardID"; + var datasetName = "DataSet1"; + var vertexIdentifierFieldName = "CardID"; var dataset = new DataGroup(datasetName, 1) { @@ -84,12 +78,12 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() { VertexAttributes = new List { - new VertexAttribute("CardID", 1) + new("CardID", 1) { VertexValues = new List { - new VertexValue("value1", 1, "id1"){ VertexAttribute = new VertexAttribute("CardID", 1)}, - new VertexValue("value2", 1, "id2") { VertexAttribute = new VertexAttribute("CardID", 1)} + new("value1", 1, "id1") { VertexAttribute = new VertexAttribute("CardID", 1) }, + new("value2", 1, "id2") { VertexAttribute = new VertexAttribute("CardID", 1) } } } } @@ -98,21 +92,21 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() mockContext.DataSets.Add(dataset); mockContext.SaveChanges(); - - List expected = new List() + + List expected = new() { - new Vertex() + new() { Id = "id1", Value = "value1" - }, - new Vertex() + }, + new() { Id = "id2", Value = "value2" } }; - + // Act var actual = _sut.GetAllVertices(datasetName, vertexIdentifierFieldName); @@ -120,5 +114,4 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() // Assert Assert.Equivalent(expected, actual); } - } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj b/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj index 591ffad..01d4505 100644 --- a/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj +++ b/mohaymen-codestar-Team02_XUnitTest/mohaymen-codestar-Team02_XUnitTest.csproj @@ -11,25 +11,25 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + - + - + diff --git a/task.txt b/task.txt new file mode 100644 index 0000000..d9039f9 --- /dev/null +++ b/task.txt @@ -0,0 +1,7 @@ +save data 1 +send graph 2 +show list valid data 3 +get target graph 3 +vertex detail 3 +edge detail 3 +