Skip to content
Open
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 @@ -27,10 +27,6 @@ public async Task<Result> ProcessTransactionForFileLine(FileCommands.ProcessTran
}

public class DummyFileProcessorManager : IFileProcessorManager {
public async Task<Result> EnsureSeededFileProfiles(CancellationToken cancellationToken) {
return Result.Success();
}

public async Task<Result<List<FileProfileModel>>> GetAllFileProfiles(CancellationToken cancellationToken) {
return Result.Success();
}
Expand Down
5 changes: 0 additions & 5 deletions FileProcessor.BusinessLogic/Managers/FileProcessorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public async Task<Result<FileProfileModel>> GetFileProfile(Guid fileProfileId,
return await this.FileProfileManager.GetFileProfile(fileProfileId, cancellationToken);
}

public async Task<Result> EnsureSeededFileProfiles(CancellationToken cancellationToken)
{
return await this.FileProfileManager.EnsureSeededFileProfiles(cancellationToken);
}

private async Task<EstateManagementContext> GetContext(Guid estateId)
{
ResolvedDbContext<EstateManagementContext>? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, estateId.ToString());
Expand Down
74 changes: 8 additions & 66 deletions FileProcessor.BusinessLogic/Managers/FileProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,16 @@ namespace FileProcessor.BusinessLogic.Managers;

public class FileProfileManager : IFileProfileManager
{
private readonly List<FileProfileModel> SeedProfiles;

private readonly IAggregateRepository<FileProfileAggregateRoot, DomainEvent> FileProfileAggregateRepository;

public FileProfileManager(List<FileProfileModel> seedProfiles,
IAggregateRepository<FileProfileAggregateRoot, DomainEvent> fileProfileAggregateRepository)
public FileProfileManager(IAggregateRepository<FileProfileAggregateRoot, DomainEvent> fileProfileAggregateRepository)
{
this.SeedProfiles = seedProfiles;
this.FileProfileAggregateRepository = fileProfileAggregateRepository;
}

public async Task<Result> EnsureSeededFileProfiles(CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, true);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
}

return Result.Success();
}

public async Task<Result<List<FileProfileModel>>> GetAllFileProfiles(CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, false);
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
Expand All @@ -52,7 +37,7 @@ public async Task<Result<List<FileProfileModel>>> GetAllFileProfiles(Cancellatio

public async Task<Result<FileProfileModel>> GetFileProfile(Guid fileProfileId, CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, false);
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
Expand All @@ -69,7 +54,7 @@ public async Task<Result<FileProfileModel>> GetFileProfile(Guid fileProfileId, C

public async Task<Result<FileProfileModel>> CreateFileProfile(CreateFileProfileRequest request, CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, true);
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
Expand All @@ -93,7 +78,7 @@ public async Task<Result<FileProfileModel>> CreateFileProfile(CreateFileProfileR

public async Task<Result<FileProfileModel>> UpdateFileProfile(Guid fileProfileId, UpdateFileProfileRequest request, CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, true);
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
Expand All @@ -117,7 +102,7 @@ public async Task<Result<FileProfileModel>> UpdateFileProfile(Guid fileProfileId

public async Task<Result> ArchiveFileProfile(Guid fileProfileId, CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken, true);
Result<FileProfileAggregateRoot> aggregateResult = await this.LoadAggregate(cancellationToken);
if (aggregateResult.IsFailed)
{
return ResultHelpers.CreateFailure(aggregateResult);
Expand All @@ -132,7 +117,7 @@ public async Task<Result> ArchiveFileProfile(Guid fileProfileId, CancellationTok
return await this.FileProfileAggregateRepository.SaveChanges(aggregateResult.Data, cancellationToken);
}

private async Task<Result<FileProfileAggregateRoot>> LoadAggregate(CancellationToken cancellationToken, bool seedIfMissing)
private async Task<Result<FileProfileAggregateRoot>> LoadAggregate(CancellationToken cancellationToken)
{
Result<FileProfileAggregateRoot> aggregateResult = await this.FileProfileAggregateRepository.GetLatestVersion(FileProfileAggregateRoot.FileProfileCollectionId, cancellationToken);
if (aggregateResult.IsSuccess)
Expand All @@ -145,49 +130,6 @@ private async Task<Result<FileProfileAggregateRoot>> LoadAggregate(CancellationT
return ResultHelpers.CreateFailure<FileProfileAggregateRoot>(aggregateResult);
}

FileProfileAggregateRoot aggregate = FileProfileAggregateRoot.Create();
if (seedIfMissing && this.SeedProfiles.Any())
{
Result<FileProfileAggregateRoot> seeded = this.SeedAggregate(aggregate);
if (seeded.IsFailed)
{
return seeded;
}

Result saveResult = await this.FileProfileAggregateRepository.SaveChanges(seeded.Data, cancellationToken);
if (saveResult.IsFailed)
{
return ResultHelpers.CreateFailure<FileProfileAggregateRoot>(saveResult);
}

return Result.Success(seeded.Data);
}

return Result.Success(aggregate);
}

private Result<FileProfileAggregateRoot> SeedAggregate(FileProfileAggregateRoot aggregate)
{
foreach (FileProfileModel fileProfile in this.SeedProfiles)
{
CreateFileProfileRequest request = new CreateFileProfileRequest
{
FileProfileId = fileProfile.FileProfileId,
Name = fileProfile.Name,
ListeningDirectory = fileProfile.ListeningDirectory,
RequestType = fileProfile.RequestType,
OperatorName = fileProfile.OperatorName,
LineTerminator = fileProfile.LineTerminator,
FileFormatHandler = fileProfile.FileFormatHandler
};

Result createResult = aggregate.CreateProfile(request);
if (createResult.IsFailed)
{
return ResultHelpers.CreateFailure<FileProfileAggregateRoot>(createResult);
}
}

return Result.Success(aggregate);
return Result.Success(FileProfileAggregateRoot.Create());
}
}
2 changes: 0 additions & 2 deletions FileProcessor.BusinessLogic/Managers/IFileProcessorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public interface IFileProcessorManager

Task<Result<FileProfileModel>> GetFileProfile(Guid fileProfileId, CancellationToken cancellationToken);

Task<Result> EnsureSeededFileProfiles(CancellationToken cancellationToken);

Task<Result<List<Models.FileImportLog>>> GetFileImportLogs(Guid estateId, DateTime startDateTime, DateTime endDateTime, Guid? merchantId, CancellationToken cancellationToken);

Task<Result<Models.FileImportLog>> GetFileImportLog(Guid fileImportLogId, Guid estateId, Guid? merchantId, CancellationToken cancellationToken);
Expand Down
2 changes: 0 additions & 2 deletions FileProcessor.BusinessLogic/Managers/IFileProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace FileProcessor.BusinessLogic.Managers;

public interface IFileProfileManager
{
Task<Result> EnsureSeededFileProfiles(CancellationToken cancellationToken);

Task<Result<List<FileProfileModel>>> GetAllFileProfiles(CancellationToken cancellationToken);

Task<Result<FileProfileModel>> GetFileProfile(Guid fileProfileId, CancellationToken cancellationToken);
Expand Down
12 changes: 6 additions & 6 deletions FileProcessor.IntegrationTests/Features/FileProfile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Background:

Scenario: Create, update and list file profiles
When I create the following file profiles
| Alias | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | Profile A | /home/txnproc/bulkfiles/profile-a | ProfileARequest | Operator A | \n | ProfileAHandler |
| Profile B | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | \r\n | ProfileBHandler |
| Alias | FileProfileId | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | 11111111-1111-1111-1111-111111111111 | Profile A | /home/txnproc/bulkfiles/profile-a | ProfileARequest | Operator A | \n | ProfileAHandler |
| Profile B | 22222222-2222-2222-2222-222222222222 | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | \r\n | ProfileBHandler |
And I update the following file profiles
| Alias | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | Profile A Updated | /home/txnproc/bulkfiles/profile-a-updated | ProfileARequestUpdated | Operator A Updated | \r\n | ProfileAHandlerUpdated |
Expand All @@ -34,9 +34,9 @@ Scenario: Create, update and list file profiles

Scenario: Reject duplicate file profile name and request type
When I create the following file profiles
| Alias | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | Profile A | /home/txnproc/bulkfiles/profile-a | ProfileARequest | Operator A | \n | ProfileAHandler |
| Profile B | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | \r\n | ProfileBHandler |
| Alias | FileProfileId | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | 33333333-3333-3333-3333-333333333333 | Profile A | /home/txnproc/bulkfiles/profile-a | ProfileARequest | Operator A | \n | ProfileAHandler |
| Profile B | 44444444-4444-4444-4444-444444444444 | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | \r\n | ProfileBHandler |
And I try to create the following duplicate file profiles
| DuplicateType | BasedOn |
| Name | Profile A |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions FileProcessor.IntegrationTests/Features/FileProfileSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public async Task WhenICreateTheFollowingFileProfiles(DataTable table)
foreach (DataTableRow row in table.Rows)
{
string alias = row["Alias"];
CreateFileProfileRequest request = this.BuildCreateRequest(row);
Result<FileProfile> createResult = await this.FileProcessorSteps.CreateFileProfile(this.TestingContext.AccessToken, request, CancellationToken.None);

createResult.IsSuccess.ShouldBeTrue(createResult.Message);
createResult.Data.ShouldNotBeNull();

this.FileProfileIds[alias] = createResult.Data.FileProfileId;
await this.CreateProfile(alias, this.BuildCreateRequest(row));
}
}

Expand Down Expand Up @@ -126,7 +120,7 @@ private CreateFileProfileRequest BuildCreateRequest(DataTableRow row)
{
return new CreateFileProfileRequest
{
FileProfileId = Guid.NewGuid(),
FileProfileId = Guid.Parse(row["FileProfileId"]),
Name = row["Name"],
ListeningDirectory = row["ListeningDirectory"],
RequestType = row["RequestType"],
Expand All @@ -136,6 +130,16 @@ private CreateFileProfileRequest BuildCreateRequest(DataTableRow row)
};
}

private async Task CreateProfile(string alias, CreateFileProfileRequest request)
{
Result<FileProfile> createResult = await this.FileProcessorSteps.CreateFileProfile(this.TestingContext.AccessToken, request, CancellationToken.None);

createResult.IsSuccess.ShouldBeTrue(createResult.Message);
createResult.Data.ShouldNotBeNull();

this.FileProfileIds[alias] = createResult.Data.FileProfileId;
}

private UpdateFileProfileRequest BuildUpdateRequest(DataTableRow row)
{
return new UpdateFileProfileRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Background:
| ClientId |
| serviceClient |

When I create the following file profiles
| Alias | FileProfileId | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Safaricom Topup | B2A59ABF-293D-4A6B-B81B-7007503C3476 | Safaricom Topup | /home/txnproc/bulkfiles/safaricom | SafaricomTopupRequest | Safaricom | \n | SafaricomFileFormatHandler |
| Voucher Issue | 8806EDBC-3ED6-406B-9E5F-A9078356BE99 | Voucher Issue | /home/txnproc/bulkfiles/voucher | VoucherRequest | Voucher | \n | VoucherFileFormatHandler |

Given I have created the following estates
| EstateName |
| Test Estate 1 |
Expand Down Expand Up @@ -152,4 +157,4 @@ Scenario: Get File Import Log Details





Loading
Loading