Skip to content
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 @@ -145,7 +145,10 @@
if (fileImportLogAggregate.IsCreated == false)
{
// First file of the day so create
fileImportLogAggregate.CreateImportLog(command.EstateId, importLogDateTime);
Result result = fileImportLogAggregate.CreateImportLog(command.EstateId, importLogDateTime);
if (result.IsFailed) {
return result;
}
}

// Move the file
Expand Down Expand Up @@ -192,7 +195,9 @@
file.MoveTo(fileDestination, overwrite: true);

// Update Import log aggregate
fileImportLogAggregate.AddImportedFile(fileId, command.MerchantId, command.UserId, command.FileProfileId, originalName, fileDestination, command.FileUploadedDateTime);
var stateResult= fileImportLogAggregate.AddImportedFile(fileId, command.MerchantId, command.UserId, command.FileProfileId, originalName, fileDestination, command.FileUploadedDateTime);
if (stateResult.IsFailed)
return stateResult;

return Result.Success(fileId);
}, importLogId, cancellationToken, false);
Expand Down Expand Up @@ -360,7 +365,7 @@
return Result.NotFound($"No contracts found for Merchant Id {fileDetails.MerchantId} on estate Id {fileDetails.EstateId}");
}

ContractResponse? contract = null;

Check warning on line 368 in FileProcessor.BusinessLogic/Services/FileProcessorDomainService.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (fileProfile.OperatorName == "Voucher")
{
contract = contracts.SingleOrDefault(c => c.Description.Contains(operatorName));
Expand All @@ -375,7 +380,7 @@
return Result.NotFound($"No merchant contract for operator Id {operatorName} found for Merchant Id {merchant.MerchantId}");
}

ContractProduct? product = contract.Products.SingleOrDefault(p => p.Value == null); // TODO: Is this enough or should the name be used and stored in file profile??

Check warning on line 383 in FileProcessor.BusinessLogic/Services/FileProcessorDomainService.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

if (product == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using SimpleResults;
using Xunit;

namespace FileProcessor.FileImportLogAggregate.Tests
Expand All @@ -25,7 +26,8 @@ public void FileImportLogAggregate_CanBeCreated_IsCreated()
public void FileImportLogAggregate_CreateImportLog_IsCreated()
{
FileImportLogAggregate fileImportLogAggregate = FileImportLogAggregate.Create(TestData.FileImportLogId);
fileImportLogAggregate.CreateImportLog(TestData.EstateId, TestData.ImportLogDateTime);
Result result = fileImportLogAggregate.CreateImportLog(TestData.EstateId, TestData.ImportLogDateTime);
result.IsSuccess.ShouldBeTrue();

FileImportLog fileImportLog = fileImportLogAggregate.GetFileImportLog();
fileImportLog.ShouldNotBeNull();
Expand All @@ -48,10 +50,8 @@ public void FileImportLogAggregate_CreateImportLog_AlreadyCreated_SilentlyHandle
fileImportLog.EstateId.ShouldBe(TestData.EstateId);
fileImportLog.FileImportLogDateTime.ShouldBe(TestData.ImportLogDateTime);

Should.NotThrow(() =>
{
fileImportLogAggregate.CreateImportLog(TestData.EstateId, TestData.ImportLogDateTime);
});
var result = fileImportLogAggregate.CreateImportLog(TestData.EstateId, TestData.ImportLogDateTime);
result.IsSuccess.ShouldBeTrue();
}

[Fact]
Expand All @@ -70,14 +70,12 @@ public void FileImportLogAggregate_AddImportedFile_FileAdded()
}

[Fact]
public void FileImportLogAggregate_AddImportedFile_ImportLogNotCreated_ErrorThrown()
{
public void FileImportLogAggregate_AddImportedFile_ImportLogNotCreated_ErrorThrown() {
FileImportLogAggregate fileImportLogAggregate = FileImportLogAggregate.Create(TestData.FileImportLogId);

Should.Throw<InvalidOperationException>(() =>
{
fileImportLogAggregate.AddImportedFile(TestData.FileId, TestData.MerchantId, TestData.UserId, TestData.FileProfileId, TestData.OriginalFileName, TestData.FilePath, TestData.FileUploadedDateTime);
});
var result = fileImportLogAggregate.AddImportedFile(TestData.FileId, TestData.MerchantId, TestData.UserId, TestData.FileProfileId, TestData.OriginalFileName, TestData.FilePath, TestData.FileUploadedDateTime);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);
}

[Fact]
Expand All @@ -86,10 +84,9 @@ public void FileImportLogAggregate_AddImportedFile_DuplicateFileId_ErrorThrown()
FileImportLogAggregate fileImportLogAggregate = FileImportLogAggregate.Create(TestData.FileImportLogId);
fileImportLogAggregate.CreateImportLog(TestData.EstateId, TestData.ImportLogDateTime);
fileImportLogAggregate.AddImportedFile(TestData.FileId, TestData.MerchantId, TestData.UserId, TestData.FileProfileId, TestData.OriginalFileName, TestData.FilePath, TestData.FileUploadedDateTime);
Should.Throw<InvalidOperationException>(() =>
{
fileImportLogAggregate.AddImportedFile(TestData.FileId, TestData.MerchantId, TestData.UserId, TestData.FileProfileId, TestData.OriginalFileName, TestData.FilePath, TestData.FileUploadedDateTime);
});
Result result = fileImportLogAggregate.AddImportedFile(TestData.FileId, TestData.MerchantId, TestData.UserId, TestData.FileProfileId, TestData.OriginalFileName, TestData.FilePath, TestData.FileUploadedDateTime);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);
}
}
}
14 changes: 9 additions & 5 deletions FileProcessor.FileImportLogAggregate/FileImportLogAggregate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using FileProcessor.Models;
using SimpleResults;

namespace FileProcessor.FileImportLogAggregate
{
Expand All @@ -14,33 +15,36 @@ namespace FileProcessor.FileImportLogAggregate
using Shared.General;

public static class FileImportLogAggregateExtensions{
public static void CreateImportLog(this FileImportLogAggregate aggregate, Guid estateId, DateTime importLogDateTime)
public static Result CreateImportLog(this FileImportLogAggregate aggregate, Guid estateId, DateTime importLogDateTime)
{
// Silently handle a duplicate create
if (aggregate.IsCreated)
return;
return Result.Success();

ImportLogCreatedEvent importLogCreatedEvent = new ImportLogCreatedEvent(aggregate.AggregateId, estateId, importLogDateTime);

aggregate.ApplyAndAppend(importLogCreatedEvent);
return Result.Success();
}

public static void AddImportedFile(this FileImportLogAggregate aggregate, Guid fileId, Guid merchantId, Guid userId, Guid fileProfileId, String originalFileName, String filePath, DateTime fileUploadedDateTime)
public static Result AddImportedFile(this FileImportLogAggregate aggregate, Guid fileId, Guid merchantId, Guid userId, Guid fileProfileId, String originalFileName, String filePath, DateTime fileUploadedDateTime)
{
if (aggregate.IsCreated == false)
{
throw new InvalidOperationException("Import log has not been created");
return Result.Invalid("Import log has not been created");
}

if (aggregate.Files.Any(f => f.FileId == fileId))
{
throw new InvalidOperationException($"Duplicate file {originalFileName} detected File Id [{fileId}]");
return Result.Invalid($"Duplicate file {originalFileName} detected File Id [{fileId}]");
}

FileAddedToImportLogEvent fileAddedToImportLogEvent =
new FileAddedToImportLogEvent(aggregate.AggregateId, fileId, aggregate.EstateId, merchantId, userId, fileProfileId, originalFileName, filePath, fileUploadedDateTime);

aggregate.ApplyAndAppend(fileAddedToImportLogEvent);

return Result.Success();
}

public static void PlayEvent(this FileImportLogAggregate aggregate, ImportLogCreatedEvent domainEvent)
Expand Down
Loading