From f44d1a7a016231ffc0a0d7c23cae015733466dbd Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Wed, 28 Aug 2024 05:21:34 -0700 Subject: [PATCH 01/10] feat: search and filter added --- .../Controllers/DataAdminController.cs | 9 +- mohaymen-codestar-Team02/Models/Edge.cs | 4 +- .../DataAdminService/DataAdminService.cs | 11 +- .../DataAdminService/IDataAdminService.cs | 2 +- .../Services/EdgeService.cs | 127 ++++++++-- .../Services/GraphService.cs | 227 +++++++++++++++++- .../Services/IEdgeService.cs | 4 +- .../Services/IGraphService.cs | 8 +- .../Services/IVertexService.cs | 2 +- .../Services/VertexService.cs | 57 ++++- .../Servies/EdgeServiceTest.cs | 110 ++++++--- .../Servies/GraphServiceTest.cs | 96 ++++++-- .../Servies/VertexServiceTest.cs | 49 ++-- 13 files changed, 583 insertions(+), 123 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index dfd36fc..bcb9046 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -50,14 +50,13 @@ public IActionResult GetDataSetsList() } [HttpGet("DataSets/{dataSetId}")] - public async Task DisplayDataSetAsGraph(long dataSetId, [FromQuery] string vertexIdentifier, - [FromQuery] string sourceIdentifier, [FromQuery] string targetIdentifier) + public async Task DisplayDataSetAsGraph([FromQuery]GraphQueryInfoDto graphQueryInfoDto, [FromQuery] Dictionary vertexAttributeValues, [FromQuery] Dictionary edgeAttributeValues) { //Todo all Of Them ServiceResponse response = - await _dataAdminService.DisplayGeraphData(dataSetId, sourceIdentifier, - targetIdentifier, vertexIdentifier); - response.Data.GraphId = dataSetId; + await _dataAdminService.DisplayGeraphData(graphQueryInfoDto.datasetId, graphQueryInfoDto.sourceIdentifier, + graphQueryInfoDto.targetIdentifier, graphQueryInfoDto.vertexIdentifier, vertexAttributeValues, edgeAttributeValues); + response.Data.GraphId = graphQueryInfoDto.datasetId; return StatusCode((int)response.Type, response); } diff --git a/mohaymen-codestar-Team02/Models/Edge.cs b/mohaymen-codestar-Team02/Models/Edge.cs index f12d88d..d313a7a 100644 --- a/mohaymen-codestar-Team02/Models/Edge.cs +++ b/mohaymen-codestar-Team02/Models/Edge.cs @@ -5,6 +5,6 @@ namespace mohaymen_codestar_Team02.Models; public class Edge : IEdge { public string? Id { get; init; } - public string? Source { get; init; } - public string? Target { get; init; } + public string? Source { get; set; } + public string? Target { 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 5e0f309..2249a8d 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -93,13 +93,14 @@ public ServiceResponse> DisplayDataSet() return new ServiceResponse>(dataGroupDtos, ApiResponseType.Success, ""); } - public async Task> DisplayGeraphData(long databaseName, + public async Task> DisplayGeraphData(long databaseId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeVales) { - var graph = _graphService.GetGraph(databaseName, sourceEdgeIdentifierFieldName, - destinationEdgeIdentifierFieldName, - vertexIdentifierFieldName); + var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, vertexAttributeVales); + var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, edgeAttributeVales); + var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName); var dto = new DisplayGraphDto() { diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs index 370f4f8..b0a3161 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/IDataAdminService.cs @@ -12,7 +12,7 @@ Task> StoreData(string? edgeFile, string? vertexFile, st ServiceResponse> DisplayDataSet(); Task> DisplayGeraphData(long dataSetId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeVales); ServiceResponse GetVertexDetail(string objectId); ServiceResponse GetEdgeDetail(string objectId); diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs index c196544..50cdfbc 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Xml.Schema; using AutoMapper; using Microsoft.EntityFrameworkCore; using mohaymen_codestar_Team02.Data; @@ -21,8 +22,7 @@ public EdgeService(IServiceProvider serviceProvider, IMapper mapper) _serviceProvider = serviceProvider; _mapper = mapper; } - - + public List GetEdgeAttributes(long edgeEntityId) { var scope = _serviceProvider.CreateScope(); @@ -35,30 +35,111 @@ public List GetEdgeAttributes(long edgeEntityId) return edgeAttribuite.Select(va => _mapper.Map(va)).ToList(); } - public List GetAllEdges(long dataSetId, string vertexIdentifierFieldName, + public Dictionary> GetAllEdges(long dataSetId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName) + string destinationEdgeIdentifierFieldName, Dictionary edgeAttributeVales) { var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - var vertexSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.VertexEntity) - .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).FirstOrDefault(ds => ds != null); + //var vertexSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.VertexEntity) + // .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).FirstOrDefault(ds => ds != null); var edgeSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.EdgeEntity) .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds != null);; - var vertexRecords = vertexSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) - .GroupBy(v => v.ObjectId); + //var vertexRecords = vertexSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) + // .GroupBy(v => v.ObjectId); var edgeRecords = edgeSet.EdgeEntity.EdgeAttributes.Select(ea => ea.EdgeValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); + var validEdgeRecords = edgeRecords + .Where(group => + edgeAttributeVales.All(attr => + group.Any(v => v.EdgeAttribute.Name == attr.Key && v.StringValue == attr.Value))); + + //var res = validEdgeRecords.Select(x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)).ToList(); + + var res = validEdgeRecords.ToDictionary(x => x.Key, + x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)); + return res; + + var edges = validEdgeRecords + .Select(group => + { + var sourceValue = group.Where(v => v.EdgeAttribute.Name == sourceEdgeIdentifierFieldName) + .Select(v => v.StringValue).FirstOrDefault(); + + var targeValue = group.Where(v => v.EdgeAttribute.Name == destinationEdgeIdentifierFieldName) + .Select(v => v.StringValue).FirstOrDefault(); + + return new Edge() + { + Id = group.Key, + Source = sourceValue, + Target = targeValue + }; + }) + .ToList(); + + /* + var dic = record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue); + if (vertexAttributeVales.Where(x => x.Value == dic[x.Key]).Count()==vertexAttributeVales.Count) + { + break; + } + + + foreach (var rec in vertexRecords) + { + bool b = true; + foreach (var vav in vertexAttributeVales) + { + foreach (var item in rec) + { + if(vav.Value==item.StringValue) + + } + } + } + + var vertexRecordsDic = vertexSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) + .GroupBy(v => v.ObjectId).Select(g=>g.GetEnumerator().Current); + + var validVertexRecords = vertexRecordsDic.Where(dic => + vertexAttributeVales.Where(x => x.Value == dic[x.Key]).Count() == vertexAttributeVales.Count); + */ + + /* + var validVertexRecords = new List>(); + foreach (var record in vertexRecords) + { + var dic = record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue); + if (vertexAttributeVales.Where(x => x.Value == dic[x.Key]).Count()==vertexAttributeVales.Count) + { + validVertexRecords.Add(record); + } + } + */ + /* + var validVertexRecords = vertexRecords + .Where(record => + vertexAttributeVales.All(attributeValue => + record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue) + .ContainsKey(attributeValue.Key) && + record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue)[attributeValue.Key] == attributeValue.Value)) + .ToList(); + */ + + /* + var dicList = vertices.GroupBy(x => x.Label).ToDictionary(x=>x.Key, x=>x.ToList()); + List edges = new List(); foreach (var record in edgeRecords) { GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, out var sourceValue, out var destinationValue); - GetSourcesAndDestinations(vertexIdentifierFieldName, vertexRecords, sourceValue, destinationValue, + GetSourcesAndDestinations(dicList, sourceValue, destinationValue, out var sources, out var destinations); foreach (var source in sources) @@ -75,17 +156,32 @@ public List GetAllEdges(long dataSetId, string vertexIdentifierFieldName, } } } - - return edges; +*/ + //return edges; } - private void GetSourcesAndDestinations(string vertexIdentifierFieldName, - IEnumerable> vertexRecords, + private void GetSourcesAndDestinations(Dictionary> vertxAttValues, string sourceValue, string destinationValue, out List sources, out List destinations) { - sources = new List(); - destinations = new List(); + //sources = new List(); + //destinations = new List(); + sources = vertxAttValues[sourceValue]; + destinations = vertxAttValues[destinationValue]; + /* + foreach (var v in vertices) + { + if (v.Label == sourceValue) + { + sources.Add(v); + } + if (v.Label == destinationValue) + { + destinations.Add(v); + } + }*/ + + /* foreach (var record1 in vertexRecords) { foreach (var item in record1) @@ -109,6 +205,7 @@ private void GetSourcesAndDestinations(string vertexIdentifierFieldName, } } } + */ } private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName, diff --git a/mohaymen-codestar-Team02/Services/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService.cs index 11ee6f9..61e9ac6 100644 --- a/mohaymen-codestar-Team02/Services/GraphService.cs +++ b/mohaymen-codestar-Team02/Services/GraphService.cs @@ -1,4 +1,8 @@ +using System.Linq; +using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.EdgeEAV; +using mohaymen_codestar_Team02.Models.VertexEAV; using QuikGraph; namespace mohaymen_codestar_Team02.Services; @@ -13,13 +17,224 @@ public GraphService(IVertexService vertexService, IEdgeService edgeService) _vertexService = vertexService; _edgeService = edgeService; } + + private void GetSourcesAndDestinations(Dictionary> vertxAttValues, + string sourceValue, string destinationValue, out List sources, out List destinations) + { + //sources = new List(); + //destinations = new List(); + + sources = vertxAttValues[sourceValue]; + destinations = vertxAttValues[destinationValue]; + /* + foreach (var v in vertices) + { + if (v.Label == sourceValue) + { + sources.Add(v); + } + if (v.Label == destinationValue) + { + destinations.Add(v); + } + }*/ + + /* + 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 (List vertices, List edges) GetGraph(Dictionary> vertices, + Dictionary> edges, string vertexIdentifierFieldName, + string SourceIdentifierFieldName, string TargetIdentifierFieldName) + { + List resEdges = new List(); + + var dicVertices = vertices.GroupBy(x => x.Value[vertexIdentifierFieldName]) + .ToDictionary(x => x.Key, x => x.ToList()); + + /* + List resVertices = new List(); + + foreach (var record in vertices) + { + var newVertex = new Vertex() + { + Id = record.Key, + Label = record.Value[vertexIdentifierFieldName] + }; + resVertices.Add(newVertex); + }*/ + var resVertices = vertices + .Select(record => new Vertex + { + Id = record.Key, + Label = record.Value[vertexIdentifierFieldName] + }) + .ToList(); + foreach (var edge in edges) + { + var sourceValue = edge.Value[SourceIdentifierFieldName]; + var targetValue = edge.Value[TargetIdentifierFieldName]; + + List>> sources; + if (!dicVertices.TryGetValue(sourceValue, out sources)) + { + continue; + } + List>> targets; + if (!dicVertices.TryGetValue(targetValue, out targets)) + { + continue; + } + + // var sources = dicVertices[sourceValue]; + // var targets = dicVertices[targetValue]; + + foreach (var source in sources) + { + foreach (var target in targets) + { + var newEdge = new Edge() + { + Id = edge.Key, + Source = source.Key, + Target = target.Key + }; + resEdges.Add(newEdge); + } + } + } + + return (resVertices, resEdges); + } + + /* + foreach (var edge in edges) + { + var sources = groupedVertices[edge["StringValue"]]; + var destinations = groupedVertices[edge["StringValue"]]; + foreach (var source in sources) + { + foreach (var des in destinations) + { + /* + Edge newEdge = new Edge() + { + Id = record.Key, + Source = source.Id, + Target = des.Id + }; + edge.Source = source.Id; + edge.Target = des.Id; + res.Add(edge); + } + } + + }*/ + /* + foreach (var edge in edges) + { + var sources = dicList[edge.Source]; + var destinations = dicList[edge.Target]; + + + //return sources.SelectMany(source => destinations.Select(des => edge)).ToList(); + + foreach (var source in sources) + { + foreach (var des in destinations) + { + /* + Edge newEdge = new Edge() + { + Id = record.Key, + Source = source.Id, + Target = des.Id + }; + edge.Source = source.Id; + edge.Target = des.Id; + res.Add(edge); + } + }*/ + /* + foreach (var record in edgeRecords) + { + GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, + out var sourceValue, out var destinationValue); + + GetSourcesAndDestinations(dicList, 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); + } + }*/ + + + /* public (List vertices, List edges) GetGraph(long dataSetID, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeValues) { - var vertices = _vertexService.GetAllVertices(dataSetID, vertexIdentifierFieldName); - var edges = _edgeService.GetAllEdges(dataSetID, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, - destinationEdgeIdentifierFieldName); + var vertices = _vertexService.GetAllVertices(dataSetID, vertexIdentifierFieldName, vertexAttributeVales); + var edges = _edgeService.GetAllEdges(dataSetID, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, edgeAttributeValues); + + + 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 f83e735..f727f34 100644 --- a/mohaymen-codestar-Team02/Services/IEdgeService.cs +++ b/mohaymen-codestar-Team02/Services/IEdgeService.cs @@ -7,9 +7,9 @@ namespace mohaymen_codestar_Team02.Services; public interface IEdgeService { - public List GetAllEdges(long dataSetId, string vertexIdentifierFieldName, + public Dictionary> GetAllEdges(long dataSetId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName); + string destinationEdgeIdentifierFieldName, Dictionary edgeAttributeVales); DetailDto GetEdgeDetails(string objId); public List GetEdgeAttributes(long edgeEntityId); diff --git a/mohaymen-codestar-Team02/Services/IGraphService.cs b/mohaymen-codestar-Team02/Services/IGraphService.cs index 069f0c6..b1046c2 100644 --- a/mohaymen-codestar-Team02/Services/IGraphService.cs +++ b/mohaymen-codestar-Team02/Services/IGraphService.cs @@ -5,7 +5,9 @@ namespace mohaymen_codestar_Team02.Services; public interface IGraphService { - (List vertices, List edges) GetGraph(long dataSetID, - string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); + + public (List vertices, List edges) GetGraph(Dictionary> vertices, + Dictionary> edges, string vertexIdentifierFieldName, + string SourceIdentifierFieldName, string TargetIdentifierFieldName); + } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/IVertexService.cs index 2e8bf3f..bdbc1da 100644 --- a/mohaymen-codestar-Team02/Services/IVertexService.cs +++ b/mohaymen-codestar-Team02/Services/IVertexService.cs @@ -6,7 +6,7 @@ namespace mohaymen_codestar_Team02.Services; public interface IVertexService { - public List GetAllVertices(long dataSetId, string vertexIdentifierFieldName); + public Dictionary> GetAllVertices(long dataSetId, string vertexIdentifierFieldName, Dictionary vertexAttributeVales); DetailDto GetVertexDetails(string objId); public List GetVertexAttributes(long vertexEntityId); diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index 26b0f53..e9e1e3c 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -5,6 +5,7 @@ using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.GraphDTO; using mohaymen_codestar_Team02.Models; +using mohaymen_codestar_Team02.Models.VertexEAV; namespace mohaymen_codestar_Team02.Services; @@ -18,7 +19,7 @@ public VertexService(IServiceProvider serviceProvider, IMapper mapper) _serviceProvider = serviceProvider; _mapper = mapper; } - + public List GetVertexAttributes(long vertexEntityId) { var scope = _serviceProvider.CreateScope(); @@ -31,20 +32,62 @@ public List GetVertexAttributes(long vertexEntityId) return vertexAttribuite.Select(va => _mapper.Map(va)).ToList(); } - public List GetAllVertices(long dataSetId, string vertexIdentifierFieldName) + public Dictionary> GetAllVertices(long dataSetId, string vertexIdentifierFieldName, Dictionary vertexAttributeVales) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); var dataSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.VertexEntity) .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues) - .FirstOrDefault(ds => ds != null); + .FirstOrDefault(); var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - List vertices = new List(); + /* + var validVertexRecords = new List>(); foreach (var record in vertexRecords) + { + var dic = record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue); + if (vertexAttributeVales.Where(x => x.Value == dic[x.Key]).Count()==vertexAttributeVales.Count) + { + validVertexRecords.Add(record); + } + }*/ + + var validVertexRecords = vertexRecords + .Where(group => + vertexAttributeVales.All(attr => + group.Any(v => v.VertexAttribute.Name == attr.Key && v.StringValue == attr.Value))); + + var res = validVertexRecords.ToDictionary(x => x.Key, + x => x.ToDictionary(g => g.VertexAttribute.Name, g => g.StringValue)); + + + //var dicList = vertices.GroupBy(x => x.Label).ToDictionary(x=>x.Key, x=>x.ToList()); + + //var result = validVertexRecords.Select(x => x.ToDictionary(g => g.VertexAttribute.Name, g => g.StringValue)).ToList(); + + /* + var vertices = validVertexRecords + .Select(group => + { + var value = group.Where(v => v.VertexAttribute.Name == vertexIdentifierFieldName) + .Select(v => v.StringValue).FirstOrDefault(); + + return new Vertex + { + Id = group.Key, + Label = value + }; + }) + .ToList(); +*/ + return res; + + /* + var vertices = new List(); + foreach (var record in validVertexRecords) { var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; Vertex v = new Vertex() @@ -52,10 +95,8 @@ public List GetAllVertices(long dataSetId, string vertexIdentifierFieldN Id = record.Key, Label = value }; - vertices.Add(v); - } - - return vertices; + vertices.Add(v); + }*/ } public DetailDto GetVertexDetails(string objId) diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs index 2abc390..62608d5 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs @@ -5,7 +5,6 @@ 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 NSubstitute; @@ -100,6 +99,7 @@ public void GetEdgeAttribute_ShouldReturnAllAttributes_WhenGivenCorrectEdgeId() var dataset = new DataGroup("Dataset1", 1) { + DataGroupId = 1, EdgeEntity = new EdgeEntity("Transaction", 1) { EdgeAttributes = new List @@ -147,25 +147,18 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie var contex = scope.ServiceProvider.GetRequiredService(); // Arrange - string datasetName = "DataSet1"; + long datasetId = 1; + string attName1 = "SourceAcount"; + string attName2 = "DestiantionAccount"; + string attName3 = "RandomAtt"; string vertexIdentifierFieldName = "CardID"; - string sourceEdgeIdentifierFieldName = "SourceAcount"; - string destinationEdgeIdentifierFieldName = "DestiantionAccount"; + string sourceEdgeIdentifierFieldName = attName1; + string destinationEdgeIdentifierFieldName = attName2; - var expected = new List() + var attValue = new Dictionary() { - new Edge() - { - Id = "id1", - Source = "id2", - Target = "id3" - }, - new Edge() - { - Id = "id2", - Source = "id4", - Target = "id5" - } + {attName1, "val1"}, + {attName2, "val8"} }; var dataset = new DataGroup("Dataset1", 1) @@ -174,50 +167,87 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie { EdgeAttributes = new List { - new EdgeAttribute(sourceEdgeIdentifierFieldName, 1) + new EdgeAttribute(attName1, 1) { EdgeValues = new List { - new EdgeValue("val1", 1, "id1") { EdgeAttribute = new EdgeAttribute(sourceEdgeIdentifierFieldName, 1)}, - new EdgeValue("val2", 1, "id2") { EdgeAttribute = new EdgeAttribute(sourceEdgeIdentifierFieldName, 1)}, - + new EdgeValue("val1", 1, "id1"){ EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val1", 1, "id2") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val2", 1, "id3") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val2", 1, "id4") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val5", 1, "id5") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val1", 1, "id6") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val1", 1, "id7") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val5", 1, "id8") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val1", 1, "id9") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, + new EdgeValue("val3", 1, "id10") { EdgeAttribute = new EdgeAttribute(attName1, 1)} } - }, - new EdgeAttribute(destinationEdgeIdentifierFieldName, 2) + }, // 2, 6, 7 + new EdgeAttribute(attName2, 1) { EdgeValues = new List { - new EdgeValue("val3", 2, "id1") { EdgeAttribute = new EdgeAttribute(destinationEdgeIdentifierFieldName, 1)}, - new EdgeValue("val3", 2, "id2") { EdgeAttribute = new EdgeAttribute(destinationEdgeIdentifierFieldName, 1)}, + new EdgeValue("val7", 2, "id1"){ EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val8", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val8", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, + new EdgeValue("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName2, 1)} } - } - } - }, - VertexEntity = new VertexEntity("Account", 1) - { - VertexAttributes = new List - { - new VertexAttribute(vertexIdentifierFieldName, 1) + }, + new EdgeAttribute(attName3, 1) { - VertexValues = new List + EdgeValues = new List { - new VertexValue("val1", 1, "id2"){ VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)}, - new VertexValue("val3", 1, "id3") { VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)}, - new VertexValue("val2", 1, "id4") { VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)}, - new VertexValue("val3", 1, "id5") { VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)} + new EdgeValue("val7", 2, "id1"){ EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val11", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val18", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, + new EdgeValue("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName3, 1)} } } } } }; + var expected = new Dictionary>() + { + {"id2", new Dictionary() + { + {attName1, "val1"}, + {attName2, "val8"}, + {attName3, "val11"} + }}, + {"id6", new Dictionary() + { + {attName1, "val1"}, + {attName2, "val8"}, + {attName3, "val8"} + }}, + {"id7", new Dictionary() + { + {attName1, "val1"}, + {attName2, "val8"}, + {attName3, "val18"} + }} + }; + contex.DataSets.Add(dataset); contex.SaveChanges(); // Act - var actual = _sut.GetAllEdges(datasetName, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, - destinationEdgeIdentifierFieldName); + var actual = _sut.GetAllEdges(datasetId, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, attValue); // Assert Assert.Equivalent(expected, actual); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs index 3f826fd..5461415 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs @@ -21,49 +21,113 @@ public GraphServiceTest() _edgeService = Substitute.For(); _sut = new GraphService(_vertexService, _edgeService); } - + [Fact] public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetNameAndIdentifiers() { // Arrange - var datasetName = "datasetName1"; - var sourceEdgeIdentifierFieldName = "AccountID"; - var destinationEdgeIdentifierFieldName = "SourceAcount"; - var vertexIdentifierFieldName = "DestiantionAccount"; + long datasetId = 1; + string vertexAttName1 = "VertexAttName1"; + string vertexAttName2 = "VertexAttName2"; + string edgeAttName1 = "EdgeAttName1"; + string edgeAttName2 = "EdgeAttName2"; + string edgeAttName3 = "EdgeAttName3"; + var SourceIdentifierFieldName = edgeAttName1; + var TargetIdentifierFieldName = edgeAttName2; + var vertexIdentifierFieldName = vertexAttName1; + + var vertexAttributeValues = new Dictionary>() + { + {"id1", new Dictionary() + { + {vertexAttName1, "val1"}, + {vertexAttName2, "val2"}, + }}, + {"id2", new Dictionary() + { + {vertexAttName1, "val1"}, + {vertexAttName2, "val3"}, + }}, + {"id3", new Dictionary() + { + {vertexAttName1, "val2"}, + {vertexAttName2, "val2"}, + }} + }; + + var edgeAttributeValues = new Dictionary>() + { + {"id1", new Dictionary() + { + {edgeAttName1, "val1"}, // s= 1, 2 d= 3 + {edgeAttName2, "val2"}, + {edgeAttName3, "val8"} + }}, + {"id2", new Dictionary() + { + {edgeAttName1, "val2"}, // + {edgeAttName2, "val4"}, + {edgeAttName3, "val8"} + }}, + {"id3", new Dictionary() + { + {edgeAttName1, "val2"}, // s= 3 d= 1, 2 + {edgeAttName2, "val1"}, + {edgeAttName3, "val8"} + }} + }; var expectedVertex = new List() { new() { Id = "id1", - Label = "value1" + Label = "val1" }, new() { Id = "id2", - Label = "value2" + Label = "val1" + }, + new() + { + Id = "id3", + Label = "val2" } }; - + var expectedEdge = new List() { new() { Id = "id1", Source = "id1", + Target = "id3" + }, + new() + { + Id = "id1", + Source = "id2", + Target = "id3" + }, + new() + { + Id = "id3", + Source = "id3", + Target = "id1" + }, + new() + { + Id = "id3", + Source = "id3", Target = "id2" } }; - + 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 actual = _sut.GetGraph(vertexAttributeValues, edgeAttributeValues, vertexIdentifierFieldName, SourceIdentifierFieldName, TargetIdentifierFieldName); // Assert Assert.Equivalent(expected, actual); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs index 4fbfa76..77701c1 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs @@ -146,21 +146,32 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() var mockContext = scope.ServiceProvider.GetRequiredService(); // Arrange - string datasetName = "DataSet1"; - string vertexIdentifierFieldName = "CardID"; + long datasetId = 1; + string attName1 = "AttName1"; + string attName2 = "AttName2"; + string vertexIdentifierFieldName = attName1; - var dataset = new DataGroup(datasetName, 1) + var dataset = new DataGroup("DatasetName1", 1) { + DataGroupId = 1, VertexEntity = new VertexEntity("Account", 1) { VertexAttributes = new List { - new VertexAttribute(vertexIdentifierFieldName, 1) + new VertexAttribute(attName1, 1) { VertexValues = new List { - new VertexValue("val1", 1, "id1"){ VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)}, - new VertexValue("val2", 1, "id2") { VertexAttribute = new VertexAttribute(vertexIdentifierFieldName, 1)} + new VertexValue("val1", 1, "id1"){ VertexAttribute = new VertexAttribute(attName1, 1)}, + new VertexValue("val2", 1, "id2") { VertexAttribute = new VertexAttribute(attName1, 1)} + } + }, + new VertexAttribute(attName2, 1) + { + VertexValues = new List + { + new VertexValue("val3", 2, "id1"){ VertexAttribute = new VertexAttribute(attName2, 1)}, + new VertexValue("val4", 2, "id2") { VertexAttribute = new VertexAttribute(attName2, 1)} } } } @@ -169,24 +180,24 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() mockContext.DataSets.Add(dataset); mockContext.SaveChanges(); - - List expected = new List() + + Dictionary> expected = new Dictionary>() { - new Vertex() + {"id1", new Dictionary() { - Id = "id1", - Label = "val1" - }, - new Vertex() - { - Id = "id2", - Label = "val2" - } + {attName1, "val1"}, + {attName2, "val3"} + }} + }; + + var attValue = new Dictionary() + { + {attName1, "val1"}, + //{attName2, "val3"}, }; - // Act - var actual = _sut.GetAllVertices(datasetName, vertexIdentifierFieldName); + var actual = _sut.GetAllVertices(datasetId, vertexIdentifierFieldName, attValue); // Assert Assert.Equivalent(expected, actual); From 51be66e4f470e2265b844ad594086a8ce42b443c Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Wed, 28 Aug 2024 05:23:29 -0700 Subject: [PATCH 02/10] refactor: commented codes removed --- .../Services/EdgeService.cs | 8 +- .../Services/GraphService.cs | 101 +----------------- .../Services/VertexService.cs | 44 -------- 3 files changed, 2 insertions(+), 151 deletions(-) diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService.cs index 50cdfbc..d1edbcc 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService.cs @@ -41,14 +41,10 @@ public Dictionary> GetAllEdges(long dataSetId { var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - //var vertexSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.VertexEntity) - // .ThenInclude(ve => ve.VertexAttributes).ThenInclude(vv => vv.VertexValues).FirstOrDefault(ds => ds != null); + var edgeSet = context.DataSets.Where(ds => ds.DataGroupId == dataSetId).Include(ds => ds.EdgeEntity) .ThenInclude(ee => ee.EdgeAttributes).ThenInclude(ev => ev.EdgeValues).FirstOrDefault(ds => ds != null);; - //var vertexRecords = vertexSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) - // .GroupBy(v => v.ObjectId); - var edgeRecords = edgeSet.EdgeEntity.EdgeAttributes.Select(ea => ea.EdgeValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); @@ -57,8 +53,6 @@ public Dictionary> GetAllEdges(long dataSetId edgeAttributeVales.All(attr => group.Any(v => v.EdgeAttribute.Name == attr.Key && v.StringValue == attr.Value))); - //var res = validEdgeRecords.Select(x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)).ToList(); - var res = validEdgeRecords.ToDictionary(x => x.Key, x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)); return res; diff --git a/mohaymen-codestar-Team02/Services/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService.cs index 61e9ac6..079742d 100644 --- a/mohaymen-codestar-Team02/Services/GraphService.cs +++ b/mohaymen-codestar-Team02/Services/GraphService.cs @@ -95,19 +95,7 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName var dicVertices = vertices.GroupBy(x => x.Value[vertexIdentifierFieldName]) .ToDictionary(x => x.Key, x => x.ToList()); - - /* - List resVertices = new List(); - - foreach (var record in vertices) - { - var newVertex = new Vertex() - { - Id = record.Key, - Label = record.Value[vertexIdentifierFieldName] - }; - resVertices.Add(newVertex); - }*/ + var resVertices = vertices .Select(record => new Vertex { @@ -132,9 +120,6 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName continue; } - // var sources = dicVertices[sourceValue]; - // var targets = dicVertices[targetValue]; - foreach (var source in sources) { foreach (var target in targets) @@ -152,89 +137,5 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName return (resVertices, resEdges); } - - /* - foreach (var edge in edges) - { - var sources = groupedVertices[edge["StringValue"]]; - var destinations = groupedVertices[edge["StringValue"]]; - foreach (var source in sources) - { - foreach (var des in destinations) - { - /* - Edge newEdge = new Edge() - { - Id = record.Key, - Source = source.Id, - Target = des.Id - }; - edge.Source = source.Id; - edge.Target = des.Id; - res.Add(edge); - } - } - - }*/ - /* - foreach (var edge in edges) - { - var sources = dicList[edge.Source]; - var destinations = dicList[edge.Target]; - - - //return sources.SelectMany(source => destinations.Select(des => edge)).ToList(); - - foreach (var source in sources) - { - foreach (var des in destinations) - { - /* - Edge newEdge = new Edge() - { - Id = record.Key, - Source = source.Id, - Target = des.Id - }; - edge.Source = source.Id; - edge.Target = des.Id; - res.Add(edge); - } - }*/ - /* - foreach (var record in edgeRecords) - { - GetSourceAndDerstinationValues(sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, record, - out var sourceValue, out var destinationValue); - GetSourcesAndDestinations(dicList, 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); - } - }*/ - - - /* - public (List vertices, List edges) GetGraph(long dataSetID, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeValues) - { - var vertices = _vertexService.GetAllVertices(dataSetID, vertexIdentifierFieldName, vertexAttributeVales); - var edges = _edgeService.GetAllEdges(dataSetID, sourceEdgeIdentifierFieldName, - destinationEdgeIdentifierFieldName, edgeAttributeValues); - - - - return (vertices, edges); - }*/ } diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService.cs index e9e1e3c..2a904ba 100644 --- a/mohaymen-codestar-Team02/Services/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService.cs @@ -43,17 +43,6 @@ public Dictionary> GetAllVertices(long dataSe var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - - /* - var validVertexRecords = new List>(); - foreach (var record in vertexRecords) - { - var dic = record.ToDictionary(x => x.VertexAttribute.Name, x => x.StringValue); - if (vertexAttributeVales.Where(x => x.Value == dic[x.Key]).Count()==vertexAttributeVales.Count) - { - validVertexRecords.Add(record); - } - }*/ var validVertexRecords = vertexRecords .Where(group => @@ -62,41 +51,8 @@ public Dictionary> GetAllVertices(long dataSe var res = validVertexRecords.ToDictionary(x => x.Key, x => x.ToDictionary(g => g.VertexAttribute.Name, g => g.StringValue)); - - //var dicList = vertices.GroupBy(x => x.Label).ToDictionary(x=>x.Key, x=>x.ToList()); - - //var result = validVertexRecords.Select(x => x.ToDictionary(g => g.VertexAttribute.Name, g => g.StringValue)).ToList(); - - /* - var vertices = validVertexRecords - .Select(group => - { - var value = group.Where(v => v.VertexAttribute.Name == vertexIdentifierFieldName) - .Select(v => v.StringValue).FirstOrDefault(); - - return new Vertex - { - Id = group.Key, - Label = value - }; - }) - .ToList(); -*/ return res; - - /* - var vertices = new List(); - foreach (var record in validVertexRecords) - { - var value = record.SingleOrDefault(r => r.VertexAttribute.Name == vertexIdentifierFieldName).StringValue; - Vertex v = new Vertex() - { - Id = record.Key, - Label = value - }; - vertices.Add(v); - }*/ } public DetailDto GetVertexDetails(string objId) From 4642bc4d8df30553b26d32bfcff08c781c1bbd5d Mon Sep 17 00:00:00 2001 From: Ftm-Sayadzadeh Date: Wed, 28 Aug 2024 22:30:57 +0430 Subject: [PATCH 03/10] refactor: just changed dir --- .../Services/{ => EdgeService/Abstraction}/IEdgeService.cs | 0 .../Services/{ => EdgeService}/EdgeService.cs | 0 .../Services/{ => GraphService/Abstraction}/IGraphService.cs | 0 .../Services/{ => GraphService}/GraphService.cs | 0 .../Services/{ => VertexService/Abstraction}/IVertexService.cs | 0 .../Services/{ => VertexService}/VertexService.cs | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename mohaymen-codestar-Team02/Services/{ => EdgeService/Abstraction}/IEdgeService.cs (100%) rename mohaymen-codestar-Team02/Services/{ => EdgeService}/EdgeService.cs (100%) rename mohaymen-codestar-Team02/Services/{ => GraphService/Abstraction}/IGraphService.cs (100%) rename mohaymen-codestar-Team02/Services/{ => GraphService}/GraphService.cs (100%) rename mohaymen-codestar-Team02/Services/{ => VertexService/Abstraction}/IVertexService.cs (100%) rename mohaymen-codestar-Team02/Services/{ => VertexService}/VertexService.cs (100%) diff --git a/mohaymen-codestar-Team02/Services/IEdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService/Abstraction/IEdgeService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/IEdgeService.cs rename to mohaymen-codestar-Team02/Services/EdgeService/Abstraction/IEdgeService.cs diff --git a/mohaymen-codestar-Team02/Services/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/EdgeService.cs rename to mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs diff --git a/mohaymen-codestar-Team02/Services/IGraphService.cs b/mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/IGraphService.cs rename to mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs diff --git a/mohaymen-codestar-Team02/Services/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService/GraphService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/GraphService.cs rename to mohaymen-codestar-Team02/Services/GraphService/GraphService.cs diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/IVertexService.cs rename to mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs diff --git a/mohaymen-codestar-Team02/Services/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService/VertexService.cs similarity index 100% rename from mohaymen-codestar-Team02/Services/VertexService.cs rename to mohaymen-codestar-Team02/Services/VertexService/VertexService.cs From dc04e436d2e9b00d0e2528940e415a98cec9bfa8 Mon Sep 17 00:00:00 2001 From: Ftm-Sayadzadeh Date: Fri, 30 Aug 2024 15:17:23 +0430 Subject: [PATCH 04/10] feat: feat cors --- mohaymen-codestar-Team02/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mohaymen-codestar-Team02/Program.cs b/mohaymen-codestar-Team02/Program.cs index b00721c..d2859a8 100644 --- a/mohaymen-codestar-Team02/Program.cs +++ b/mohaymen-codestar-Team02/Program.cs @@ -10,7 +10,7 @@ options.AddPolicy("AllowSpecificOrigins", builder => { - builder.WithOrigins("http://localhost:4200") + builder.WithOrigins("http://localhost:4200" , "https://codestar-g2.abriment.com/") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); From 4a5cf33f4a1fb08a618fd9d6232a66c4fcd82e7a Mon Sep 17 00:00:00 2001 From: Ftm-Sayadzadeh Date: Fri, 30 Aug 2024 15:48:39 +0430 Subject: [PATCH 05/10] refactor: just refactor --- .../Controllers/DataAdminController.cs | 7 ++- mohaymen-codestar-Team02/Program.cs | 2 +- .../Services/AnalystService/AnalystService.cs | 4 +- .../Abstraction/IDataAdminService.cs | 3 +- .../DataAdminService/DataAdminService.cs | 6 ++- .../Services/EdgeService/EdgeService.cs | 6 +-- .../GraphService/Abstraction/IGraphService.cs | 2 - .../Services/GraphService/GraphService.cs | 47 +++++++------------ .../Abstraction/IVertexService.cs | 4 +- .../Services/VertexService/VertexService.cs | 11 +++-- .../{ => EdgeServiceTest}/EdgeServiceTest.cs | 0 .../GraphServiceTest.cs | 0 .../VertexServiceTest.cs | 0 13 files changed, 42 insertions(+), 50 deletions(-) rename mohaymen-codestar-Team02_XUnitTest/Servies/{ => EdgeServiceTest}/EdgeServiceTest.cs (100%) rename mohaymen-codestar-Team02_XUnitTest/Servies/{ => GraphServiceTest}/GraphServiceTest.cs (100%) rename mohaymen-codestar-Team02_XUnitTest/Servies/{ => VertexServiceTest}/VertexServiceTest.cs (100%) diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 1ccc4e7..7b859fe 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -49,11 +49,14 @@ public IActionResult GetDataSetsList() } [HttpGet("DataSets/{dataSetId}")] - public async Task DisplayDataSetAsGraph([FromQuery]GraphQueryInfoDto graphQueryInfoDto, [FromQuery] Dictionary vertexAttributeValues, [FromQuery] Dictionary edgeAttributeValues) + public async Task DisplayDataSetAsGraph([FromQuery] GraphQueryInfoDto graphQueryInfoDto, + [FromQuery] Dictionary vertexAttributeValues, + [FromQuery] Dictionary edgeAttributeValues) { ServiceResponse response = await _dataAdminService.DisplayGeraphData(graphQueryInfoDto.datasetId, graphQueryInfoDto.sourceIdentifier, - graphQueryInfoDto.targetIdentifier, graphQueryInfoDto.vertexIdentifier, vertexAttributeValues, edgeAttributeValues); + graphQueryInfoDto.targetIdentifier, graphQueryInfoDto.vertexIdentifier, vertexAttributeValues, + edgeAttributeValues); response.Data.GraphId = graphQueryInfoDto.datasetId; return StatusCode((int)response.Type, response); } diff --git a/mohaymen-codestar-Team02/Program.cs b/mohaymen-codestar-Team02/Program.cs index d2859a8..36d2da1 100644 --- a/mohaymen-codestar-Team02/Program.cs +++ b/mohaymen-codestar-Team02/Program.cs @@ -10,7 +10,7 @@ options.AddPolicy("AllowSpecificOrigins", builder => { - builder.WithOrigins("http://localhost:4200" , "https://codestar-g2.abriment.com/") + builder.WithOrigins("http://localhost:4200", "https://codestar-g2.abriment.com/") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); diff --git a/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs b/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs index 26908df..e1b70e2 100644 --- a/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs +++ b/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs @@ -130,7 +130,7 @@ public async Task> GetTheVertexNeighbor(GraphQu validVertexLabel.Add(source.StringValue); validVertexLabel.Add(target.StringValue); validEdges.Add(new Edge() - { Id = edgeValue.Id, Source = source.ObjectId, Target = target.ObjectId }); + { Id = edgeValue.Id, Source = source.ObjectId, Target = target.ObjectId }); } } } @@ -151,7 +151,7 @@ public async Task> GetTheVertexNeighbor(GraphQu Console.WriteLine("finish the creating of vertex"); var responseData = new DisplayGraphDto() - { GraphId = graphQueryInfoDto.datasetId, Edges = validEdges, Vertices = resultVertex }; + { GraphId = graphQueryInfoDto.datasetId, Edges = validEdges, Vertices = resultVertex }; time.Stop(); Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@ that take (" + time.ElapsedMilliseconds + ") milieSec to find the VertexNeighbor @@@@@@@@@@@@@@@@@@@@@@@@@@@@"); diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs index b0a3161..db9ccc2 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs @@ -12,7 +12,8 @@ Task> StoreData(string? edgeFile, string? vertexFile, st ServiceResponse> DisplayDataSet(); Task> DisplayGeraphData(long dataSetId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeVales); + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, + Dictionary vertexAttributeVales, Dictionary edgeAttributeVales); ServiceResponse GetVertexDetail(string objectId); ServiceResponse GetEdgeDetail(string objectId); diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs index 89b4ceb..d728172 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -95,12 +95,14 @@ public ServiceResponse> DisplayDataSet() public async Task> DisplayGeraphData(long databaseId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeVales, Dictionary edgeAttributeVales) + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, + Dictionary vertexAttributeVales, Dictionary edgeAttributeVales) { var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, vertexAttributeVales); var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName, edgeAttributeVales); - var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName); + var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName); var dto = new DisplayGraphDto() { diff --git a/mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs b/mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs index aad258d..57f0c2b 100644 --- a/mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs +++ b/mohaymen-codestar-Team02/Services/EdgeService/EdgeService.cs @@ -16,7 +16,7 @@ public EdgeService(IServiceProvider serviceProvider, IMapper mapper) _serviceProvider = serviceProvider; _mapper = mapper; } - + public List GetEdgeAttributes(long edgeEntityId) { var scope = _serviceProvider.CreateScope(); @@ -48,10 +48,10 @@ public Dictionary> GetAllEdges(long dataSetId group.Any(v => v.EdgeAttribute.Name == attr.Key && v.StringValue == attr.Value))); var res = validEdgeRecords.ToDictionary(x => x.Key, - x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)); + x => x.ToDictionary(g => g.EdgeAttribute.Name, g => g.StringValue)); return res; } - + public DetailDto GetEdgeDetails(string objId) { using var scope = _serviceProvider.CreateScope(); diff --git a/mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs b/mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs index b1046c2..19f3040 100644 --- a/mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs +++ b/mohaymen-codestar-Team02/Services/GraphService/Abstraction/IGraphService.cs @@ -5,9 +5,7 @@ namespace mohaymen_codestar_Team02.Services; public interface IGraphService { - public (List vertices, List edges) GetGraph(Dictionary> vertices, Dictionary> edges, string vertexIdentifierFieldName, string SourceIdentifierFieldName, string TargetIdentifierFieldName); - } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/GraphService/GraphService.cs b/mohaymen-codestar-Team02/Services/GraphService/GraphService.cs index 079742d..69a1574 100644 --- a/mohaymen-codestar-Team02/Services/GraphService/GraphService.cs +++ b/mohaymen-codestar-Team02/Services/GraphService/GraphService.cs @@ -17,7 +17,7 @@ public GraphService(IVertexService vertexService, IEdgeService edgeService) _vertexService = vertexService; _edgeService = edgeService; } - + private void GetSourcesAndDestinations(Dictionary> vertxAttValues, string sourceValue, string destinationValue, out List sources, out List destinations) { @@ -38,7 +38,7 @@ private void GetSourcesAndDestinations(Dictionary> vertxAtt destinations.Add(v); } }*/ - + /* foreach (var record1 in vertexRecords) { @@ -74,15 +74,9 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName 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; } } @@ -91,11 +85,11 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName Dictionary> edges, string vertexIdentifierFieldName, string SourceIdentifierFieldName, string TargetIdentifierFieldName) { - List resEdges = new List(); + var resEdges = new List(); var dicVertices = vertices.GroupBy(x => x.Value[vertexIdentifierFieldName]) .ToDictionary(x => x.Key, x => x.ToList()); - + var resVertices = vertices .Select(record => new Vertex { @@ -110,32 +104,23 @@ private void GetSourceAndDerstinationValues(string sourceEdgeIdentifierFieldName var targetValue = edge.Value[TargetIdentifierFieldName]; List>> sources; - if (!dicVertices.TryGetValue(sourceValue, out sources)) - { - continue; - } + if (!dicVertices.TryGetValue(sourceValue, out sources)) continue; List>> targets; - if (!dicVertices.TryGetValue(targetValue, out targets)) - { - continue; - } + if (!dicVertices.TryGetValue(targetValue, out targets)) continue; foreach (var source in sources) + foreach (var target in targets) { - foreach (var target in targets) + var newEdge = new Edge() { - var newEdge = new Edge() - { - Id = edge.Key, - Source = source.Key, - Target = target.Key - }; - resEdges.Add(newEdge); - } + Id = edge.Key, + Source = source.Key, + Target = target.Key + }; + resEdges.Add(newEdge); } } return (resVertices, resEdges); } - -} +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs b/mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs index 26d1406..903ed09 100644 --- a/mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService/Abstraction/IVertexService.cs @@ -6,7 +6,9 @@ namespace mohaymen_codestar_Team02.Services; public interface IVertexService { - public Dictionary> GetAllVertices(long dataSetId, string vertexIdentifierFieldName, Dictionary vertexAttributeVales); + public Dictionary> GetAllVertices(long dataSetId, + string vertexIdentifierFieldName, Dictionary vertexAttributeVales); + DetailDto GetVertexDetails(string objId); public List GetVertexAttributes(long vertexEntityId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/VertexService/VertexService.cs b/mohaymen-codestar-Team02/Services/VertexService/VertexService.cs index c3a34c3..d95952d 100644 --- a/mohaymen-codestar-Team02/Services/VertexService/VertexService.cs +++ b/mohaymen-codestar-Team02/Services/VertexService/VertexService.cs @@ -17,7 +17,7 @@ public VertexService(IServiceProvider serviceProvider, IMapper mapper) _serviceProvider = serviceProvider; _mapper = mapper; } - + public List GetVertexAttributes(long vertexEntityId) { var scope = _serviceProvider.CreateScope(); @@ -30,7 +30,8 @@ public List GetVertexAttributes(long vertexEntityId) return vertexAttribuite.Select(va => _mapper.Map(va)).ToList(); } - public Dictionary> GetAllVertices(long dataSetId, string vertexIdentifierFieldName, Dictionary vertexAttributeVales) + public Dictionary> GetAllVertices(long dataSetId, + string vertexIdentifierFieldName, Dictionary vertexAttributeVales) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -41,7 +42,7 @@ public Dictionary> GetAllVertices(long dataSe var vertexRecords = dataSet.VertexEntity.VertexAttributes.Select(a => a.VertexValues).SelectMany(v => v) .GroupBy(v => v.ObjectId); - + var validVertexRecords = vertexRecords .Where(group => vertexAttributeVales.All(attr => @@ -49,8 +50,8 @@ public Dictionary> GetAllVertices(long dataSe var res = validVertexRecords.ToDictionary(x => x.Key, x => x.ToDictionary(g => g.VertexAttribute.Name, g => g.StringValue)); - - return res; + + return res; } public DetailDto GetVertexDetails(string objId) diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest/EdgeServiceTest.cs similarity index 100% rename from mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest/EdgeServiceTest.cs diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest/GraphServiceTest.cs similarity index 100% rename from mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest/GraphServiceTest.cs diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest/VertexServiceTest.cs similarity index 100% rename from mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest/VertexServiceTest.cs From 4921fb957c61ed7ae317db99bda79223bdf6d391 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Wed, 4 Sep 2024 06:37:01 -0700 Subject: [PATCH 06/10] fix: some bug fixed on displaying graph --- .../Controllers/DataAdminController.cs | 15 +++++++-------- mohaymen-codestar-Team02/Dto/GetGraphDto.cs | 11 +++++++++++ .../Services/IVertexService.cs | 1 - 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 mohaymen-codestar-Team02/Dto/GetGraphDto.cs diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index 1ccc4e7..b99edf5 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -15,7 +15,7 @@ public class DataAdminController : ControllerBase { private readonly IDataAdminService _dataAdminService; private readonly IFileReader _fileReader; - + public DataAdminController(IDataAdminService dataAdminService, IFileReader fileReader) { @@ -48,23 +48,22 @@ public IActionResult GetDataSetsList() return StatusCode((int)response.Type, response); } - [HttpGet("DataSets/{dataSetId}")] - public async Task DisplayDataSetAsGraph([FromQuery]GraphQueryInfoDto graphQueryInfoDto, [FromQuery] Dictionary vertexAttributeValues, [FromQuery] Dictionary edgeAttributeValues) + [HttpPost("DataSets")] + public async Task DisplayDataSetAsGraph(GetGraphDto getGraphDto) { ServiceResponse response = - await _dataAdminService.DisplayGeraphData(graphQueryInfoDto.datasetId, graphQueryInfoDto.sourceIdentifier, - graphQueryInfoDto.targetIdentifier, graphQueryInfoDto.vertexIdentifier, vertexAttributeValues, edgeAttributeValues); - response.Data.GraphId = graphQueryInfoDto.datasetId; + await _dataAdminService.DisplayGeraphData(getGraphDto.datasetId, getGraphDto.sourceIdentifier, + getGraphDto.targetIdentifier, getGraphDto.vertexIdentifier, getGraphDto.vertexAttributeValues, getGraphDto.edgeAttributeValues); + response.Data.GraphId = getGraphDto.datasetId; return StatusCode((int)response.Type, response); } - [HttpGet("DataSets/Vertices/{objectId}")] public async Task DisplayVertexDetails(string objectId) { var respond = _dataAdminService.GetVertexDetail(objectId); return StatusCode((int)respond.Type, respond); - } + } [HttpGet("DataSets/Edges/{objectId}")] public async Task DisplayEdgeDetails(string objectId) diff --git a/mohaymen-codestar-Team02/Dto/GetGraphDto.cs b/mohaymen-codestar-Team02/Dto/GetGraphDto.cs new file mode 100644 index 0000000..45bc8b7 --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GetGraphDto.cs @@ -0,0 +1,11 @@ +namespace mohaymen_codestar_Team02.Dto; + +public class GetGraphDto +{ + public long datasetId { get; set; } + public string sourceIdentifier { get; set; } + public string targetIdentifier { get; set; } + public string vertexIdentifier { get; set; } + public Dictionary vertexAttributeValues { get; set; } + public Dictionary edgeAttributeValues { get; set; } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/IVertexService.cs b/mohaymen-codestar-Team02/Services/IVertexService.cs index 26d1406..8a69f3f 100644 --- a/mohaymen-codestar-Team02/Services/IVertexService.cs +++ b/mohaymen-codestar-Team02/Services/IVertexService.cs @@ -1,6 +1,5 @@ using mohaymen_codestar_Team02.Dto; using mohaymen_codestar_Team02.Dto.GraphDTO; -using mohaymen_codestar_Team02.Models; namespace mohaymen_codestar_Team02.Services; From 214dfabaf19a606d158fe6bdccf732da0e280083 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Fri, 6 Sep 2024 12:41:41 -0700 Subject: [PATCH 07/10] refactor: some refactor on DataAdminController.cs and AnalystController.cs --- .../Controllers/AnalystController.cs | 31 ++++++++++++++++++- .../Controllers/DataAdminController.cs | 24 +++----------- mohaymen-codestar-Team02/Dto/GetGraphDto.cs | 11 ------- .../Dto/GraphDTO/FilterGraphDto.cs | 11 +++++++ .../Dto/GraphDTO/GetGraphDto.cs | 9 ++++++ 5 files changed, 55 insertions(+), 31 deletions(-) delete mode 100644 mohaymen-codestar-Team02/Dto/GetGraphDto.cs create mode 100644 mohaymen-codestar-Team02/Dto/GraphDTO/FilterGraphDto.cs create mode 100644 mohaymen-codestar-Team02/Dto/GraphDTO/GetGraphDto.cs diff --git a/mohaymen-codestar-Team02/Controllers/AnalystController.cs b/mohaymen-codestar-Team02/Controllers/AnalystController.cs index 80247ed..f74ff1e 100644 --- a/mohaymen-codestar-Team02/Controllers/AnalystController.cs +++ b/mohaymen-codestar-Team02/Controllers/AnalystController.cs @@ -1,16 +1,21 @@ using Microsoft.AspNetCore.Mvc; using mohaymen_codestar_Team02.Dto; +using mohaymen_codestar_Team02.Dto.GraphDTO; +using mohaymen_codestar_Team02.Models; using mohaymen_codestar_Team02.Services.AnalystService; +using mohaymen_codestar_Team02.Services.DataAdminService; namespace mohaymen_codestar_Team02.Controllers; public class AnalystController : ControllerBase { private readonly IAnalystService AnalystService; + private readonly IDataAdminService _dataAdminService; - public AnalystController(IAnalystService analystService) + public AnalystController(IAnalystService analystService, IDataAdminService dataAdminService) { AnalystService = analystService; + _dataAdminService = dataAdminService; } [HttpGet("Analyst")] @@ -26,4 +31,28 @@ public async Task ExpandVertex([FromQuery] GraphQueryInfoDto grap var Response = await AnalystService.GetTheVertexNeighbor(graphQueryInfoDto, vertexId); return StatusCode((int)Response.Type, Response); } + + [HttpPost("Analyst")] + public async Task DisplayDataSetAsGraph([FromBody]FilterGraphDto filterGraphDto) + { + ServiceResponse response = + await _dataAdminService.DisplayGeraphData(filterGraphDto.DatasetId, filterGraphDto.SourceIdentifier, + filterGraphDto.TargetIdentifier, filterGraphDto.VertexIdentifier, filterGraphDto.VertexAttributeValues, filterGraphDto.EdgeAttributeValues); + response.Data.GraphId = filterGraphDto.DatasetId; + return StatusCode((int)response.Type, response); + } + + [HttpGet("Analyst/Vertex/{id}")] + public async Task DisplayVertexAttributes(long id) + { + var response = _dataAdminService.GetVertexAttributes(id); + return StatusCode((int)response.Type, response); + } + + [HttpGet("Analyst/Edge/{id}")] + public async Task DisplayEdgeAttributes(long id) + { + var response = _dataAdminService.GetEdgeAttributes(id); + return StatusCode((int)response.Type, response); + } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index b99edf5..ea75ca5 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -47,14 +47,14 @@ public IActionResult GetDataSetsList() var response = _dataAdminService.DisplayDataSet(); return StatusCode((int)response.Type, response); } - - [HttpPost("DataSets")] + + [HttpPost("DataSets/Graph")] public async Task DisplayDataSetAsGraph(GetGraphDto getGraphDto) { ServiceResponse response = - await _dataAdminService.DisplayGeraphData(getGraphDto.datasetId, getGraphDto.sourceIdentifier, - getGraphDto.targetIdentifier, getGraphDto.vertexIdentifier, getGraphDto.vertexAttributeValues, getGraphDto.edgeAttributeValues); - response.Data.GraphId = getGraphDto.datasetId; + await _dataAdminService.DisplayGeraphData(getGraphDto.DatasetId, getGraphDto.SourceIdentifier, + getGraphDto.TargetIdentifier, getGraphDto.VertexIdentifier, new Dictionary(){}, new Dictionary(){}); + response.Data.GraphId = getGraphDto.DatasetId; return StatusCode((int)response.Type, response); } @@ -71,18 +71,4 @@ public async Task DisplayEdgeDetails(string objectId) var respond = _dataAdminService.GetEdgeDetail(objectId); return StatusCode((int)respond.Type, respond); } - - [HttpGet("DataSets/Vertex/{id}")] - public async Task DisplayVertexAttributes(long id) - { - var response = _dataAdminService.GetVertexAttributes(id); - return StatusCode((int)response.Type, response); - } - - [HttpGet("DataSets/Edge/{id}")] - public async Task DisplayEdgeAttributes(long id) - { - var response = _dataAdminService.GetEdgeAttributes(id); - return StatusCode((int)response.Type, response); - } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GetGraphDto.cs b/mohaymen-codestar-Team02/Dto/GetGraphDto.cs deleted file mode 100644 index 45bc8b7..0000000 --- a/mohaymen-codestar-Team02/Dto/GetGraphDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace mohaymen_codestar_Team02.Dto; - -public class GetGraphDto -{ - public long datasetId { get; set; } - public string sourceIdentifier { get; set; } - public string targetIdentifier { get; set; } - public string vertexIdentifier { get; set; } - public Dictionary vertexAttributeValues { get; set; } - public Dictionary edgeAttributeValues { get; set; } -} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/FilterGraphDto.cs b/mohaymen-codestar-Team02/Dto/GraphDTO/FilterGraphDto.cs new file mode 100644 index 0000000..ef40152 --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GraphDTO/FilterGraphDto.cs @@ -0,0 +1,11 @@ +namespace mohaymen_codestar_Team02.Dto; + +public class FilterGraphDto +{ + public long DatasetId { get; set; } + public string SourceIdentifier { get; set; } + public string TargetIdentifier { get; set; } + public string VertexIdentifier { get; set; } + public Dictionary VertexAttributeValues { get; set; } + public Dictionary EdgeAttributeValues { get; set; } +} \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/GetGraphDto.cs b/mohaymen-codestar-Team02/Dto/GraphDTO/GetGraphDto.cs new file mode 100644 index 0000000..ff7e47c --- /dev/null +++ b/mohaymen-codestar-Team02/Dto/GraphDTO/GetGraphDto.cs @@ -0,0 +1,9 @@ +namespace mohaymen_codestar_Team02.Dto; + +public class GetGraphDto +{ + public long DatasetId { get; set; } + public string SourceIdentifier { get; set; } + public string TargetIdentifier { get; set; } + public string VertexIdentifier { get; set; } +} \ No newline at end of file From 26ef5e5d7dbea2a00b83a9f97ac7b46f8133fc50 Mon Sep 17 00:00:00 2001 From: HanaNrvtn Date: Fri, 6 Sep 2024 12:58:05 -0700 Subject: [PATCH 08/10] refactor: replace some method in services --- .../Controllers/AnalystController.cs | 8 ++-- .../Controllers/DataAdminController.cs | 2 +- .../Services/AnalystService/AnalystService.cs | 40 ++++++++++++++++++- .../AnalystService/IAnalystService.cs | 9 +++++ .../Abstraction/IDataAdminService.cs | 7 +--- .../DataAdminService/DataAdminService.cs | 19 ++------- 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/mohaymen-codestar-Team02/Controllers/AnalystController.cs b/mohaymen-codestar-Team02/Controllers/AnalystController.cs index f74ff1e..919bf7d 100644 --- a/mohaymen-codestar-Team02/Controllers/AnalystController.cs +++ b/mohaymen-codestar-Team02/Controllers/AnalystController.cs @@ -10,12 +10,10 @@ namespace mohaymen_codestar_Team02.Controllers; public class AnalystController : ControllerBase { private readonly IAnalystService AnalystService; - private readonly IDataAdminService _dataAdminService; public AnalystController(IAnalystService analystService, IDataAdminService dataAdminService) { AnalystService = analystService; - _dataAdminService = dataAdminService; } [HttpGet("Analyst")] @@ -36,7 +34,7 @@ public async Task ExpandVertex([FromQuery] GraphQueryInfoDto grap public async Task DisplayDataSetAsGraph([FromBody]FilterGraphDto filterGraphDto) { ServiceResponse response = - await _dataAdminService.DisplayGeraphData(filterGraphDto.DatasetId, filterGraphDto.SourceIdentifier, + await AnalystService.DisplayGeraphData(filterGraphDto.DatasetId, filterGraphDto.SourceIdentifier, filterGraphDto.TargetIdentifier, filterGraphDto.VertexIdentifier, filterGraphDto.VertexAttributeValues, filterGraphDto.EdgeAttributeValues); response.Data.GraphId = filterGraphDto.DatasetId; return StatusCode((int)response.Type, response); @@ -45,14 +43,14 @@ await _dataAdminService.DisplayGeraphData(filterGraphDto.DatasetId, filterGraphD [HttpGet("Analyst/Vertex/{id}")] public async Task DisplayVertexAttributes(long id) { - var response = _dataAdminService.GetVertexAttributes(id); + var response = AnalystService.GetVertexAttributes(id); return StatusCode((int)response.Type, response); } [HttpGet("Analyst/Edge/{id}")] public async Task DisplayEdgeAttributes(long id) { - var response = _dataAdminService.GetEdgeAttributes(id); + var response = AnalystService.GetEdgeAttributes(id); return StatusCode((int)response.Type, response); } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs index ea75ca5..7125b44 100644 --- a/mohaymen-codestar-Team02/Controllers/DataAdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/DataAdminController.cs @@ -53,7 +53,7 @@ public async Task DisplayDataSetAsGraph(GetGraphDto getGraphDto) { ServiceResponse response = await _dataAdminService.DisplayGeraphData(getGraphDto.DatasetId, getGraphDto.SourceIdentifier, - getGraphDto.TargetIdentifier, getGraphDto.VertexIdentifier, new Dictionary(){}, new Dictionary(){}); + getGraphDto.TargetIdentifier, getGraphDto.VertexIdentifier); response.Data.GraphId = getGraphDto.DatasetId; return StatusCode((int)response.Type, response); } diff --git a/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs b/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs index e1b70e2..3b7e040 100644 --- a/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs +++ b/mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs @@ -13,10 +13,16 @@ namespace mohaymen_codestar_Team02.Services.AnalystService; public class AnalystService : IAnalystService { private readonly IServiceProvider _serviceProvider; + private readonly IVertexService _vertexService; + private readonly IEdgeService _edgeService; + private readonly IGraphService _graphService; - public AnalystService(IServiceProvider serviceProvider) + public AnalystService(IServiceProvider serviceProvider, IVertexService vertexService, IEdgeService edgeService, IGraphService graphService) { _serviceProvider = serviceProvider; + _vertexService = vertexService; + _edgeService = edgeService; + _graphService = graphService; } private DataGroup JoinTheEdgeTable(IQueryable validDataSetTable, GraphQueryInfoDto graphQueryInfoDto) @@ -157,4 +163,36 @@ public async Task> GetTheVertexNeighbor(GraphQu ") milieSec to find the VertexNeighbor @@@@@@@@@@@@@@@@@@@@@@@@@@@@"); return new ServiceResponse(responseData, ApiResponseType.Success, string.Empty); } + + public async Task> DisplayGeraphData(long databaseId, + string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary vertexAttributeValus, Dictionary edgeAttributeValues) + { + var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, vertexAttributeValus); + var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName, edgeAttributeValues); + var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, + destinationEdgeIdentifierFieldName); + + var dto = new DisplayGraphDto() + { + Vertices = graph.vertices, + Edges = graph.edges + }; + return new ServiceResponse(dto, ApiResponseType.Success, + Resources.GraphFetchedSuccessfullyMessage); + } + + public ServiceResponse> GetVertexAttributes(long vertexEntityId) + { + var att = _vertexService.GetVertexAttributes(vertexEntityId); + return new ServiceResponse>(att, ApiResponseType.Success, ""); + } + + public ServiceResponse> GetEdgeAttributes(long edgeEntityId) + { + var att = _edgeService.GetEdgeAttributes(edgeEntityId); + return new ServiceResponse>(att, ApiResponseType.Success, ""); + } + } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/AnalystService/IAnalystService.cs b/mohaymen-codestar-Team02/Services/AnalystService/IAnalystService.cs index c6c0a82..7a69b48 100644 --- a/mohaymen-codestar-Team02/Services/AnalystService/IAnalystService.cs +++ b/mohaymen-codestar-Team02/Services/AnalystService/IAnalystService.cs @@ -7,4 +7,13 @@ namespace mohaymen_codestar_Team02.Services.AnalystService; public interface IAnalystService { Task> GetTheVertexNeighbor(GraphQueryInfoDto graphQueryInfoDto, string vertexId); + + Task> DisplayGeraphData(long databaseId, + string sourceEdgeIdentifierFieldName, + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, + Dictionary vertexAttributeValus, Dictionary edgeAttributeValues); + + ServiceResponse> GetVertexAttributes(long vertexEntityId); + + ServiceResponse> GetEdgeAttributes(long edgeEntityId); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs b/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs index db9ccc2..cfeb5fb 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/Abstraction/IDataAdminService.cs @@ -12,13 +12,8 @@ Task> StoreData(string? edgeFile, string? vertexFile, st ServiceResponse> DisplayDataSet(); Task> DisplayGeraphData(long dataSetId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, - Dictionary vertexAttributeVales, Dictionary edgeAttributeVales); + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName); ServiceResponse GetVertexDetail(string objectId); ServiceResponse GetEdgeDetail(string objectId); - - ServiceResponse> GetVertexAttributes(long vertexEntityId); - - ServiceResponse> GetEdgeAttributes(long edgeEntityId); } \ 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 d728172..caed92b 100644 --- a/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs +++ b/mohaymen-codestar-Team02/Services/DataAdminService/DataAdminService.cs @@ -95,12 +95,11 @@ public ServiceResponse> DisplayDataSet() public async Task> DisplayGeraphData(long databaseId, string sourceEdgeIdentifierFieldName, - string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, - Dictionary vertexAttributeVales, Dictionary edgeAttributeVales) + string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName) { - var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, vertexAttributeVales); + var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, new Dictionary(){}); var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName, - destinationEdgeIdentifierFieldName, edgeAttributeVales); + destinationEdgeIdentifierFieldName, new Dictionary(){}); var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName, destinationEdgeIdentifierFieldName); @@ -124,16 +123,4 @@ public ServiceResponse GetEdgeDetail(string objectId) return new ServiceResponse(_edgeService.GetEdgeDetails(objectId), ApiResponseType.Success, string.Empty); } - - public ServiceResponse> GetVertexAttributes(long vertexEntityId) - { - var att = _vertexService.GetVertexAttributes(vertexEntityId); - return new ServiceResponse>(att, ApiResponseType.Success, ""); - } - - public ServiceResponse> GetEdgeAttributes(long edgeEntityId) - { - var att = _edgeService.GetEdgeAttributes(edgeEntityId); - return new ServiceResponse>(att, ApiResponseType.Success, ""); - } } \ No newline at end of file From a185cefb220134553d2d98438ead6c63acb4715c Mon Sep 17 00:00:00 2001 From: Ftm-Sayadzadeh Date: Sat, 7 Sep 2024 10:42:33 +0430 Subject: [PATCH 09/10] refactor: refactor classes and services --- .../Controllers/AdminController.cs | 2 +- mohaymen-codestar-Team02/Data/DataContext.cs | 2 +- .../Dto/{GraphDTO => GraphDto}/DetailDto.cs | 0 .../{GraphDTO => GraphDto}/DisplayGraphDto.cs | 0 .../GetPermissionDto.cs | 0 .../Dto/{Role => RoleDto}/GetRoleDto.cs | 0 .../ChangePasswordUserDto.cs | 0 .../Dto/{User => UserDto}/CreateUserDto.cs | 0 .../Dto/{User => UserDto}/DeleteUserDto.cs | 0 .../Dto/{User => UserDto}/GetUserDto.cs | 0 .../Dto/{User => UserDto}/LoginUserDto.cs | 0 .../Dto/{User => UserDto}/UpdateUserDto.cs | 0 .../AddUserRoleDto.cs | 0 .../DeleteUserRoleDto.cs | 0 .../Models/Auth/UserRole.cs | 4 +- .../Models/newModel/Tables.cs | 9 - .../Abstraction/IAdminService.cs | 10 +- .../Services/Administration/AdminService.cs | 10 +- .../Administration/AdminServiceTest.cs | 185 +++++++++++++----- .../AnalystService/AnalystServiceTest.cs | 0 .../AuthenticationServiceTest.cs | 18 +- .../CookieService/CookieServiceTest.cs | 2 +- .../DataAdminService/DataAdminServiceTest.cs | 28 ++- .../EdgeServiceTest/EdgeServiceTest.cs | 143 +++++++------- .../GraphServiceTest/GraphServiceTest.cs | 96 +++++---- .../PasswordHandler/PasswordHandlerTest.cs | 11 +- .../ProfileService/ProfileServiceTest.cs | 4 +- .../StoreData}/EdgeStorerCsvTest.cs | 4 +- .../StoreData}/StoreDataServiceTest.cs | 2 +- .../StoreData}/VertexStorerCsvTest.cs | 2 +- .../TokenService/TokenServiceTest.cs | 12 +- .../VertexServiceTest/VertexServiceTest.cs | 52 ++--- 32 files changed, 333 insertions(+), 263 deletions(-) rename mohaymen-codestar-Team02/Dto/{GraphDTO => GraphDto}/DetailDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{GraphDTO => GraphDto}/DisplayGraphDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{Permission => PermissionDto}/GetPermissionDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{Role => RoleDto}/GetRoleDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/ChangePasswordUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/CreateUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/DeleteUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/GetUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/LoginUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{User => UserDto}/UpdateUserDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{UserRole => UserRoleDto}/AddUserRoleDto.cs (100%) rename mohaymen-codestar-Team02/Dto/{UserRole => UserRoleDto}/DeleteUserRoleDto.cs (100%) delete mode 100644 mohaymen-codestar-Team02/Models/newModel/Tables.cs rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/Administration/AdminServiceTest.cs (83%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/AnalystService/AnalystServiceTest.cs (100%) rename mohaymen-codestar-Team02_XUnitTest/{Servies/Authenticatoin => Services/Authentication}/AuthenticationServiceTest.cs (94%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/CookieService/CookieServiceTest.cs (98%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/DataAdminService/DataAdminServiceTest.cs (89%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/EdgeServiceTest/EdgeServiceTest.cs (52%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/GraphServiceTest/GraphServiceTest.cs (53%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/PasswordHandler/PasswordHandlerTest.cs (91%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/ProfileService/ProfileServiceTest.cs (97%) rename mohaymen-codestar-Team02_XUnitTest/{Servies/StorData => Services/StoreData}/EdgeStorerCsvTest.cs (94%) rename mohaymen-codestar-Team02_XUnitTest/{Servies/StorData => Services/StoreData}/StoreDataServiceTest.cs (97%) rename mohaymen-codestar-Team02_XUnitTest/{Servies/StorData => Services/StoreData}/VertexStorerCsvTest.cs (97%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/TokenService/TokenServiceTest.cs (93%) rename mohaymen-codestar-Team02_XUnitTest/{Servies => Services}/VertexServiceTest/VertexServiceTest.cs (79%) diff --git a/mohaymen-codestar-Team02/Controllers/AdminController.cs b/mohaymen-codestar-Team02/Controllers/AdminController.cs index 2e122ba..2ad80c2 100644 --- a/mohaymen-codestar-Team02/Controllers/AdminController.cs +++ b/mohaymen-codestar-Team02/Controllers/AdminController.cs @@ -21,7 +21,7 @@ public AdminController(IAdminService adminService) } [HttpGet("users")] - public async Task GetAllUsers([FromBody] int pageNumber) + public async Task GetAllUsers([FromQuery] int pageNumber) { var response = await _adminService.GetUsersPaginated(pageNumber); diff --git a/mohaymen-codestar-Team02/Data/DataContext.cs b/mohaymen-codestar-Team02/Data/DataContext.cs index 245b3ec..8cda218 100644 --- a/mohaymen-codestar-Team02/Data/DataContext.cs +++ b/mohaymen-codestar-Team02/Data/DataContext.cs @@ -11,7 +11,7 @@ public DataContext(DbContextOptions options) : base(options) { } - public DbSet Users { get; set; } + public DbSet Users { get; set; } public DbSet Roles { get; set; } public DbSet UserRoles { get; set; } public DbSet VertexEntities { get; set; } diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs b/mohaymen-codestar-Team02/Dto/GraphDto/DetailDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/GraphDTO/DetailDto.cs rename to mohaymen-codestar-Team02/Dto/GraphDto/DetailDto.cs diff --git a/mohaymen-codestar-Team02/Dto/GraphDTO/DisplayGraphDto.cs b/mohaymen-codestar-Team02/Dto/GraphDto/DisplayGraphDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/GraphDTO/DisplayGraphDto.cs rename to mohaymen-codestar-Team02/Dto/GraphDto/DisplayGraphDto.cs diff --git a/mohaymen-codestar-Team02/Dto/Permission/GetPermissionDto.cs b/mohaymen-codestar-Team02/Dto/PermissionDto/GetPermissionDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/Permission/GetPermissionDto.cs rename to mohaymen-codestar-Team02/Dto/PermissionDto/GetPermissionDto.cs diff --git a/mohaymen-codestar-Team02/Dto/Role/GetRoleDto.cs b/mohaymen-codestar-Team02/Dto/RoleDto/GetRoleDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/Role/GetRoleDto.cs rename to mohaymen-codestar-Team02/Dto/RoleDto/GetRoleDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/ChangePasswordUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/ChangePasswordUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/ChangePasswordUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/ChangePasswordUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/CreateUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/CreateUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/CreateUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/CreateUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/DeleteUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/DeleteUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/DeleteUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/DeleteUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/GetUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/GetUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/GetUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/GetUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/LoginUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/LoginUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/LoginUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/LoginUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/User/UpdateUserDto.cs b/mohaymen-codestar-Team02/Dto/UserDto/UpdateUserDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/User/UpdateUserDto.cs rename to mohaymen-codestar-Team02/Dto/UserDto/UpdateUserDto.cs diff --git a/mohaymen-codestar-Team02/Dto/UserRole/AddUserRoleDto.cs b/mohaymen-codestar-Team02/Dto/UserRoleDto/AddUserRoleDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/UserRole/AddUserRoleDto.cs rename to mohaymen-codestar-Team02/Dto/UserRoleDto/AddUserRoleDto.cs diff --git a/mohaymen-codestar-Team02/Dto/UserRole/DeleteUserRoleDto.cs b/mohaymen-codestar-Team02/Dto/UserRoleDto/DeleteUserRoleDto.cs similarity index 100% rename from mohaymen-codestar-Team02/Dto/UserRole/DeleteUserRoleDto.cs rename to mohaymen-codestar-Team02/Dto/UserRoleDto/DeleteUserRoleDto.cs diff --git a/mohaymen-codestar-Team02/Models/Auth/UserRole.cs b/mohaymen-codestar-Team02/Models/Auth/UserRole.cs index 443455c..5edc3a9 100644 --- a/mohaymen-codestar-Team02/Models/Auth/UserRole.cs +++ b/mohaymen-codestar-Team02/Models/Auth/UserRole.cs @@ -6,8 +6,8 @@ public class UserRole { public long UserId { get; set; } - [ForeignKey("UserId")] public virtual User User { get; set; } + [ForeignKey("UserId")] public virtual User? User { get; set; } public long RoleId { get; set; } - [ForeignKey("RoleId")] public virtual Role Role { get; set; } + [ForeignKey("RoleId")] public virtual Role? Role { get; set; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Models/newModel/Tables.cs b/mohaymen-codestar-Team02/Models/newModel/Tables.cs deleted file mode 100644 index ac2fa11..0000000 --- a/mohaymen-codestar-Team02/Models/newModel/Tables.cs +++ /dev/null @@ -1,9 +0,0 @@ -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/Administration/Abstraction/IAdminService.cs b/mohaymen-codestar-Team02/Services/Administration/Abstraction/IAdminService.cs index fe9538c..7662363 100644 --- a/mohaymen-codestar-Team02/Services/Administration/Abstraction/IAdminService.cs +++ b/mohaymen-codestar-Team02/Services/Administration/Abstraction/IAdminService.cs @@ -8,10 +8,10 @@ public interface IAdminService { Task?>> GetUsersPaginated(int pageNumber); Task> GetUserByUsername(string? username); - Task> CreateUser(User user, string password, List roles); - Task> DeleteUser(User user); - Task> UpdateUser(User user); + Task> CreateUser(User? user, string password, List roles); + Task> DeleteUser(User? user); + Task> UpdateUser(User? user); Task>> GetAllRoles(); - Task> AddRole(User user, Role role); - Task> DeleteRole(User user, Role role); + Task> AddRole(User? user, Role? role); + Task> DeleteRole(User? user, Role? role); } \ No newline at end of file diff --git a/mohaymen-codestar-Team02/Services/Administration/AdminService.cs b/mohaymen-codestar-Team02/Services/Administration/AdminService.cs index 557f209..b6b446f 100644 --- a/mohaymen-codestar-Team02/Services/Administration/AdminService.cs +++ b/mohaymen-codestar-Team02/Services/Administration/AdminService.cs @@ -85,7 +85,7 @@ public async Task>> GetAllRoles() return new ServiceResponse>(roles, ApiResponseType.Success, Resources.UsersRetrievedMassage); } - public async Task> CreateUser(User user, string password, List roles) + public async Task> CreateUser(User? user, string password, List roles) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -136,7 +136,7 @@ private bool IsRoleMatching(List roles, DataContext context) return matchingRoles; } - public async Task> DeleteUser(User user) + public async Task> DeleteUser(User? user) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -166,7 +166,7 @@ private bool IsRoleMatching(List roles, DataContext context) Resources.UserDeletionSuccessfulMessage); } - public async Task> UpdateUser(User user) + public async Task> UpdateUser(User? user) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -196,7 +196,7 @@ private bool IsRoleMatching(List roles, DataContext context) Resources.UserUpdateSuccessfulyMessage); } - public async Task> AddRole(User user, Role role) + public async Task> AddRole(User? user, Role? role) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); @@ -237,7 +237,7 @@ private bool IsRoleMatching(List roles, DataContext context) Resources.RoleAddedSuccessfulyMassage); } - public async Task> DeleteRole(User user, Role role) + public async Task> DeleteRole(User? user, Role? role) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/Administration/AdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/Administration/AdminServiceTest.cs similarity index 83% rename from mohaymen-codestar-Team02_XUnitTest/Servies/Administration/AdminServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/Administration/AdminServiceTest.cs index 227215b..64f84e3 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/Administration/AdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/Administration/AdminServiceTest.cs @@ -1,17 +1,17 @@ +using AutoMapper; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using mohaymen_codestar_Team02.Data; +using mohaymen_codestar_Team02.Dto.Role; +using mohaymen_codestar_Team02.Dto.User; using mohaymen_codestar_Team02.Models; using mohaymen_codestar_Team02.Services; using mohaymen_codestar_Team02.Services.Administration; using mohaymen_codestar_Team02.Services.CookieService; using mohaymen_codestar_Team02.Services.PasswordHandller; using NSubstitute; -using AutoMapper; -using Microsoft.Extensions.DependencyInjection; -using mohaymen_codestar_Team02.Dto.Role; -using mohaymen_codestar_Team02.Dto.User; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.Administration; +namespace mohaymen_codestar_Team02_XUnitTest.Services.Administration; public class AdminServiceTest { @@ -92,7 +92,7 @@ public async Task CreateUser_ShouldReturnCreated_WhenUserIsSuccessfullyRegistere // Arrange FixTheReturnOfCookies("admin"); - var newUser = AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); var fakePasswordHash = new byte[] { 1, 2, 3, 4 }; var fakePasswordSalt = new byte[] { 5, 6, 7, 8 }; @@ -106,13 +106,13 @@ public async Task CreateUser_ShouldReturnCreated_WhenUserIsSuccessfullyRegistere var role = new Role { RoleType = RoleType.DataAdmin.ToString() }; mockContext.Roles.Add(role); - mockContext.SaveChanges(); + await mockContext.SaveChangesAsync(); _passwordService.ValidatePassword(Arg.Any()).Returns(true); // Act var result = await _sut.CreateUser( - new User() { UserId = 8, Username = "mamad" }, "password", new List() { "DataAdmin" }); + new User() { UserId = 8, Username = "testUser" }, "password", new List() { "DataAdmin" }); // Assert Assert.Equal(ApiResponseType.Created, result.Type); @@ -140,18 +140,16 @@ public async Task CreateUser_ShouldSetCorrectPasswordHashAndSalt_WhenUserIsSucce x[2] = fakePasswordSalt; }); _passwordService.ValidatePassword(Arg.Any()).Returns(true); - var newUser = new User() { UserId = 8, Username = "mamad" }; + var newUser = new User() { UserId = 8, Username = "testUser" }; // Act - var result = await _sut.CreateUser(newUser, "password", new List()); + await _sut.CreateUser(newUser, "password", new List()); // Assert - Assert.Equal(ApiResponseType.Created, result.Type); Assert.Equal(fakePasswordHash, newUser.PasswordHash); Assert.Equal(fakePasswordSalt, newUser.Salt); } - [Fact] public async Task GetUserByUsername_ShouldReturnUnauthorized_WhenTokenIsEmpty() { @@ -173,8 +171,8 @@ public async Task GetUserByUsername_ShouldReturnSuccess_WhenUserIsFound() // Arrange FixTheReturnOfCookies("admin"); - var adminUser = AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var testUser = AddUserWithRole("testUser", "SystemAdmin", 2, mockContext); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("testUser", "SystemAdmin", 2, mockContext); var userDto = new GetUserDto { Username = "testUser" }; _mapper.Map(Arg.Any()).Returns(userDto); @@ -183,7 +181,25 @@ public async Task GetUserByUsername_ShouldReturnSuccess_WhenUserIsFound() // Assert Assert.Equal(ApiResponseType.Success, result.Type); - Assert.NotNull(result.Data); + } + + [Fact] + public async Task GetUserByUsername_ShouldReturnSpecificUser_WhenUserIsFound() + { + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("testUser", "SystemAdmin", 2, mockContext); + var userDto = new GetUserDto { Username = "testUser" }; + _mapper.Map(Arg.Any()).Returns(userDto); + + // Act + var result = await _sut.GetUserByUsername("testUser"); + + // Assert Assert.Equal("testUser", result.Data.Username); } @@ -208,8 +224,8 @@ public async Task GetUserByUsername_ShouldReturnNotFound_WhenUserDoesNotExist() // Arrange FixTheReturnOfCookies("admin"); - var adminUser = AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var targetUser = AddUserWithRole("targetUser", "SystemAdmin", 2, mockContext); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("targetUser", "SystemAdmin", 2, mockContext); var userDto = new GetUserDto { Username = "targetUser" }; _mapper.Map(Arg.Any()).Returns(userDto); @@ -234,14 +250,14 @@ public async Task GetAllUsers_ShouldReturnUnauthorized_WhenTokenIsEmpty() } [Fact] - public async Task GetAllUsers_ShouldReturnAllUsersSuccessfully_WhenAdminExist() + public async Task GetAllUsers_ShouldReturnSuccess_WhenAdminExist() { using var scope = _serviceProvider.CreateScope(); var mockContext = scope.ServiceProvider.GetRequiredService(); // Arrange FixTheReturnOfCookies("admin"); - var adminUser = AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); AddUserWithRole("user1", "User", 2, mockContext); AddUserWithRole("user2", "User", 3, mockContext); @@ -252,6 +268,26 @@ public async Task GetAllUsers_ShouldReturnAllUsersSuccessfully_WhenAdminExist() // Assert Assert.Equal(ApiResponseType.Success, result.Type); + } + + [Fact] + public async Task GetAllUsers_ShouldReturnAllUsersSuccessfully_WhenAdminExist() + { + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("user1", "User", 2, mockContext); + AddUserWithRole("user2", "User", 3, mockContext); + + _mapper.Map(Arg.Any()).Returns(new GetUserDto()); + + // Act + var result = await _sut.GetUsersPaginated(1); + + // Assert Assert.Equal(3, result.Data.Count); } @@ -269,7 +305,7 @@ public async Task GetAllUsers_ShouldReturnBadRequest_WhenAdminNotFound() } [Fact] - public async Task GetAllRoles_ShouldReturnAllRolesSuccessfully_WhenAdminExists() + public async Task GetAllRoles_ShouldReturnSuccess_WhenAdminExists() { using var scope = _serviceProvider.CreateScope(); var mockContext = scope.ServiceProvider.GetRequiredService(); @@ -278,7 +314,6 @@ public async Task GetAllRoles_ShouldReturnAllRolesSuccessfully_WhenAdminExists() mockContext.Roles.Add(new Role { RoleId = 1, RoleType = "SystemAdmin" }); mockContext.Roles.Add(new Role { RoleId = 2, RoleType = "Analyst" }); await mockContext.SaveChangesAsync(); - _mapper.Map(Arg.Any()).Returns(new GetRoleDto()); // Act @@ -286,31 +321,29 @@ public async Task GetAllRoles_ShouldReturnAllRolesSuccessfully_WhenAdminExists() // Assert Assert.Equal(ApiResponseType.Success, result.Type); - Assert.Equal(2, result.Data.Count); } - private void FixTheReturnOfCookies(string? returnThis) + [Fact] + public async Task GetAllRoles_ShouldReturnAllRolesSuccessfully_WhenAdminExists() { - _cookieService.GetCookieValue().Returns(returnThis); - _tokenService.GetUserNameFromToken().Returns(returnThis); - } + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); - private UserRole AddUserWithRole(string userName, string roleType, long id, DataContext dataContext) - { - 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 }; - dataContext.Users.Add(user); - dataContext.Roles.Add(role); - dataContext.UserRoles.Add(userRole); - dataContext.SaveChanges(); - return new UserRole { Role = role, User = user }; + // Arrange + List roles = + [ + new Role { RoleId = 1, RoleType = "SystemAdmin" }, + new Role { RoleId = 2, RoleType = "Analyst" } + ]; + foreach (var role in roles) mockContext.Roles.Add(role); + await mockContext.SaveChangesAsync(); + _mapper.Map(Arg.Any()).Returns(new GetRoleDto()); + + // Act + var result = await _sut.GetAllRoles(); + + // Assert + Assert.Equal(2, result.Data.Count); } [Fact] @@ -367,7 +400,7 @@ public async Task AddRole_ShouldReturnNotFound_WhenUserDoesNotExist() // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var user = AddUserWithRole("target", "DataAdmin", 2, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); // Act var result = await _sut.AddRole(new User() { Username = "testUser" }, @@ -509,7 +542,7 @@ public async Task DeleteRole_ShouldRoleBeNullIfLookingForIt_WhenUserRoleExistsAn // Assert var result = mockContext.UserRoles.SingleOrDefault(ur => - ur.UserId == user.User.UserId && ur.RoleId == user.Role.RoleId); + user.Role != null && user.User != null && ur.UserId == user.User.UserId && ur.RoleId == user.Role.RoleId); Assert.Null(result); } @@ -522,7 +555,7 @@ public async Task DeleteRole_ShouldReturnNotFound_WhenUserDoesNotExist() // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var user = AddUserWithRole("target", "DataAdmin", 2, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); // Act var result = await _sut.DeleteRole(new User() { Username = "testUser" }, @@ -566,10 +599,11 @@ public async Task DeleteUser_ShouldReturnNotFound_WhenUserDoesNotExist() // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var user = AddUserWithRole("target", "DataAdmin", 2, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); // Act var result = await _sut.DeleteUser(new User() { Username = "testUser" }); + // Assert Assert.Equal(ApiResponseType.NotFound, result.Type); } @@ -601,7 +635,7 @@ public async Task DeleteUser_ShouldReturnYouCanNotDeleteYourself_WhenAdminDelete // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var user = AddUserWithRole("target", "DataAdmin", 2, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); // Act var result = await _sut.DeleteUser(new User() { Username = "admin" }); @@ -645,7 +679,7 @@ public async Task UpdateUser_ShouldReturnNotFound_WhenUserNotFound() // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SystemAdmin", 1, mockContext); - var user = AddUserWithRole("target", "DataAdmin", 2, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); // Act var result = await _sut.UpdateUser(new User() { Username = "testUSer" }); @@ -678,8 +712,59 @@ public async Task UpdateUser_ShouldReturnSuccess_WhenUpdateIsSuccessful() var result = await _sut.UpdateUser(updateUser); // Assert - Assert.NotNull(result); Assert.Equal(ApiResponseType.Success, result.Type); - Assert.NotNull(result.Data); + } + + [Fact] + public async Task UpdateUser_ShouldUpdateUser_WhenUpdateIsSuccessful() + { + using var scope = _serviceProvider.CreateScope(); + var mockContext = scope.ServiceProvider.GetRequiredService(); + + // Arrange + FixTheReturnOfCookies("admin"); + AddUserWithRole("admin", "SystemAdmin", 1, mockContext); + AddUserWithRole("target", "DataAdmin", 2, mockContext); + + _mapper.Map(Arg.Any()).Returns(new GetUserDto()); + + var updateUser = new User() + { + Username = "target", + FirstName = "update", + LastName = "update", + Email = "update@example.com" + }; + var expected = _mapper.Map(updateUser); + + // Act + var result = await _sut.UpdateUser(updateUser); + + // Assert + Assert.Equal(expected, result.Data); + } + + private void FixTheReturnOfCookies(string? returnThis) + { + _cookieService.GetCookieValue().Returns(returnThis); + _tokenService.GetUserNameFromToken().Returns(returnThis); + } + + private UserRole AddUserWithRole(string userName, string roleType, long id, DataContext dataContext) + { + 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 }; + dataContext.Users.Add(user); + dataContext.Roles.Add(role); + dataContext.UserRoles.Add(userRole); + dataContext.SaveChanges(); + return new UserRole { Role = role, User = user }; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/AnalystService/AnalystServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/AnalystService/AnalystServiceTest.cs similarity index 100% rename from mohaymen-codestar-Team02_XUnitTest/Servies/AnalystService/AnalystServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/AnalystService/AnalystServiceTest.cs diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/Authenticatoin/AuthenticationServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs similarity index 94% rename from mohaymen-codestar-Team02_XUnitTest/Servies/Authenticatoin/AuthenticationServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs index 3aacd11..0e87b9e 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/Authenticatoin/AuthenticationServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs @@ -12,7 +12,7 @@ using mohaymen_codestar_Team02.Services.PasswordHandller; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.Authenticatoin; +namespace mohaymen_codestar_Team02_XUnitTest.Services.Authentication; public class AuthenticationServiceTests { @@ -20,7 +20,7 @@ public class AuthenticationServiceTests private readonly ITokenService _tokenService; private readonly ICookieService _cookieService; private readonly IPasswordService _passwordService; - private IServiceProvider _serviceProvider; + private readonly IServiceProvider _serviceProvider; public AuthenticationServiceTests() { @@ -70,7 +70,6 @@ public async Task Login_ShouldReturnBadRequest_WhenPasswordIsNullOrEmpty(string // Assert Assert.Equal(ApiResponseType.BadRequest, result.Type); - Assert.Null(result.Data); } [Fact] @@ -85,7 +84,6 @@ public async Task Login_ShouldReturnBadRequest_WhenUserDoesNotExist() // Assert Assert.Equal(ApiResponseType.BadRequest, result.Type); - Assert.Null(result.Data); } [Fact] @@ -104,7 +102,6 @@ public async Task Login_ShouldReturnBadRequest_WhenPasswordIsIncorrect() // Assert Assert.Equal(ApiResponseType.BadRequest, result.Type); - Assert.Null(result.Data); } [Fact] @@ -126,7 +123,6 @@ public async Task Login_ShouldReturnSuccess_WhenCredentialsAreCorrect() // Assert Assert.Equal(ApiResponseType.Success, result.Type); - Assert.NotNull(result.Data); } private void AddUserToDatabase(string username, string password) @@ -154,14 +150,13 @@ public void Logout_ShouldCallGetExpiredCookie_WhenCookieIsPresent() { // Arrange _cookieService.GetCookieValue().Returns("someCookieValue"); + _cookieService.Received(1).GetExpiredCookie(); // Act var result = _sut.Logout(); // Assert - _cookieService.Received(1).GetExpiredCookie(); Assert.Equal(ApiResponseType.Success, result.Type); - Assert.Null(result.Data); } [Fact] @@ -169,14 +164,12 @@ public void Logout_ShouldNotCallGetExpiredCookie_WhenCookieIsNotPresent() { // Arrange _cookieService.GetCookieValue().Returns((string?)null); - + _cookieService.DidNotReceive().GetExpiredCookie(); // Act var result = _sut.Logout(); // Assert - _cookieService.DidNotReceive().GetExpiredCookie(); Assert.Equal(ApiResponseType.Success, result.Type); - Assert.Null(result.Data); } [Fact] @@ -261,7 +254,7 @@ private void FixTheReturnOfCookies(string? returnThis) _tokenService.GetUserNameFromToken().Returns(returnThis); } - private UserRole AddUserWithRole(string userName, string roleType, long id, List permissions) + private void AddUserWithRole(string userName, string roleType, long id, List permissions) { using var scope = _serviceProvider.CreateScope(); var mockContext = scope.ServiceProvider.GetRequiredService(); @@ -281,6 +274,5 @@ private UserRole AddUserWithRole(string userName, string roleType, long id, List mockContext.Roles.Add(role); mockContext.UserRoles.Add(userRole); mockContext.SaveChanges(); - return new UserRole { Role = role, User = user }; } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/CookieService/CookieServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/CookieService/CookieServiceTest.cs similarity index 98% rename from mohaymen-codestar-Team02_XUnitTest/Servies/CookieService/CookieServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/CookieService/CookieServiceTest.cs index 59a2171..c19401f 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/CookieService/CookieServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/CookieService/CookieServiceTest.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Http; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.CookieService; +namespace mohaymen_codestar_Team02_XUnitTest.Services.CookieService; public class CookieServiceTests { diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/DataAdminService/DataAdminServiceTest.cs similarity index 89% rename from mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/DataAdminService/DataAdminServiceTest.cs index d7ca8bb..bfc9d5b 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/DataAdminService/DataAdminServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/DataAdminService/DataAdminServiceTest.cs @@ -11,21 +11,21 @@ using mohaymen_codestar_Team02.Services.StoreData.Abstraction; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.DataAdminService; +namespace mohaymen_codestar_Team02_XUnitTest.Services.DataAdminService; public class DataAdminServiceTest { - private readonly IStorHandler _storHandler; + private readonly IStorHandler _storeHandler; private readonly IDisplayDataService _displayDataService; private readonly IMapper _mapper; private readonly IServiceProvider _serviceProvider; private DataContext _dataContext; - private readonly mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService _sut; private readonly IEdgeService _edgeService; private readonly IVertexService _vertexService; private readonly ITokenService _tokenService; private readonly ICookieService _cookieService; private readonly IGraphService _graphService; + private readonly mohaymen_codestar_Team02.Services.DataAdminService.DataAdminService _sut; public DataAdminServiceTest() { @@ -34,7 +34,7 @@ public DataAdminServiceTest() _tokenService = Substitute.For(); _vertexService = Substitute.For(); _edgeService = Substitute.For(); - _storHandler = Substitute.For(); + _storeHandler = Substitute.For(); _displayDataService = Substitute.For(); _mapper = Substitute.For(); @@ -50,9 +50,9 @@ 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.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); + _cookieService, _storeHandler, _displayDataService, _edgeService, _vertexService, _mapper, _graphService); + _storeHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); + _storeHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } private void FixTheReturnOfCookies(string? returnThis) @@ -102,7 +102,7 @@ public async Task StoreData_ReturnsBadRequest_WhenCreatingTheDataGroupIsFail() //Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SustemAdmin", 1); - _storHandler.StoreDataSet("mahdddd", Arg.Any()).Returns(-1); + _storeHandler.StoreDataSet("mahdddd", Arg.Any()).Returns(-1); //Action var result = await _sut.StoreData("sample", "sample", "mahdddd", "name", "ma"); //Assert @@ -115,7 +115,7 @@ public async Task StoreData_ReturnsBadRequest_WhenEdageStorerStoreValuesReturnFa //Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SustemAdmin", 1); - _storHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); + _storeHandler.EdageStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); //Action var result = await _sut.StoreData("sample", "sample", "test", "mahdddd", "mahdddd"); //Assert @@ -128,7 +128,7 @@ public async Task StoreData_ReturnsBadRequest_WhenVertexStorerStoreValuesReturnF // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SustemAdmin", 1); - _storHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); + _storeHandler.VertexStorer.StoreFileData(Arg.Any(), Arg.Any(), Arg.Any()).Returns(false); // Act var result = await _sut.StoreData("sampleEdgeFile", "sampleVertexFile", "testData", "mamama", "mmm"); @@ -143,7 +143,7 @@ public async Task StoreData_ReturnsSuccess_WhenInputAreValid() // Arrange FixTheReturnOfCookies("admin"); AddUserWithRole("admin", "SustemAdmin", 1); - _storHandler.StoreDataSet(Arg.Any(), Arg.Any()).Returns(9); + _storeHandler.StoreDataSet(Arg.Any(), Arg.Any()).Returns(9); // Act var result = await _sut.StoreData("sampleEdgeFile", "sampleVertexFile", "testData", "a", "lll"); // Assert @@ -254,10 +254,4 @@ public void DisplayDataSet_ShouldReturnDataSet_WhenGivenCorrectUsername() // Assert Assert.Equivalent(expected, actual); } - - public ServiceResponse> GetVertexAttributes(long vertexEntityId) - { - var att = _vertexService.GetVertexAttributes(vertexEntityId); - return new ServiceResponse>(att, ApiResponseType.Success, ""); - } } \ No newline at end of file diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest/EdgeServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/EdgeServiceTest/EdgeServiceTest.cs similarity index 52% rename from mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest/EdgeServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/EdgeServiceTest/EdgeServiceTest.cs index d00b63f..d6f9e78 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/EdgeServiceTest/EdgeServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/EdgeServiceTest/EdgeServiceTest.cs @@ -8,7 +8,7 @@ using mohaymen_codestar_Team02.Services; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies; +namespace mohaymen_codestar_Team02_XUnitTest.Services.EdgeServiceTest; public class EdgeServiceTest { @@ -74,20 +74,20 @@ public void GetEdgeAttribute_ShouldReturnAllAttributes_WhenGivenCorrectEdgeId() // Arrange long edgeEntityId = 1; - var AttName1 = "Att1"; - var AttName2 = "Att2"; + var attName1 = "Att1"; + var attName2 = "Att2"; var expected = new List() { new() { Id = 1, - Name = AttName1 + Name = attName1 }, new() { Id = 2, - Name = AttName2 + Name = attName2 } }; @@ -98,11 +98,11 @@ public void GetEdgeAttribute_ShouldReturnAllAttributes_WhenGivenCorrectEdgeId() { EdgeAttributes = new List { - new(AttName1, edgeEntityId) + new(attName1, edgeEntityId) { Id = 1 }, - new(AttName2, edgeEntityId) + new(attName2, edgeEntityId) { Id = 2 } @@ -117,14 +117,14 @@ public void GetEdgeAttribute_ShouldReturnAllAttributes_WhenGivenCorrectEdgeId() .Returns(new GetAttributeDto() { Id = 1, - Name = AttName1 + Name = attName1 }); _mapper.Map(Arg.Is(value => value.Id == 2)) .Returns(new GetAttributeDto() { Id = 2, - Name = AttName2 + Name = attName2 }); // Act @@ -142,17 +142,17 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie // Arrange long datasetId = 1; - string attName1 = "SourceAcount"; - string attName2 = "DestiantionAccount"; - string attName3 = "RandomAtt"; - string vertexIdentifierFieldName = "CardID"; - string sourceEdgeIdentifierFieldName = attName1; - string destinationEdgeIdentifierFieldName = attName2; + var attName1 = "SourceAcount"; + var attName2 = "DestiantionAccount"; + var attName3 = "RandomAtt"; + var vertexIdentifierFieldName = "CardID"; + var sourceEdgeIdentifierFieldName = attName1; + var destinationEdgeIdentifierFieldName = attName2; var attValue = new Dictionary() { - {attName1, "val1"}, - {attName2, "val8"} + { attName1, "val1" }, + { attName2, "val8" } }; var dataset = new DataGroup("Dataset1", 1) @@ -161,83 +161,86 @@ public void GetAllEdges_ShouldReturnAllEdges_WhenGivenCorrectDatasetAndIdentifie { EdgeAttributes = new List { - new EdgeAttribute(attName1, 1) + new(attName1, 1) { EdgeValues = new List { - new EdgeValue("val1", 1, "id1"){ EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val1", 1, "id2") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val2", 1, "id3") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val2", 1, "id4") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val5", 1, "id5") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val1", 1, "id6") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val1", 1, "id7") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val5", 1, "id8") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val1", 1, "id9") { EdgeAttribute = new EdgeAttribute(attName1, 1)}, - new EdgeValue("val3", 1, "id10") { EdgeAttribute = new EdgeAttribute(attName1, 1)} + new("val1", 1, "id1") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val1", 1, "id2") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val2", 1, "id3") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val2", 1, "id4") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val5", 1, "id5") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val1", 1, "id6") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val1", 1, "id7") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val5", 1, "id8") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val1", 1, "id9") { EdgeAttribute = new EdgeAttribute(attName1, 1) }, + new("val3", 1, "id10") { EdgeAttribute = new EdgeAttribute(attName1, 1) } } }, // 2, 6, 7 - new EdgeAttribute(attName2, 1) + new(attName2, 1) { EdgeValues = new List { - new EdgeValue("val7", 2, "id1"){ EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val8", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val8", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName2, 1)}, - new EdgeValue("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName2, 1)} + new("val7", 2, "id1") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val8", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val8", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName2, 1) }, + new("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName2, 1) } } }, - new EdgeAttribute(attName3, 1) + new(attName3, 1) { EdgeValues = new List { - new EdgeValue("val7", 2, "id1"){ EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val11", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val18", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName3, 1)}, - new EdgeValue("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName3, 1)} - } + new("val7", 2, "id1") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val11", 2, "id2") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val9", 2, "id3") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val10", 2, "id4") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val11", 2, "id5") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val8", 2, "id6") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val18", 2, "id7") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val12", 2, "id8") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val12", 2, "id9") { EdgeAttribute = new EdgeAttribute(attName3, 1) }, + new("val8", 2, "id10") { EdgeAttribute = new EdgeAttribute(attName3, 1) } + } } - } - } - }; var expected = new Dictionary>() { - {"id2", new Dictionary() { - {attName1, "val1"}, - {attName2, "val8"}, - {attName3, "val11"} - }}, - {"id6", new Dictionary() + "id2", new Dictionary() + { + { attName1, "val1" }, + { attName2, "val8" }, + { attName3, "val11" } + } + }, { - {attName1, "val1"}, - {attName2, "val8"}, - {attName3, "val8"} - }}, - {"id7", new Dictionary() + "id6", new Dictionary() + { + { attName1, "val1" }, + { attName2, "val8" }, + { attName3, "val8" } + } + }, { - {attName1, "val1"}, - {attName2, "val8"}, - {attName3, "val18"} - }} + "id7", new Dictionary() + { + { attName1, "val1" }, + { attName2, "val8" }, + { attName3, "val18" } + } + } }; - + contex.DataSets.Add(dataset); contex.SaveChanges(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest/GraphServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/GraphServiceTest/GraphServiceTest.cs similarity index 53% rename from mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest/GraphServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/GraphServiceTest/GraphServiceTest.cs index 7a823b8..e69f83e 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/GraphServiceTest/GraphServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/GraphServiceTest/GraphServiceTest.cs @@ -2,8 +2,7 @@ using mohaymen_codestar_Team02.Services; using NSubstitute; - -namespace mohaymen_codestar_Team02_XUnitTest.Servies; +namespace mohaymen_codestar_Team02_XUnitTest.Services.GraphServiceTest; public class GraphServiceTest { @@ -17,60 +16,72 @@ public GraphServiceTest() _edgeService = Substitute.For(); _sut = new GraphService(_vertexService, _edgeService); } - + [Fact] public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetNameAndIdentifiers() { // Arrange long datasetId = 1; - string vertexAttName1 = "VertexAttName1"; - string vertexAttName2 = "VertexAttName2"; - string edgeAttName1 = "EdgeAttName1"; - string edgeAttName2 = "EdgeAttName2"; - string edgeAttName3 = "EdgeAttName3"; - var SourceIdentifierFieldName = edgeAttName1; - var TargetIdentifierFieldName = edgeAttName2; + var vertexAttName1 = "VertexAttName1"; + var vertexAttName2 = "VertexAttName2"; + var edgeAttName1 = "EdgeAttName1"; + var edgeAttName2 = "EdgeAttName2"; + var edgeAttName3 = "EdgeAttName3"; + var sourceIdentifierFieldName = edgeAttName1; + var targetIdentifierFieldName = edgeAttName2; var vertexIdentifierFieldName = vertexAttName1; var vertexAttributeValues = new Dictionary>() { - {"id1", new Dictionary() { - {vertexAttName1, "val1"}, - {vertexAttName2, "val2"}, - }}, - {"id2", new Dictionary() + "id1", new Dictionary() + { + { vertexAttName1, "val1" }, + { vertexAttName2, "val2" } + } + }, { - {vertexAttName1, "val1"}, - {vertexAttName2, "val3"}, - }}, - {"id3", new Dictionary() + "id2", new Dictionary() + { + { vertexAttName1, "val1" }, + { vertexAttName2, "val3" } + } + }, { - {vertexAttName1, "val2"}, - {vertexAttName2, "val2"}, - }} + "id3", new Dictionary() + { + { vertexAttName1, "val2" }, + { vertexAttName2, "val2" } + } + } }; - + var edgeAttributeValues = new Dictionary>() { - {"id1", new Dictionary() { - {edgeAttName1, "val1"}, // s= 1, 2 d= 3 - {edgeAttName2, "val2"}, - {edgeAttName3, "val8"} - }}, - {"id2", new Dictionary() + "id1", new Dictionary() + { + { edgeAttName1, "val1" }, // s= 1, 2 d= 3 + { edgeAttName2, "val2" }, + { edgeAttName3, "val8" } + } + }, { - {edgeAttName1, "val2"}, // - {edgeAttName2, "val4"}, - {edgeAttName3, "val8"} - }}, - {"id3", new Dictionary() + "id2", new Dictionary() + { + { edgeAttName1, "val2" }, // + { edgeAttName2, "val4" }, + { edgeAttName3, "val8" } + } + }, { - {edgeAttName1, "val2"}, // s= 3 d= 1, 2 - {edgeAttName2, "val1"}, - {edgeAttName3, "val8"} - }} + "id3", new Dictionary() + { + { edgeAttName1, "val2" }, // s= 3 d= 1, 2 + { edgeAttName2, "val1" }, + { edgeAttName3, "val8" } + } + } }; var expectedVertex = new List() @@ -91,7 +102,7 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN Label = "val2" } }; - + var expectedEdge = new List() { new() @@ -119,11 +130,12 @@ public void GetGraph_ShouldReturnListOfVerticesAndDestinations_WhenGivenDatasetN Target = "id2" } }; - + var expected = (expectedVertex, expectedEdge); - + // Act - var actual = _sut.GetGraph(vertexAttributeValues, edgeAttributeValues, vertexIdentifierFieldName, SourceIdentifierFieldName, TargetIdentifierFieldName); + var actual = _sut.GetGraph(vertexAttributeValues, edgeAttributeValues, vertexIdentifierFieldName, + sourceIdentifierFieldName, targetIdentifierFieldName); // Assert Assert.Equivalent(expected, actual); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/PasswordHandler/PasswordHandlerTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/PasswordHandler/PasswordHandlerTest.cs similarity index 91% rename from mohaymen-codestar-Team02_XUnitTest/Servies/PasswordHandler/PasswordHandlerTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/PasswordHandler/PasswordHandlerTest.cs index 2c5b0ce..9c183ef 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/PasswordHandler/PasswordHandlerTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/PasswordHandler/PasswordHandlerTest.cs @@ -1,15 +1,10 @@ -namespace mohaymen_codestar_Team02_XUnitTest.Servies.PasswordHandler; - using mohaymen_codestar_Team02.Services.PasswordHandller; +namespace mohaymen_codestar_Team02_XUnitTest.Services.PasswordHandler; + public class PasswordServiceTests { - private readonly PasswordService _sut; - - public PasswordServiceTests() - { - _sut = new PasswordService(); - } + private readonly PasswordService _sut = new(); [Fact] public void CreatePasswordHash_ShouldGenerateDifferentHashAndSalt_ForDifferentPasswords() diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/ProfileService/ProfileServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/ProfileService/ProfileServiceTest.cs similarity index 97% rename from mohaymen-codestar-Team02_XUnitTest/Servies/ProfileService/ProfileServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/ProfileService/ProfileServiceTest.cs index 382c900..ee465a9 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/ProfileService/ProfileServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/ProfileService/ProfileServiceTest.cs @@ -10,7 +10,7 @@ using mohaymen_codestar_Team02.Services.PasswordHandller; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.ProfileService; +namespace mohaymen_codestar_Team02_XUnitTest.Services.ProfileService; public class ProfileServiceTests { @@ -163,7 +163,7 @@ public async Task UpdateUser_ShouldReturnSuccess_WhenUserIsUpdated() Assert.Equal(ApiResponseType.Success, result.Type); } - private User AddUserToDatabase(string username, string password) + private User? AddUserToDatabase(string username, string password) { using var scope = _serviceProvider.CreateScope(); var mockContext = scope.ServiceProvider.GetRequiredService(); diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/EdgeStorerCsvTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/EdgeStorerCsvTest.cs similarity index 94% rename from mohaymen-codestar-Team02_XUnitTest/Servies/StorData/EdgeStorerCsvTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/StoreData/EdgeStorerCsvTest.cs index 6a55d50..5de4fc5 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/EdgeStorerCsvTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/EdgeStorerCsvTest.cs @@ -1,11 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using mohaymen_codestar_Team02.Data; -using mohaymen_codestar_Team02.Models.EdgeEAV; using mohaymen_codestar_Team02.Services.StoreData; -using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.StorData; +namespace mohaymen_codestar_Team02_XUnitTest.Services.StoreData; public class EdgeStorerCsvTests { diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/StoreDataServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/StoreDataServiceTest.cs similarity index 97% rename from mohaymen-codestar-Team02_XUnitTest/Servies/StorData/StoreDataServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/StoreData/StoreDataServiceTest.cs index 1dcf722..9987f1f 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/StoreDataServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/StoreDataServiceTest.cs @@ -6,7 +6,7 @@ using mohaymen_codestar_Team02.Services.StoreData.Abstraction; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.StorData; +namespace mohaymen_codestar_Team02_XUnitTest.Services.StoreData; public class StoreDataServiceTest { diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/VertexStorerCsvTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/VertexStorerCsvTest.cs similarity index 97% rename from mohaymen-codestar-Team02_XUnitTest/Servies/StorData/VertexStorerCsvTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/StoreData/VertexStorerCsvTest.cs index 0a0ff82..ff07319 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/StorData/VertexStorerCsvTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/StoreData/VertexStorerCsvTest.cs @@ -3,7 +3,7 @@ using mohaymen_codestar_Team02.Data; using mohaymen_codestar_Team02.Services.StoreData; -namespace mohaymen_codestar_Team02_XUnitTest.Servies.StorData; +namespace mohaymen_codestar_Team02_XUnitTest.Services.StoreData; public class VertexStorerCsvTests { diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/TokenService/TokenServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/TokenService/TokenServiceTest.cs similarity index 93% rename from mohaymen-codestar-Team02_XUnitTest/Servies/TokenService/TokenServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/TokenService/TokenServiceTest.cs index c1576f3..aa685a7 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/TokenService/TokenServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/TokenService/TokenServiceTest.cs @@ -1,15 +1,13 @@ -namespace mohaymen_codestar_Team02_XUnitTest.Servies.TokenService; - using System.Security.Claims; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using NSubstitute; -using Xunit; -using mohaymen_codestar_Team02.Services.TokenService; -using Microsoft.AspNetCore.Http; + +namespace mohaymen_codestar_Team02_XUnitTest.Services.TokenService; public class TokenServiceTests { - private readonly TokenService _sut; + private readonly mohaymen_codestar_Team02.Services.TokenService.TokenService _sut; private readonly IConfiguration _configuration; private readonly IHttpContextAccessor _httpContextAccessor; @@ -22,7 +20,7 @@ public TokenServiceTests() _configuration.GetSection("AppSettings:Token").Value .Returns("SuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSuperSecretKey"); - _sut = new TokenService(_configuration, _httpContextAccessor); + _sut = new mohaymen_codestar_Team02.Services.TokenService.TokenService(_configuration, _httpContextAccessor); } [Fact] diff --git a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest/VertexServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/VertexServiceTest/VertexServiceTest.cs similarity index 79% rename from mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest/VertexServiceTest.cs rename to mohaymen-codestar-Team02_XUnitTest/Services/VertexServiceTest/VertexServiceTest.cs index aacf76f..353b712 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Servies/VertexServiceTest/VertexServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/VertexServiceTest/VertexServiceTest.cs @@ -8,7 +8,7 @@ using mohaymen_codestar_Team02.Services; using NSubstitute; -namespace mohaymen_codestar_Team02_XUnitTest.Servies; +namespace mohaymen_codestar_Team02_XUnitTest.Services.VertexServiceTest; public class VertexServiceTest { @@ -39,20 +39,20 @@ public void GetVertexAttribute_ShouldReturnAllAttributes_WhenGivenCorrectVertexI // Arrange long vertexEntityId = 1; - var AttName1 = "Att1"; - var AttName2 = "Att2"; + var attName1 = "Att1"; + var attName2 = "Att2"; var expected = new List() { new() { Id = 1, - Name = AttName1 + Name = attName1 }, new() { Id = 2, - Name = AttName2 + Name = attName2 } }; @@ -62,11 +62,11 @@ public void GetVertexAttribute_ShouldReturnAllAttributes_WhenGivenCorrectVertexI { VertexAttributes = new List { - new(AttName1, 1) + new(attName1, 1) { Id = 1 }, - new(AttName2, 1) + new(attName2, 1) { Id = 2 } @@ -81,14 +81,14 @@ public void GetVertexAttribute_ShouldReturnAllAttributes_WhenGivenCorrectVertexI .Returns(new GetAttributeDto() { Id = 1, - Name = AttName1 + Name = attName1 }); _mapper.Map(Arg.Is(value => value.Id == 2)) .Returns(new GetAttributeDto() { Id = 2, - Name = AttName2 + Name = attName2 }); // Act @@ -141,9 +141,9 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() // Arrange long datasetId = 1; - string attName1 = "AttName1"; - string attName2 = "AttName2"; - string vertexIdentifierFieldName = attName1; + var attName1 = "AttName1"; + var attName2 = "AttName2"; + var vertexIdentifierFieldName = attName1; var dataset = new DataGroup("DatasetName1", 1) { @@ -152,21 +152,21 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() { VertexAttributes = new List { - new VertexAttribute(attName1, 1) + new(attName1, 1) { VertexValues = new List { - new VertexValue("val1", 1, "id1"){ VertexAttribute = new VertexAttribute(attName1, 1)}, - new VertexValue("val2", 1, "id2") { VertexAttribute = new VertexAttribute(attName1, 1)} + new("val1", 1, "id1") { VertexAttribute = new VertexAttribute(attName1, 1) }, + new("val2", 1, "id2") { VertexAttribute = new VertexAttribute(attName1, 1) } } }, - new VertexAttribute(attName2, 1) + new(attName2, 1) { VertexValues = new List { - new VertexValue("val3", 2, "id1"){ VertexAttribute = new VertexAttribute(attName2, 1)}, - new VertexValue("val4", 2, "id2") { VertexAttribute = new VertexAttribute(attName2, 1)} - } + new("val3", 2, "id1") { VertexAttribute = new VertexAttribute(attName2, 1) }, + new("val4", 2, "id2") { VertexAttribute = new VertexAttribute(attName2, 1) } + } } } } @@ -175,18 +175,20 @@ public void GetAllVertices_ShouldReturnAllVertices_WhenGivenCorrectDatasetName() mockContext.DataSets.Add(dataset); mockContext.SaveChanges(); - Dictionary> expected = new Dictionary>() + var expected = new Dictionary>() { - {"id1", new Dictionary() { - {attName1, "val1"}, - {attName2, "val3"} - }} + "id1", new Dictionary() + { + { attName1, "val1" }, + { attName2, "val3" } + } + } }; var attValue = new Dictionary() { - {attName1, "val1"}, + { attName1, "val1" } //{attName2, "val3"}, }; From bbf937c50720cfc2f2110c7182c738b799627d90 Mon Sep 17 00:00:00 2001 From: Ftm-Sayadzadeh Date: Sat, 7 Sep 2024 10:55:43 +0430 Subject: [PATCH 10/10] fix: fix logout test --- .../Services/Authentication/AuthenticationServiceTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs b/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs index 0e87b9e..6e3c6cb 100644 --- a/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs +++ b/mohaymen-codestar-Team02_XUnitTest/Services/Authentication/AuthenticationServiceTest.cs @@ -150,7 +150,7 @@ public void Logout_ShouldCallGetExpiredCookie_WhenCookieIsPresent() { // Arrange _cookieService.GetCookieValue().Returns("someCookieValue"); - _cookieService.Received(1).GetExpiredCookie(); + _cookieService.GetExpiredCookie(); // Act var result = _sut.Logout();