From f1431918c4b523248e0510e2d914d849f2c350fe Mon Sep 17 00:00:00 2001 From: msmahdinejad <154900233+msmahdinejad@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:01:23 +0330 Subject: [PATCH] fix(RollBack): Fix roll back (#33) * Add failed EdgesAdditionService unit tests. * Complete EdgesAdditionService class & pass its unit tests. * add & pass SingleNodeAdditionService unit tests. * fix single node addition * Complete SingleEdgeAdditionService class & pass its tests. * some changes. * fix nodesAddition RollBack and its tests! * fix roll back for edges --------- Co-authored-by: sadq --- .../Services/EdgesAdditionServiceTests.cs | 109 +++++++++--------- .../Services/NodesAdditionServiceTests.cs | 84 ++++++++------ .../SingleEdgeAdditionServiceTests.cs | 57 ++++++--- .../SingleNodeAdditionServiceTests.cs | 26 +++-- .../Abstraction/ISingleEdgeAdditionService.cs | 7 +- .../Abstraction/ISingleNodeAdditionService.cs | 3 +- .../GraphServices/EdgesAdditionService.cs | 14 ++- .../GraphServices/NodesAdditionService.cs | 10 +- .../SingleEdgeAdditionService.cs | 5 +- .../SingleNodeAdditionService.cs | 4 +- 10 files changed, 186 insertions(+), 133 deletions(-) diff --git a/RelationshipAnalysis.Test/Services/EdgesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/EdgesAdditionServiceTests.cs index b824fcd..80d1f9e 100644 --- a/RelationshipAnalysis.Test/Services/EdgesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/EdgesAdditionServiceTests.cs @@ -311,61 +311,60 @@ private IFormFile CreateFileMock(string csvContent) fileMock.Length.Returns(stream.Length); return fileMock; } - -// // TODO -// [Fact] -// public async Task AddEdges_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() -// { -// // Arrange -// var expected = new ActionResponse() -// { -// Data = new MessageDto(Resources.SuccessfulEdgeAdditionMessage), -// StatusCode = StatusCodeType.Success -// }; -// var csvContent = @"""SourceAcount"",""DestiantionAccount"",""Amount"",""Date"",""TransactionID"",""Type"" -// ""6534454617"",""6039548046"",""500,000,000"",""1399/04/23"",""153348811341"",""پایا"" -// ""6534454617"",""6039548046"",""500,000,000"",""1399/04/23"",""153348811341"",""پایا"" -// ""6039548046"",""5287517379"",""100,000,000"",""1399/04/23"",""192524206627"",""پایا"""; -// var fileToBeSend = CreateFileMock(csvContent); -// -// var validatorMock = NSubstitute.Substitute.For(); -// validatorMock.Validate(fileToBeSend, "TransactionID", "SourceAcount", "DestiantionAccount").Returns(expected); -// var processorMock = NSubstitute.Substitute.For(); -// processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List()); -// var additionServiceMock = new Mock(); -// -// // Setup the mock to throw an exception for any inputs -// additionServiceMock -// .Setup(service => service.AddSingleEdge( -// It.IsAny>(), -// It.IsAny(), -// It.IsAny(), -// It.IsAny(), -// It.IsAny(), -// It.IsAny(), -// It.IsAny() -// )) -// .Throws(new Exception("Custom exception message")); -// _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock.Object); -// -// // Act -// var result = await _sut.AddEdges(new UploadEdgeDto() -// { -// File = fileToBeSend, -// EdgeCategoryName = "Transaction", -// UniqueKeyHeaderName = "TransactionID", -// SourceNodeCategoryName = "Account", -// TargetNodeCategoryName = "Account", -// SourceNodeHeaderName = "SourceAcount", -// TargetNodeHeaderName = "DestiantionAccount" -// }); -// // Assert -// Assert.Equivalent(expected, result); -// using var scope = _serviceProvider.CreateScope(); -// var context = scope.ServiceProvider.GetRequiredService(); -// Assert.Equal(0, context.Nodes.Count()); -// Assert.Equal("Custom exception message", result.Data.Message); -// } + // TODO + [Fact] + public async Task AddEdges_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() + { + // Arrange + var expected = new ActionResponse() + { + Data = new MessageDto(Resources.SuccessfulEdgeAdditionMessage), + StatusCode = StatusCodeType.Success + }; + var csvContent = @"""SourceAcount"",""DestiantionAccount"",""Amount"",""Date"",""TransactionID"",""Type"" +""6534454617"",""6039548046"",""500,000,000"",""1399/04/23"",""153348811341"",""پایا"" +""6534454617"",""6039548046"",""500,000,000"",""1399/04/23"",""153348811341"",""پایا"" +""6039548046"",""5287517379"",""100,000,000"",""1399/04/23"",""192524206627"",""پایا"""; + var fileToBeSend = CreateFileMock(csvContent); + + var validatorMock = NSubstitute.Substitute.For(); + validatorMock.Validate(fileToBeSend, "TransactionID", "SourceAcount", "DestiantionAccount").Returns(expected); + var processorMock = NSubstitute.Substitute.For(); + processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List() { new Dictionary()}); + var additionServiceMock = new Mock(); + + // Setup the mock to throw an exception for any inputs + additionServiceMock + .Setup(service => service.AddSingleEdge( + It.IsAny(), + It.IsAny>(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny() + )) + .Throws(new Exception("Custom exception message")); + _sut = new EdgesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock.Object); + + // Act + var result = await _sut.AddEdges(new UploadEdgeDto() + { + File = fileToBeSend, + EdgeCategoryName = "Transaction", + UniqueKeyHeaderName = "TransactionID", + SourceNodeCategoryName = "Account", + TargetNodeCategoryName = "Account", + SourceNodeHeaderName = "SourceAcount", + TargetNodeHeaderName = "DestiantionAccount" + }); + // Assert + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + Assert.Equal(0, context.Nodes.Count()); + Assert.Equal("Custom exception message", result.Data.Message); + } } \ No newline at end of file diff --git a/RelationshipAnalysis.Test/Services/NodesAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/NodesAdditionServiceTests.cs index 5f1be19..60c2014 100644 --- a/RelationshipAnalysis.Test/Services/NodesAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/NodesAdditionServiceTests.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.DependencyInjection; +using Moq; using NSubstitute; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; @@ -143,43 +144,52 @@ public async Task AddNodes_ShouldReturnSuccess_WhenNodeDtoIsValid() Assert.Equivalent(expected, result); } -// // TODO -// [Fact] -// public async Task AddNodes_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() -// { -// // Arrange -// var expected = new ActionResponse() -// { -// Data = new MessageDto(Resources.FailedAddRecordsMessage), -// StatusCode = StatusCodeType.BadRequest -// }; -// var csvContent = @"""AccountID"",""CardID"",""IBAN"" -// ""6534454617"",""6104335000000190"",""IR120778801496000000198"" -// ""6534454617"",""6104335000000190"",""IR120778801496000000198"" -// ""4000000028"",""6037699000000020"",""IR033880987114000000028"" -// "; -// var fileToBeSend = CreateFileMock(csvContent); -// -// var validatorMock = NSubstitute.Substitute.For(); -// validatorMock.Validate(fileToBeSend, "AccountID").Returns(expected); -// var processorMock = NSubstitute.Substitute.For(); -// processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List()); -// var additionServiceMock = NSubstitute.Substitute.For(); -// _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock); -// -// // Act -// var result = await _sut.AddNodes(new UploadNodeDto() -// { -// File = fileToBeSend, -// NodeCategoryName = "Account", -// UniqueKeyHeaderName = "AccountID" -// }); -// // Assert -// Assert.Equivalent(expected, result); -// using var scope = _serviceProvider.CreateScope(); -// var context = scope.ServiceProvider.GetRequiredService(); -// Assert.Equal(0, context.Nodes.Count()); -// } + // TODO + [Fact] + public async Task AddNodes_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData() + { + // Arrange + var expected = new ActionResponse() + { + Data = new MessageDto(Resources.ValidFileMessage), + StatusCode = StatusCodeType.Success + }; + var csvContent = @"""AccountID"",""CardID"",""IBAN"" +""6534454617"",""6104335000000190"",""IR120778801496000000198"" +""6534454617"",""6104335000000190"",""IR120778801496000000198"" +""4000000028"",""6037699000000020"",""IR033880987114000000028"" +"; + var fileToBeSend = CreateFileMock(csvContent); + + var validatorMock = NSubstitute.Substitute.For(); + validatorMock.Validate(fileToBeSend, "AccountID").Returns(expected); + var processorMock = NSubstitute.Substitute.For(); + processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List(){ new Dictionary() }); + var additionServiceMock = new Mock(); + + additionServiceMock + .Setup(service => service.AddSingleNode( + It.IsAny(), + It.IsAny>(), + It.IsAny(), + It.IsAny() + )) + .ThrowsAsync(new Exception("Custom exception message")); + _sut = new NodesAdditionService(_serviceProvider, validatorMock, processorMock, additionServiceMock.Object); + + // Act + var result = await _sut.AddNodes(new UploadNodeDto() + { + File = fileToBeSend, + NodeCategoryName = "Account", + UniqueKeyHeaderName = "AccountID" + }); + // Assert + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + Assert.Equal(0, context.Nodes.Count()); + Assert.Equal("Custom exception message", result.Data.Message); + } private IFormFile CreateFileMock(string csvContent) diff --git a/RelationshipAnalysis.Test/Services/SingleEdgeAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/SingleEdgeAdditionServiceTests.cs index 042fcfd..30861d8 100644 --- a/RelationshipAnalysis.Test/Services/SingleEdgeAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/SingleEdgeAdditionServiceTests.cs @@ -89,12 +89,13 @@ public async Task AddSingleEdge_ShouldAddNewEdge_WhenValidRecordIsProvided() { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act - await _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + await _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); var edge = await context.Edges.SingleOrDefaultAsync(e => e.EdgeUniqueString == "TestEdge"); Assert.NotNull(edge); Assert.Equal(1, edge.EdgeSourceNodeId); @@ -121,12 +122,14 @@ public async Task AddSingleEdge_ShouldAddNewAttributes_WhenEdgeExists() { "Attribute2", "Value2" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + // Act - await _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + await _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); var edge = await context.Edges.SingleOrDefaultAsync(e => e.EdgeUniqueString == "tran1"); Assert.NotNull(edge); Assert.Equal(1, edge.EdgeSourceNodeId); @@ -154,9 +157,13 @@ public async Task AddSingleEdge_ShouldThrowException_WhenUniqueEdgeNameIsEmpty() { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert await Assert.ThrowsAsync(action); @@ -174,10 +181,14 @@ public async Task AddSingleEdge_ShouldThrowException_WhenUniqueTargetNodeNameIsE { "TargetNode", "acc2" }, { "Attribute1", "Value1" } }; + + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert await Assert.ThrowsAsync(action); @@ -196,9 +207,12 @@ public async Task AddSingleEdge_ShouldThrowException_WhenUniqueSourceNodeNameIsE { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert await Assert.ThrowsAsync(action); @@ -215,9 +229,13 @@ public async Task AddSingleEdge_ShouldThrowException_WhenSourceNodeDoesNotExist( { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert await Assert.ThrowsAsync(action); @@ -234,10 +252,14 @@ public async Task AddSingleEdge_ShouldThrowException_WhenTargetNodeDoesNotExist( { "TargetNode", "NotExist" }, { "Attribute1", "Value1" } }; + + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert await Assert.ThrowsAsync(action); @@ -255,9 +277,12 @@ public async Task AddSingleEdge_ShouldThrowException_WhenEdgeValueAlreadyExists( { "att1", "dsjsdnfukj" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert @@ -275,10 +300,14 @@ public async Task AddSingleEdge_ShouldThrowException_WhenSourceOrDestinationIsDe { "TargetNode", "acc2" }, { "att2", "dsjsdnfukj" } }; - + + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + // Act var action = () => - _sut.AddSingleEdge(record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); + _sut.AddSingleEdge(context, record, "UniqueEdge", "SourceNode", "TargetNode", 1, 1, 1); // Assert diff --git a/RelationshipAnalysis.Test/Services/SingleNodeAdditionServiceTests.cs b/RelationshipAnalysis.Test/Services/SingleNodeAdditionServiceTests.cs index b50cd09..15048a5 100644 --- a/RelationshipAnalysis.Test/Services/SingleNodeAdditionServiceTests.cs +++ b/RelationshipAnalysis.Test/Services/SingleNodeAdditionServiceTests.cs @@ -63,12 +63,14 @@ public async Task AddSingleNode_ShouldAddNewNode_WhenValidRecordIsProvided() { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act - await _sut.AddSingleNode(record, "UniqueName", 1); + await _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); + var node = await context.Nodes.SingleOrDefaultAsync(n => n.NodeUniqueString == "TestNode2"); Assert.NotNull(node); Assert.Equal(1, node.NodeCategoryId); @@ -91,12 +93,14 @@ public async Task AddSingleNode_ShouldAddAttributes_WhenNodeExists() { "Attribute2", "Value2" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act - await _sut.AddSingleNode(record, "UniqueName", 1); + await _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert - using var scope = _serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); + var node = await context.Nodes.SingleOrDefaultAsync(n => n.NodeUniqueString == "TestNode"); Assert.NotNull(node); Assert.Equal(1, node.NodeCategoryId); @@ -119,8 +123,11 @@ public async Task AddSingleNode_ShouldThrowException_WhenUniqueNameIsEmpty() { "Attribute1", "Value1" } }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act - var action = () => _sut.AddSingleNode(record, "UniqueName", 1); + var action = () => _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert await Assert.ThrowsAsync(action); @@ -136,8 +143,11 @@ public async Task AddSingleNode_ShouldThrowException_WhenNodeValueAlreadyExists( { "Attribute1", "ExistingValue" }, }; + using var scope = _serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + // Act - var action = () => _sut.AddSingleNode(record, "UniqueName", 1); + var action = () => _sut.AddSingleNode(context, record, "UniqueName", 1); // Assert await Assert.ThrowsAsync(action); diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleEdgeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleEdgeAdditionService.cs index 245277b..7b2d879 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleEdgeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleEdgeAdditionService.cs @@ -1,7 +1,10 @@ -namespace RelationshipAnalysis.Services.GraphServices.Abstraction; + +using RelationshipAnalysis.Context; + +namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface ISingleEdgeAdditionService { - Task AddSingleEdge(IDictionary record, string uniqueHeaderName, string uniqueSourceHeaderName, string uniqueTargetHeaderName, + Task AddSingleEdge(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, string uniqueSourceHeaderName, string uniqueTargetHeaderName, int edgeCategoryId, int sourceNodeCategoryId, int targetNodeCategoryId); } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleNodeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleNodeAdditionService.cs index a0f9357..224ac25 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleNodeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/ISingleNodeAdditionService.cs @@ -1,3 +1,4 @@ +using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph; @@ -5,5 +6,5 @@ namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface ISingleNodeAdditionService { - Task AddSingleNode(IDictionary record, string uniqueHeaderName, int nodeCategoryId); + Task AddSingleNode(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, int nodeCategoryId); } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/EdgesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/EdgesAdditionService.cs index cb768ff..5099cc7 100644 --- a/RelationshipAnalysis/Services/GraphServices/EdgesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/EdgesAdditionService.cs @@ -48,13 +48,17 @@ public async Task> AddEdges(UploadEdgeDto uploadEdgeD var objects = await csvProcessorService.ProcessCsvAsync(file); - using (var transaction = await context.Database.BeginTransactionAsync()) + await using (var transaction = await context.Database.BeginTransactionAsync()) { try - { - objects.ForEach(ob => - singleEdgeAdditionService.AddSingleEdge((IDictionary)ob, uniqueHeader, uniqueSourceHeader, uniqueTargetHeader, - edgeCategory.EdgeCategoryId, sourceNodeCategory.NodeCategoryId ,targetNodeCategory.NodeCategoryId)); + { + foreach (var obj in objects) + { + await singleEdgeAdditionService.AddSingleEdge(context, (IDictionary)obj, + uniqueHeader, uniqueSourceHeader, uniqueTargetHeader, + edgeCategory.EdgeCategoryId, sourceNodeCategory.NodeCategoryId, + targetNodeCategory.NodeCategoryId); + } await transaction.CommitAsync(); } catch (Exception e) diff --git a/RelationshipAnalysis/Services/GraphServices/NodesAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/NodesAdditionService.cs index 8bf87d2..1627d1e 100644 --- a/RelationshipAnalysis/Services/GraphServices/NodesAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/NodesAdditionService.cs @@ -34,13 +34,15 @@ public async Task> AddNodes(UploadNodeDto uploadNodeD var objects = await csvProcessorService.ProcessCsvAsync(file); - using (var transaction = await context.Database.BeginTransactionAsync()) + await using (var transaction = await context.Database.BeginTransactionAsync()) { try { - objects.ForEach(ob => - singleNodeAdditionService.AddSingleNode((IDictionary)ob, uniqueHeader, - nodeCategory.NodeCategoryId)); + foreach (var obj in objects) + { + await singleNodeAdditionService.AddSingleNode(context, (IDictionary)obj, uniqueHeader, + nodeCategory.NodeCategoryId); + } await transaction.CommitAsync(); } catch (Exception e) diff --git a/RelationshipAnalysis/Services/GraphServices/SingleEdgeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/SingleEdgeAdditionService.cs index 184d16b..83107b2 100644 --- a/RelationshipAnalysis/Services/GraphServices/SingleEdgeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/SingleEdgeAdditionService.cs @@ -9,13 +9,10 @@ namespace RelationshipAnalysis.Services.GraphServices; public class SingleEdgeAdditionService(IServiceProvider serviceProvider) : ISingleEdgeAdditionService { - public async Task AddSingleEdge(IDictionary record, string uniqueHeaderName, + public async Task AddSingleEdge(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, string uniqueSourceHeaderName, string uniqueTargetHeaderName, int edgeCategoryId, int sourceNodeCategoryId, int targetNodeCategoryId) { - using var scope = serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - if (((string)record[uniqueHeaderName]).IsNullOrEmpty()) { throw new Exception(Resources.FailedAddRecordsMessage); diff --git a/RelationshipAnalysis/Services/GraphServices/SingleNodeAdditionService.cs b/RelationshipAnalysis/Services/GraphServices/SingleNodeAdditionService.cs index 80d493a..432a924 100644 --- a/RelationshipAnalysis/Services/GraphServices/SingleNodeAdditionService.cs +++ b/RelationshipAnalysis/Services/GraphServices/SingleNodeAdditionService.cs @@ -8,10 +8,8 @@ namespace RelationshipAnalysis.Services.GraphServices; public class SingleNodeAdditionService(IServiceProvider serviceProvider) : ISingleNodeAdditionService { - public async Task AddSingleNode(IDictionary record, string uniqueHeaderName, int nodeCategoryId) + public async Task AddSingleNode(ApplicationDbContext context, IDictionary record, string uniqueHeaderName, int nodeCategoryId) { - using var scope = serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); if (((string)record[uniqueHeaderName]).IsNullOrEmpty()) { throw new Exception(Resources.FailedAddRecordsMessage);