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 @@ -89,7 +89,7 @@ private FileProfileAggregateRoot CreateArchivedAggregate()
});
aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
FileFormatHandler = "UpdatedHandler"
FileFormatHandler = TestData.VoucherFileFormatHandler
});
aggregate.ArchiveProfile(TestData.FileProfileId);
return aggregate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void FileProfileAggregate_CreateUpdateAndUniquenessFlow_WorksAsExpected()

Result updateRequestType = aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
RequestType = "SafaricomTopupRequestUpdated"
RequestType = TestData.SafaricomRequestType
});

Result updateOperatorName = aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
Expand All @@ -63,17 +63,17 @@ public void FileProfileAggregate_CreateUpdateAndUniquenessFlow_WorksAsExpected()

Result updateFileFormatHandler = aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
FileFormatHandler = "SafaricomUpdatedFileFormatHandler"
FileFormatHandler = TestData.VoucherFileFormatHandler
});

Result duplicateNameCreate = aggregate.CreateProfile(this.CreateProfile(
Guid.Parse("33333333-3333-3333-3333-333333333333"),
"Voucher Profile",
"/home/txnproc/bulkfiles/duplicate-name",
"GammaRequest",
TestData.SafaricomRequestType,
"Gamma Operator",
LineTerminatorType.LineFeed,
"GammaHandler"));
TestData.SafaricomFileFormatHandler));

Result duplicateRequestTypeCreate = aggregate.CreateProfile(this.CreateProfile(
Guid.Parse("44444444-4444-4444-4444-444444444444"),
Expand All @@ -82,7 +82,7 @@ public void FileProfileAggregate_CreateUpdateAndUniquenessFlow_WorksAsExpected()
TestData.VoucherRequestType,
"Gamma Operator",
LineTerminatorType.LineFeed,
"GammaHandler"));
TestData.VoucherFileFormatHandler));

List<FileProcessor.Models.FileProfile> fileProfiles = aggregate.GetAllProfiles();
FileProcessor.Models.FileProfile updatedProfile = aggregate.GetProfile(TestData.FileProfileId);
Expand All @@ -105,10 +105,10 @@ public void FileProfileAggregate_CreateUpdateAndUniquenessFlow_WorksAsExpected()
updatedProfile.ShouldNotBeNull();
updatedProfile.Name.ShouldBe("Safaricom Profile Updated");
updatedProfile.ListeningDirectory.ShouldBe("/home/txnproc/bulkfiles/safaricom-updated");
updatedProfile.RequestType.ShouldBe("SafaricomTopupRequestUpdated");
updatedProfile.RequestType.ShouldBe(TestData.SafaricomRequestType);
updatedProfile.OperatorName.ShouldBe("Safaricom Updated");
updatedProfile.LineTerminator.ShouldBe("\r\n");
updatedProfile.FileFormatHandler.ShouldBe("SafaricomUpdatedFileFormatHandler");
updatedProfile.FileFormatHandler.ShouldBe(TestData.VoucherFileFormatHandler);
updatedProfile.ProcessedDirectory.ShouldBe("/home/txnproc/bulkfiles/safaricom-updated/processed");
updatedProfile.FailedDirectory.ShouldBe("/home/txnproc/bulkfiles/safaricom-updated/failed");

Expand Down Expand Up @@ -160,7 +160,7 @@ public void FileProfileAggregate_Archive_RetainsHistoricalVersionsButHidesActive
FileProcessor.Models.FileProfile originalVersion = aggregate.GetProfile(TestData.FileProfileId);
aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
FileFormatHandler = "UpdatedHandler"
FileFormatHandler = TestData.VoucherFileFormatHandler
});

Result archiveResult = aggregate.ArchiveProfile(TestData.FileProfileId);
Expand Down Expand Up @@ -293,7 +293,7 @@ public void FileProfileAggregate_Update_CreatesNewVersionAndPreservesPreviousVer

Result updateResult = aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
FileFormatHandler = "UpdatedHandler"
FileFormatHandler = TestData.VoucherFileFormatHandler
});

FileProcessor.Models.FileProfile updatedProfile = aggregate.GetProfile(TestData.FileProfileId);
Expand All @@ -305,7 +305,7 @@ public void FileProfileAggregate_Update_CreatesNewVersionAndPreservesPreviousVer
updateResult.IsSuccess.ShouldBeTrue();
updatedProfile.FileProfileVersionId.ShouldNotBe(originalProfile.FileProfileVersionId);
updatedProfile.FileProfileVersion.ShouldBe(2);
updatedProfile.FileFormatHandler.ShouldBe("UpdatedHandler");
updatedProfile.FileFormatHandler.ShouldBe(TestData.VoucherFileFormatHandler);
historicalProfile.FileProfileVersionId.ShouldBe(originalProfile.FileProfileVersionId);
historicalProfile.FileProfileVersion.ShouldBe(1);
historicalProfile.FileFormatHandler.ShouldBe(TestData.SafaricomFileFormatHandler);
Expand Down Expand Up @@ -359,10 +359,10 @@ public void FileProfileAggregate_Create_WithDuplicateName_IsRejected()
TestData.SafaricomFileProfileId,
TestData.SafaricomProfileName,
"/tmp/other",
"DifferentRequest",
TestData.VoucherRequestType,
"Other",
LineTerminatorType.LineFeed,
"OtherHandler"));
TestData.VoucherFileFormatHandler));

firstCreate.IsSuccess.ShouldBeTrue();
duplicateCreate.IsFailed.ShouldBeTrue();
Expand Down Expand Up @@ -427,13 +427,77 @@ public void FileProfileAggregate_Create_WithDuplicateRequestType_IsRejected()
TestData.SafaricomRequestType,
"Other",
LineTerminatorType.LineFeed,
"OtherHandler"));
TestData.SafaricomFileFormatHandler));

firstCreate.IsSuccess.ShouldBeTrue();
duplicateCreate.IsFailed.ShouldBeTrue();
duplicateCreate.Status.ShouldBe(ResultStatus.Invalid);
}

[Fact]
public void FileProfileAggregate_Create_WithUnsupportedProcessingConfiguration_IsRejected()
{
FileProfileAggregateRoot aggregate = FileProfileAggregateRoot.Create();

Result result = aggregate.CreateProfile(this.CreateProfile(
TestData.FileProfileId,
TestData.SafaricomProfileName,
TestData.SafaricomListeningDirectory,
"UnsupportedRequestType",
TestData.SafaricomOperatorIdentifier,
LineTerminatorType.LineFeed,
"UnsupportedFileFormatHandler"));

result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);
result.Errors.ShouldContain(error => error.Contains("Unsupported request type"));
result.Errors.ShouldContain(error => error.Contains("Unsupported file format handler"));
}

[Fact]
public void FileProfileAggregate_Create_WithWhitespaceAroundProcessingConfiguration_IsAccepted()
{
FileProfileAggregateRoot aggregate = FileProfileAggregateRoot.Create();

Result result = aggregate.CreateProfile(this.CreateProfile(
TestData.FileProfileId,
TestData.SafaricomProfileName,
TestData.SafaricomListeningDirectory,
$" {TestData.SafaricomRequestType} ",
TestData.SafaricomOperatorIdentifier,
LineTerminatorType.LineFeed,
$" {TestData.SafaricomFileFormatHandler} "));

result.IsSuccess.ShouldBeTrue();
aggregate.GetProfile(TestData.FileProfileId).RequestType.ShouldBe(TestData.SafaricomRequestType);
aggregate.GetProfile(TestData.FileProfileId).FileFormatHandler.ShouldBe(TestData.SafaricomFileFormatHandler);
}

[Fact]
public void FileProfileAggregate_Update_WithUnsupportedProcessingConfiguration_IsRejected()
{
FileProfileAggregateRoot aggregate = FileProfileAggregateRoot.Create();
aggregate.CreateProfile(this.CreateProfile(
TestData.FileProfileId,
TestData.SafaricomProfileName,
TestData.SafaricomListeningDirectory,
TestData.SafaricomRequestType,
TestData.SafaricomOperatorIdentifier,
LineTerminatorType.LineFeed,
TestData.SafaricomFileFormatHandler));

Result result = aggregate.UpdateProfile(TestData.FileProfileId, new UpdateFileProfileRequest
{
RequestType = "UnsupportedRequestType",
FileFormatHandler = "UnsupportedFileFormatHandler"
});

result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);
result.Errors.ShouldContain(error => error.Contains("Unsupported request type"));
result.Errors.ShouldContain(error => error.Contains("Unsupported file format handler"));
}

private CreateFileProfileRequest CreateProfile(Guid fileProfileId,
string name,
string listeningDirectory,
Expand Down
36 changes: 36 additions & 0 deletions FileProcessor.FileProfileAggregate/FileProfileAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
return Result.Success();
}

private static String? TrimWhitespaceExceptLineBreaks(String value)

Check warning on line 218 in FileProcessor.FileProfileAggregate/FileProfileAggregate.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 (String.IsNullOrEmpty(value))
return value;
Expand Down Expand Up @@ -342,6 +342,13 @@
return requiredFieldsResult;
}

Result supportedConfigurationResult = ValidateSupportedConfiguration(request.RequestType,
request.FileFormatHandler);
if (supportedConfigurationResult.IsFailed)
{
return supportedConfigurationResult;
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved
}

return aggregate.ValidateCreateUniqueness(request);
}

Expand All @@ -360,6 +367,13 @@
return proposedValuesResult;
}

Result supportedConfigurationResult = ValidateSupportedConfiguration(request.RequestType,
request.FileFormatHandler);
if (supportedConfigurationResult.IsFailed)
{
return supportedConfigurationResult;
}

return aggregate.ValidateUpdateUniqueness(fileProfileId, currentProfile, request);
}

Expand Down Expand Up @@ -389,7 +403,29 @@
: Result.Invalid(errors);
}

private static Result ValidateSupportedConfiguration(string requestType, string fileFormatHandler)
{
var errors = new List<string>();

string normalizedRequestType = requestType?.Trim();
string normalizedFileFormatHandler = fileFormatHandler?.Trim();

if (normalizedRequestType != null && FileProfileConfiguration.IsSupportedRequestType(normalizedRequestType) == false)
{
errors.Add($"Unsupported request type [{requestType}]");
}

if (normalizedFileFormatHandler != null && FileProfileConfiguration.IsSupportedFileFormatHandler(normalizedFileFormatHandler) == false)
{
errors.Add($"Unsupported file format handler [{fileFormatHandler}]");
}

return errors.Count == 0
? Result.Success()
: Result.Invalid(errors);
}

private static void AddIfInvalid(string? value, string errorMessage, ICollection<string> errors)

Check warning on line 428 in FileProcessor.FileProfileAggregate/FileProfileAggregate.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 (string.IsNullOrWhiteSpace(value))
{
Expand Down
23 changes: 23 additions & 0 deletions FileProcessor.FileProfileAggregate/FileProfileConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace FileProcessor.FileProfileAggregate;

public static class FileProfileConfiguration
{
public static string SafaricomTopupRequestType => "SafaricomTopupRequest";
public static string VoucherRequestType => "VoucherRequest";
public static string SafaricomFileFormatHandler => "SafaricomFileFormatHandler";
public static string VoucherFileFormatHandler => "VoucherFileFormatHandler";

public static bool IsSupportedRequestType(string requestType)
{
return String.Equals(requestType, SafaricomTopupRequestType, StringComparison.Ordinal) ||
String.Equals(requestType, VoucherRequestType, StringComparison.Ordinal);
}

public static bool IsSupportedFileFormatHandler(string fileFormatHandler)
{
return String.Equals(fileFormatHandler, SafaricomFileFormatHandler, StringComparison.Ordinal) ||
String.Equals(fileFormatHandler, VoucherFileFormatHandler, StringComparison.Ordinal);
}
}
19 changes: 12 additions & 7 deletions FileProcessor.IntegrationTests/Features/FileProfile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ Background:
Scenario: Create, update and list file profiles
When I create the following file profiles
| 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 | 1 | ProfileAHandler |
| Profile B | 22222222-2222-2222-2222-222222222222 | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | 2 | ProfileBHandler |
| Profile A | 11111111-1111-1111-1111-111111111111 | Profile A | /home/txnproc/bulkfiles/profile-a | SafaricomTopupRequest | Operator A | 1 | SafaricomFileFormatHandler |
| Profile B | 22222222-2222-2222-2222-222222222222 | Profile B | /home/txnproc/bulkfiles/profile-b | VoucherRequest | Operator B | 2 | VoucherFileFormatHandler |
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 | 2 | ProfileAHandlerUpdated |
| Profile A | Profile A Updated | /home/txnproc/bulkfiles/profile-a-updated | SafaricomTopupRequest | Operator A Updated | 2 | SafaricomFileFormatHandler |
Then the file profiles list should contain 2 items
And the file profiles should have the following values
| Alias | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Profile A | Profile A Updated | /home/txnproc/bulkfiles/profile-a-updated | ProfileARequestUpdated | Operator A Updated | 2 | ProfileAHandlerUpdated |
| Profile B | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | 2 | ProfileBHandler |
| Profile A | Profile A Updated | /home/txnproc/bulkfiles/profile-a-updated | SafaricomTopupRequest | Operator A Updated | 2 | SafaricomFileFormatHandler |
| Profile B | Profile B | /home/txnproc/bulkfiles/profile-b | VoucherRequest | Operator B | 2 | VoucherFileFormatHandler |

Scenario: Reject duplicate file profile name and request type
When I create the following file profiles
| 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 | 1 | ProfileAHandler |
| Profile B | 44444444-4444-4444-4444-444444444444 | Profile B | /home/txnproc/bulkfiles/profile-b | ProfileBRequest | Operator B | 2 | ProfileBHandler |
| Profile A | 33333333-3333-3333-3333-333333333333 | Profile A | /home/txnproc/bulkfiles/profile-a | SafaricomTopupRequest | Operator A | 1 | SafaricomFileFormatHandler |
| Profile B | 44444444-4444-4444-4444-444444444444 | Profile B | /home/txnproc/bulkfiles/profile-b | VoucherRequest | Operator B | 2 | VoucherFileFormatHandler |
And I try to create the following duplicate file profiles
| DuplicateType | BasedOn |
| Name | Profile A |
| RequestType | Profile B |
And the file profiles list should contain 2 items

Scenario: Reject unsupported processing configuration
When I try to create the following invalid file profiles
| Alias | FileProfileId | Name | ListeningDirectory | RequestType | OperatorName | LineTerminator | FileFormatHandler |
| Invalid Profile | 55555555-5555-5555-5555-555555555555 | Invalid Profile | /home/txnproc/bulkfiles/invalid | UnsupportedRequestType | Operator | 1 | UnsupportedFileFormatHandler |
Loading
Loading