Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload edges file #31

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task UploadNode_ShouldReturnSuccess_WhenDtoIsValid()

var formDataContent = new MultipartFormDataContent();
formDataContent.Add(new StringContent("Account"), "NodeCategoryName");
formDataContent.Add(new StringContent("AccountID"), "UniqueAttributeHeaderName");
formDataContent.Add(new StringContent("AccountID"), "UniqueKeyHeaderName");
formDataContent.Add(fileContent, "file", mockFile.FileName);

var request = new HttpRequestMessage(HttpMethod.Post, "api/node");
Expand Down
259 changes: 199 additions & 60 deletions RelationshipAnalysis.Test/Resources.Designer.cs

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion RelationshipAnalysis.Test/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>

<root>

<data name="InvalidTargetNodeCategory">
<value>Target Node category is invalid!</value>
</data>
<data name="InvalidSourceNodeCategory">
<value>Source Node category is invalid!</value>
</data>
<data name="InvalidEdgeCategory">
<value>Edge category is invalid!</value>
</data>
<data name="SuccessfulEdgeAdditionMessage">
<value>Edges added successfully!</value>
</data>


<data name="ValidFileMessage">
<value>File is valid!</value>
</data>
Expand Down
371 changes: 371 additions & 0 deletions RelationshipAnalysis.Test/Services/EdgesAdditionServiceTests.cs

Large diffs are not rendered by default.

66 changes: 54 additions & 12 deletions RelationshipAnalysis.Test/Services/NodesAdditionServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ public class NodesAdditionServiceTests

public NodesAdditionServiceTests()
{
_context = new ApplicationDbContext(new DbContextOptionsBuilder<ApplicationDbContext>()
var serviceCollection = new ServiceCollection();

var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning))
.Options);

var serviceCollection = new ServiceCollection();
serviceCollection.AddScoped(_ => _context);
.Options;

serviceCollection.AddScoped(_ => new ApplicationDbContext(options));

SeedDatabase();
_serviceProvider = serviceCollection.BuildServiceProvider();

SeedDatabase();
}

private void SeedDatabase()
{
_context.Add(new NodeCategory()
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
context.Add(new NodeCategory()
{
NodeCategoryName = "Account",
NodeCategoryId = 1
});
_context.SaveChanges();
context.SaveChanges();
}

[Fact]
Expand Down Expand Up @@ -70,7 +74,7 @@ public async Task AddNodes_ShouldReturnBadRequest_WhenUniqueHeaderIsInvalid()
{
File = fileToBeSend,
NodeCategoryName = "Account",
UniqueAttributeHeaderName = "SomeHeaderThatDoesntExist"
UniqueKeyHeaderName = "SomeHeaderThatDoesntExist"
});
// Assert
Assert.Equivalent(expected, result);
Expand Down Expand Up @@ -100,7 +104,7 @@ public async Task AddNodes_ShouldReturnBadRequest_WhenNodeCategoryIsInvalid()
{
File = fileToBeSend,
NodeCategoryName = "SomeNodeCategoryThatDoesntExist",
UniqueAttributeHeaderName = "AccountID"
UniqueKeyHeaderName = "AccountID"
});
// Assert
Assert.Equivalent(expected, result);
Expand Down Expand Up @@ -133,13 +137,51 @@ public async Task AddNodes_ShouldReturnSuccess_WhenNodeDtoIsValid()
{
File = fileToBeSend,
NodeCategoryName = "Account",
UniqueAttributeHeaderName = "AccountID"
UniqueKeyHeaderName = "AccountID"
});
// Assert
Assert.Equivalent(expected, result);
}


// // TODO
// [Fact]
// public async Task AddNodes_ShouldReturnBadRequestAndRollBack_WhenDbFailsToAddData()
// {
// // Arrange
// var expected = new ActionResponse<MessageDto>()
// {
// 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<ICsvValidatorService>();
// validatorMock.Validate(fileToBeSend, "AccountID").Returns(expected);
// var processorMock = NSubstitute.Substitute.For<ICsvProcessorService>();
// processorMock.ProcessCsvAsync(fileToBeSend).Returns(new List<dynamic>());
// var additionServiceMock = NSubstitute.Substitute.For<ISingleNodeAdditionService>();
// _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<ApplicationDbContext>();
// Assert.Equal(0, context.Nodes.Count());
// }


private IFormFile CreateFileMock(string csvContent)
{
var csvFileName = "test.csv";
Expand Down
Loading