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
8 changes: 4 additions & 4 deletions TransactionProcessor.Tests/Factories/ModelFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public void ModelFactory_Merchant_NullAddresses_IsConverted()
merchantResponse.MerchantId.ShouldBe(merchantModel.MerchantId);
merchantResponse.MerchantName.ShouldBe(merchantModel.MerchantName);

merchantResponse.Addresses.ShouldBeNull();
merchantResponse.Addresses.ShouldBeEmpty();

merchantResponse.Contacts.ShouldHaveSingleItem();
ContactResponse contactResponse = merchantResponse.Contacts.Single();
Expand Down Expand Up @@ -612,7 +612,7 @@ public void ModelFactory_Merchant_NullContacts_IsConverted()
addressResponse.Country.ShouldBe(merchantModel.Addresses.Single().Country);
addressResponse.PostalCode.ShouldBe(merchantModel.Addresses.Single().PostalCode);

merchantResponse.Contacts.ShouldBeNull();
merchantResponse.Contacts.ShouldBeEmpty();

merchantResponse.Devices.ShouldHaveSingleItem();
KeyValuePair<Guid, String> device = merchantResponse.Devices.Single();
Expand Down Expand Up @@ -659,7 +659,7 @@ public void ModelFactory_Merchant_NullDevices_IsConverted()
contactResponse.ContactName.ShouldBe(merchantModel.Contacts.Single().ContactName);
contactResponse.ContactPhoneNumber.ShouldBe(merchantModel.Contacts.Single().ContactPhoneNumber);

merchantResponse.Devices.ShouldBeNull();
merchantResponse.Devices.ShouldBeEmpty();

merchantResponse.Operators.ShouldHaveSingleItem();
MerchantOperatorResponse operatorDetails = merchantResponse.Operators.Single();
Expand Down Expand Up @@ -706,7 +706,7 @@ public void ModelFactory_Merchant_NullOperators_IsConverted()
device.Key.ShouldBe(merchantModel.Devices.Single().DeviceId);
device.Value.ShouldBe(merchantModel.Devices.Single().DeviceIdentifier);

merchantResponse.Operators.ShouldBeNull();
merchantResponse.Operators.ShouldBeEmpty();
}

[Fact]
Expand Down
105 changes: 65 additions & 40 deletions TransactionProcessor/Factories/ModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,30 +377,12 @@ private static TransactionProcessor.DataTransferObjects.Responses.Merchant.Settl

#endregion

public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merchant)
{
if (merchant == null)
{
return Result.Invalid("merchant cannot be null");
}

MerchantResponse merchantResponse = new MerchantResponse
{
EstateId = merchant.EstateId,
EstateReportingId = merchant.EstateReportingId,
MerchantId = merchant.MerchantId,
MerchantReportingId = merchant.MerchantReportingId,
MerchantName = merchant.MerchantName,
SettlementSchedule = ModelFactory.ConvertFrom(merchant.SettlementSchedule),
MerchantReference = merchant.Reference,
NextStatementDate = merchant.NextStatementDate
};
private static List<AddressResponse> ConvertFrom(List<Address> addresses) {

if (merchant.Addresses != null && merchant.Addresses.Any())
List<AddressResponse> result = new List<AddressResponse>();
if (addresses != null && addresses.Any())
{
merchantResponse.Addresses = new List<AddressResponse>();

merchant.Addresses.ForEach(a => merchantResponse.Addresses.Add(new AddressResponse
addresses.ForEach(a => result.Add(new AddressResponse
{
AddressId = a.AddressId,
Town = a.Town,
Expand All @@ -414,11 +396,15 @@ public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merc
}));
}

if (merchant.Contacts != null && merchant.Contacts.Any())
{
merchantResponse.Contacts = new List<ContactResponse>();
return result;
}

merchant.Contacts.ForEach(c => merchantResponse.Contacts.Add(new ContactResponse
private static List<ContactResponse> ConvertFrom(List<Contact> contacts) {
List<ContactResponse> result = new List<ContactResponse>();

if (contacts != null && contacts.Any())
{
contacts.ForEach(c => result.Add(new ContactResponse
{
ContactId = c.ContactId,
ContactPhoneNumber = c.ContactPhoneNumber,
Expand All @@ -427,21 +413,27 @@ public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merc
}));
}

if (merchant.Devices != null && merchant.Devices.Any())
{
merchantResponse.Devices = new Dictionary<Guid, String>();
return result;
}

foreach (Device device in merchant.Devices)
{
merchantResponse.Devices.Add(device.DeviceId, device.DeviceIdentifier);
public static Dictionary<Guid, String> ConvertFrom(List<Device> devices) {
Dictionary<Guid, String> result = new();

if (devices != null && devices.Any()) {
foreach (Device device in devices) {
result.Add(device.DeviceId, device.DeviceIdentifier);
}
}

if (merchant.Operators != null && merchant.Operators.Any())
{
merchantResponse.Operators = new List<MerchantOperatorResponse>();
return result;
}

private static List<MerchantOperatorResponse> ConvertFrom(List<Models.Merchant.Operator> operators) {
List<MerchantOperatorResponse> result = new List<MerchantOperatorResponse>();

merchant.Operators.ForEach(a => merchantResponse.Operators.Add(new MerchantOperatorResponse
if (operators != null && operators.Any())
{
operators.ForEach(a => result.Add(new MerchantOperatorResponse
{
Name = a.Name,
MerchantNumber = a.MerchantNumber,
Expand All @@ -451,11 +443,16 @@ public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merc
}));
}

if (merchant.Contracts != null && merchant.Contracts.Any())
return result;
}

private static List<MerchantContractResponse> ConvertFrom(List<Models.Merchant.Contract> contracts) {
List<MerchantContractResponse> result = new();

if (contracts != null && contracts.Any())
{
merchantResponse.Contracts = new List<MerchantContractResponse>();
merchant.Contracts.ForEach(mc => {
merchantResponse.Contracts.Add(new MerchantContractResponse()
contracts.ForEach(mc => {
result.Add(new MerchantContractResponse()
{
ContractId = mc.ContractId,
ContractProducts = mc.ContractProducts,
Expand All @@ -464,6 +461,34 @@ public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merc
});
}

return result;
}

public static Result<MerchantResponse> ConvertFrom(Models.Merchant.Merchant merchant)
{
if (merchant == null)
{
return Result.Invalid("merchant cannot be null");
}

MerchantResponse merchantResponse = new MerchantResponse
{
EstateId = merchant.EstateId,
EstateReportingId = merchant.EstateReportingId,
MerchantId = merchant.MerchantId,
MerchantReportingId = merchant.MerchantReportingId,
MerchantName = merchant.MerchantName,
SettlementSchedule = ModelFactory.ConvertFrom(merchant.SettlementSchedule),
MerchantReference = merchant.Reference,
NextStatementDate = merchant.NextStatementDate
};

merchantResponse.Addresses = ConvertFrom(merchant.Addresses);
merchantResponse.Contacts = ConvertFrom(merchant.Contacts);
merchantResponse.Devices = ConvertFrom(merchant.Devices);
merchantResponse.Operators = ConvertFrom(merchant.Operators);
merchantResponse.Contracts = ConvertFrom(merchant.Contracts);

return merchantResponse;
}
}
Expand Down
Loading