Skip to content

Commit 98530f4

Browse files
Merge pull request #1583 from TransactionProcessing/bug/#1581_merchant_created_with_no_postcode
Refactor Address to enforce required fields and validation
2 parents 5c1b600 + ce03ddd commit 98530f4

24 files changed

Lines changed: 217 additions & 112 deletions

File tree

.github/workflows/prlinked.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

TransactionProcessor.Aggregates.Tests/MerchantAggregateTests.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void MerchantAggregate_AddAddress_AddressIsAdded(){
114114
aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated, TestData.AddressModel, TestData.ContactModel,
115115
TestData.SettlementScheduleModel);
116116

117-
Address newAddress = new(Guid.Empty, TestData.MerchantAddressLine1,
117+
Address newAddress = Address.Create(Guid.Empty, TestData.MerchantAddressLine1,
118118
TestData.MerchantAddressLine2,
119119
TestData.MerchantAddressLine3,
120120
TestData.MerchantAddressLine4,
@@ -577,7 +577,7 @@ public void MerchantAggregate_UpdateAddress_AddressIsAdded(){
577577
Merchant merchantModel = aggregate.GetMerchant();
578578
Address? address = merchantModel.Addresses.ShouldHaveSingleItem();
579579

580-
Address newAddress = new(address.AddressId, TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
580+
Address newAddress = Address.Create(address.AddressId, TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
581581
Result result = aggregate.UpdateAddress(newAddress);
582582
result.IsSuccess.ShouldBeTrue();
583583

@@ -598,7 +598,7 @@ public void MerchantAggregate_UpdateAddress_MerchantNotCreated_ErrorThrown()
598598
{
599599
MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId);
600600

601-
Address newAddress = new(Guid.NewGuid(), TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
601+
Address newAddress = Address.Create(Guid.NewGuid(), TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
602602
Result result = aggregate.UpdateAddress(newAddress);
603603
result.IsFailed.ShouldBeTrue();
604604
result.Status.ShouldBe(ResultStatus.Invalid);
@@ -610,7 +610,7 @@ public void MerchantAggregate_UpdateAddress_AddressNotFound_NoErrorThrown(){
610610
aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated, TestData.AddressModel, TestData.ContactModel,
611611
TestData.SettlementScheduleModel);
612612

613-
Address newAddress = new(Guid.NewGuid(), TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
613+
Address newAddress = Address.Create(Guid.NewGuid(), TestData.MerchantAddressLine1Update, TestData.MerchantAddressLine2Update, TestData.MerchantAddressLine3Update, TestData.MerchantAddressLine4Update, TestData.MerchantTownUpdate, TestData.MerchantRegionUpdate, TestData.MerchantPostalCodeUpdate, TestData.MerchantCountryUpdate);
614614

615615
Result result = aggregate.UpdateAddress(newAddress);
616616
result.IsSuccess.ShouldBeTrue();
@@ -625,7 +625,7 @@ public void MerchantAggregate_UpdateAddress_UpdatedAddressHasNotChanges_NoErrorT
625625
Merchant merchantModel = aggregate.GetMerchant();
626626
Address? address = merchantModel.Addresses.ShouldHaveSingleItem();
627627

628-
Address newAddress = new (address.AddressId, address.AddressLine1, address.AddressLine2, address.AddressLine3, address.AddressLine4, address.Town, address.Region, address.PostalCode, address.Country);
628+
Address newAddress = Address.Create(address.AddressId, address.AddressLine1, address.AddressLine2, address.AddressLine3, address.AddressLine4, address.Town, address.Region, address.PostalCode, address.Country);
629629

630630
Result result = aggregate.UpdateAddress(newAddress);
631631

@@ -845,5 +845,48 @@ public void MerchantAggregate_RemoveContract_And_ReAdd_ContractIsReAdded()
845845
contractModel.ContractId.ShouldBe(TestData.ContractId);
846846
contractModel.IsDeleted.ShouldBeFalse();
847847
}
848+
849+
[Theory]
850+
[InlineData("")]
851+
[InlineData(null)]
852+
public void Address_AddressLine1IsRequired_ErrorThrown(String addressLine1){
853+
Should.Throw<ArgumentException>(() => {
854+
Address.Create(Guid.NewGuid(), addressLine1, TestData.MerchantAddressLine2, TestData.MerchantAddressLine3, TestData.MerchantAddressLine4, TestData.MerchantTown, TestData.MerchantRegion, TestData.MerchantPostalCode, TestData.MerchantCountry);
855+
});
856+
}
857+
858+
[Theory]
859+
[InlineData("")]
860+
[InlineData(null)]
861+
public void Address_TownIsRequired_ErrorThrown(String town)
862+
{
863+
Should.Throw<ArgumentException>(() => {
864+
Address.Create(Guid.NewGuid(), TestData.MerchantAddressLine1, TestData.MerchantAddressLine2, TestData.MerchantAddressLine3, TestData.MerchantAddressLine4, town, TestData.MerchantRegion, TestData.MerchantPostalCode, TestData.MerchantCountry);
865+
});
866+
}
867+
868+
869+
[Theory]
870+
[InlineData("")]
871+
[InlineData(null)]
872+
public void Address_PostalCodeIsRequired_ErrorThrown(String postalCode)
873+
{
874+
Should.Throw<ArgumentException>(() => {
875+
Address.Create(Guid.NewGuid(), TestData.MerchantAddressLine1, TestData.MerchantAddressLine2, TestData.MerchantAddressLine3, TestData.MerchantAddressLine4, TestData.MerchantTown, TestData.MerchantRegion, postalCode, TestData.MerchantCountry);
876+
});
877+
}
878+
879+
880+
881+
[Theory]
882+
[InlineData("")]
883+
[InlineData(null)]
884+
public void Address_CountryIsRequired_ErrorThrown(String country)
885+
{
886+
Should.Throw<ArgumentException>(() => {
887+
Address.Create(Guid.NewGuid(), TestData.MerchantAddressLine1, TestData.MerchantAddressLine2, TestData.MerchantAddressLine3, TestData.MerchantAddressLine4, TestData.MerchantTown, TestData.MerchantRegion, TestData.MerchantPostalCode, country);
888+
});
889+
}
890+
848891
}
849892
}

TransactionProcessor.Aggregates/MerchantAggregate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public static Merchant GetMerchant(this MerchantAggregate aggregate)
379379
{
380380
merchantModel.Addresses = new();
381381
foreach (KeyValuePair<Guid, Address> aggregateAddress in aggregate.Addresses) {
382-
AddressModel address = new AddressModel(aggregateAddress.Key, aggregateAddress.Value.AddressLine1, aggregateAddress.Value.AddressLine2, aggregateAddress.Value.AddressLine3, aggregateAddress.Value.AddressLine4, aggregateAddress.Value.Town, aggregateAddress.Value.Region, aggregateAddress.Value.PostalCode, aggregateAddress.Value.Country);
382+
AddressModel address = AddressModel.Create(aggregateAddress.Key, aggregateAddress.Value.AddressLine1, aggregateAddress.Value.AddressLine2, aggregateAddress.Value.AddressLine3, aggregateAddress.Value.AddressLine4, aggregateAddress.Value.Town, aggregateAddress.Value.Region, aggregateAddress.Value.PostalCode, aggregateAddress.Value.Country);
383383

384384
merchantModel.Addresses.Add(address);
385385
}

TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public async Task<Result> CreateMerchant(MerchantCommands.CreateMerchantCommand
199199
MerchantAggregate merchantAggregate = merchantResult.Data;
200200

201201
// Build up the models for the Crete call
202-
Address address = new Address(Guid.Empty, command.RequestDto.Address.AddressLine1, command.RequestDto.Address.AddressLine2, command.RequestDto.Address.AddressLine3, command.RequestDto.Address.AddressLine4, command.RequestDto.Address.Town, command.RequestDto.Address.Region, command.RequestDto.Address.PostalCode, command.RequestDto.Address.Country);
202+
Address address = Address.Create(Guid.Empty, command.RequestDto.Address.AddressLine1, command.RequestDto.Address.AddressLine2, command.RequestDto.Address.AddressLine3, command.RequestDto.Address.AddressLine4, command.RequestDto.Address.Town, command.RequestDto.Address.Region, command.RequestDto.Address.PostalCode, command.RequestDto.Address.Country);
203203
Contact contact = new Contact(Guid.Empty, command.RequestDto.Contact.EmailAddress, command.RequestDto.Contact.ContactName, command.RequestDto.Contact.PhoneNumber);
204204
// Set the settlement schedule
205205
SettlementSchedule settlementSchedule = ConvertSettlementSchedule(command.RequestDto.SettlementSchedule);
@@ -504,7 +504,7 @@ public async Task<Result> AddMerchantAddress(MerchantCommands.AddMerchantAddress
504504
if (result.IsFailed)
505505
return ResultHelpers.CreateFailure(result);
506506

507-
Address address = new(Guid.Empty, command.RequestDto.AddressLine1, command.RequestDto.AddressLine2, command.RequestDto.AddressLine3, command.RequestDto.AddressLine4, command.RequestDto.Town, command.RequestDto.Region, command.RequestDto.PostalCode, command.RequestDto.Country);
507+
Address address = Address.Create(Guid.Empty, command.RequestDto.AddressLine1, command.RequestDto.AddressLine2, command.RequestDto.AddressLine3, command.RequestDto.AddressLine4, command.RequestDto.Town, command.RequestDto.Region, command.RequestDto.PostalCode, command.RequestDto.Country);
508508

509509
Result stateResult = merchantAggregate.AddAddress(address);
510510
if (stateResult.IsFailed)
@@ -542,7 +542,7 @@ public async Task<Result> UpdateMerchantAddress(MerchantCommands.UpdateMerchantA
542542
if (result.IsFailed)
543543
return ResultHelpers.CreateFailure(result);
544544

545-
Address address = new(command.AddressId, command.RequestDto.AddressLine1, command.RequestDto.AddressLine2, command.RequestDto.AddressLine3, command.RequestDto.AddressLine4, command.RequestDto.Town, command.RequestDto.Region, command.RequestDto.PostalCode, command.RequestDto.Country);
545+
Address address = Address.Create(command.AddressId, command.RequestDto.AddressLine1, command.RequestDto.AddressLine2, command.RequestDto.AddressLine3, command.RequestDto.AddressLine4, command.RequestDto.Town, command.RequestDto.Region, command.RequestDto.PostalCode, command.RequestDto.Country);
546546

547547
Result stateResult = merchantAggregate.UpdateAddress(address);
548548
if (stateResult.IsFailed)

TransactionProcessor.IntegrationTesting.Helpers/SpecflowExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,10 @@ public static List<CreateEstateRequest> ToCreateEstateRequests(this DataTableRow
10501050
"Region"),
10511051
Country =
10521052
ReqnrollTableHelper.GetStringRowValue(tableRow,
1053-
"Country")
1053+
"Country"),
1054+
PostalCode =
1055+
ReqnrollTableHelper.GetStringRowValue(tableRow,
1056+
"PostalCode")
10541057
},
10551058
SettlementSchedule = schedule,
10561059
MerchantId = Guid.NewGuid()

TransactionProcessor.IntegrationTests/Features/Contract.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Background:
4646
Scenario: Get Merchant Contracts
4747

4848
Given I create the following merchants
49-
| MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName |
50-
| Test Merchant 1 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 |
51-
| Test Merchant 2 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant2.co.uk | Test Estate 2 |
49+
| MerchantName | AddressLine1 | Town | Region | PostalCode | Country | ContactName | EmailAddress | EstateName |
50+
| Test Merchant 1 | Address Line 1 | TestTown | Test Region | TE57 1NG | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 |
51+
| Test Merchant 2 | Address Line 1 | TestTown | Test Region | TE57 2NG | United Kingdom | Test Contact 1 | testcontact1@merchant2.co.uk | Test Estate 2 |
5252

5353
Given I create a contract with the following values
5454
| EstateName | OperatorName | ContractDescription |

TransactionProcessor.IntegrationTests/Features/Contract.feature.cs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TransactionProcessor.IntegrationTests/Features/LogonTransaction.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ Background:
3434
| Test Estate 1 | Test Operator 1 |
3535

3636
Given I create the following merchants
37-
| MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName |
38-
| Test Merchant 1 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 |
39-
| Test Merchant 2 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 2 | testcontact2@merchant2.co.uk | Test Estate 1 |
40-
| Test Merchant 3 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 3 | testcontact3@merchant2.co.uk | Test Estate 1 |
41-
| Test Merchant 4 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 4 | testcontact4@merchant2.co.uk | Test Estate 1 |
42-
| Test Merchant 5 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 5 | testcontact5@merchant2.co.uk | Test Estate 1 |
43-
| Test Merchant 6 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 6 | testcontact6@merchant2.co.uk | Test Estate 1 |
44-
| Test Merchant 7 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 7 | testcontact7@merchant2.co.uk | Test Estate 1 |
37+
| MerchantName | AddressLine1 | Town | Region | PostalCode | Country | ContactName | EmailAddress | EstateName |
38+
| Test Merchant 1 | Address Line 1 | TestTown | Test Region | TE57 1NG | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 |
39+
| Test Merchant 2 | Address Line 1 | TestTown | Test Region | TE57 2NG | United Kingdom | Test Contact 2 | testcontact2@merchant2.co.uk | Test Estate 1 |
40+
| Test Merchant 3 | Address Line 1 | TestTown | Test Region | TE57 3NG | United Kingdom | Test Contact 3 | testcontact3@merchant2.co.uk | Test Estate 1 |
41+
| Test Merchant 4 | Address Line 1 | TestTown | Test Region | TE57 4NG | United Kingdom | Test Contact 4 | testcontact4@merchant2.co.uk | Test Estate 1 |
42+
| Test Merchant 5 | Address Line 1 | TestTown | Test Region | TE57 5NG | United Kingdom | Test Contact 5 | testcontact5@merchant2.co.uk | Test Estate 1 |
43+
| Test Merchant 6 | Address Line 1 | TestTown | Test Region | TE57 6NG | United Kingdom | Test Contact 6 | testcontact6@merchant2.co.uk | Test Estate 1 |
44+
| Test Merchant 7 | Address Line 1 | TestTown | Test Region | TE57 7NG | United Kingdom | Test Contact 7 | testcontact7@merchant2.co.uk | Test Estate 1 |
4545

4646
Given I have assigned the following operator to the merchants
4747
| OperatorName | MerchantName | MerchantNumber | TerminalNumber | EstateName |

0 commit comments

Comments
 (0)