From 9a93140ff2252060db3afd8ae8ff04f5161abce2 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Thu, 17 Aug 2023 22:08:17 +0100 Subject: [PATCH] Allow action id through API Client --- .../FactoryTests/ModelFactoryTests.cs | 2160 ++++++++--------- .../Factories/IModelFactory.cs | 71 - .../Factories/ModelFactory.cs | 251 +- .../Services/ApiClient.cs | 182 +- .../Services/IApiClient.cs | 64 +- .../FactoryTests/ViewModelFactoryTests.cs | 308 +-- .../Estate/Controllers/ContractController.cs | 84 +- .../Estate/Controllers/EstateController.cs | 24 +- .../Controllers/FileProcessingController.cs | 63 +- .../Estate/Controllers/HomeController.cs | 15 +- .../Estate/Controllers/MerchantController.cs | 99 +- .../Estate/Controllers/OperatorController.cs | 32 +- .../Estate/Controllers/ReportingController.cs | 17 +- .../Models/ContractProductTypeViewModel.cs | 3 + .../Bootstrapper/FactoryRegistry.cs | 17 - EstateAdministrationUI/Common/Helpers.cs | 17 + .../Factories/IViewModelFactory.cs | 61 - .../Factories/ViewModelFactory.cs | 98 +- EstateAdministrationUI/Startup.cs | 1 - 19 files changed, 1445 insertions(+), 2122 deletions(-) delete mode 100644 EstateAdministrationUI.BusinessLogic/Factories/IModelFactory.cs delete mode 100644 EstateAdministrationUI/Bootstrapper/FactoryRegistry.cs delete mode 100644 EstateAdministrationUI/Factories/IViewModelFactory.cs diff --git a/EstateAdministrationUI.BusinessLogic.Tests/FactoryTests/ModelFactoryTests.cs b/EstateAdministrationUI.BusinessLogic.Tests/FactoryTests/ModelFactoryTests.cs index 0cd6322..8015257 100644 --- a/EstateAdministrationUI.BusinessLogic.Tests/FactoryTests/ModelFactoryTests.cs +++ b/EstateAdministrationUI.BusinessLogic.Tests/FactoryTests/ModelFactoryTests.cs @@ -1,1538 +1,1288 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace EstateAdministrationUI.BusinessLogic.Tests.FactoryTests -{ +namespace EstateAdministrationUI.BusinessLogic.Tests.FactoryTests{ + using System; + using System.Collections.Generic; using System.Linq; - using Areas.Estate.Models; + using EstateAdministrationUI.Factories; using EstateManagement.DataTransferObjects.Requests; using EstateManagement.DataTransferObjects.Responses; using Factories; using FileProcessor.DataTransferObjects.Responses; - using Microsoft.AspNetCore.Identity; using Models; using Shouldly; using Testing; using TransactionProcessor.DataTransferObjects; using Xunit; + using CalculationType = EstateManagement.DataTransferObjects.CalculationType; + using FeeType = EstateManagement.DataTransferObjects.FeeType; + using FileLineProcessingResult = Models.FileLineProcessingResult; - public class ModelFactoryTests - { - [Theory] - [InlineData(SettlementSchedule.Immediate, EstateManagement.DataTransferObjects.SettlementSchedule.Immediate)] - [InlineData(SettlementSchedule.Weekly, EstateManagement.DataTransferObjects.SettlementSchedule.Weekly)] - [InlineData(SettlementSchedule.Monthly, EstateManagement.DataTransferObjects.SettlementSchedule.Monthly)] - public void ModelFactory_ConvertFrom_CreateMerchantModel_ModelIsConverted(SettlementSchedule settlementSchedule, - EstateManagement.DataTransferObjects.SettlementSchedule expectedSettlementSchedule) - { - CreateMerchantModel model = TestData.CreateMerchantModel(settlementSchedule); + public class ModelFactoryTests{ + #region Methods - ModelFactory modelFactory = new ModelFactory(); + [Fact] + public void ModelFactory_ConvertFrom_AddMerchantDeviceModel_IsConverted(){ + AddMerchantDeviceModel model = new AddMerchantDeviceModel{ + DeviceIdentifier = TestData.DeviceIdentifier + }; - CreateMerchantRequest request = modelFactory.ConvertFrom(model); + AddMerchantDeviceRequest apiRequest = ModelFactory.ConvertFrom(model); - request.Contact.ShouldNotBeNull(); - request.Contact.EmailAddress.ShouldBe(model.Contact.ContactEmailAddress); - request.Contact.PhoneNumber.ShouldBe(model.Contact.ContactPhoneNumber); - request.Contact.ContactName.ShouldBe(model.Contact.ContactName); + apiRequest.ShouldNotBeNull(); + apiRequest.DeviceIdentifier.ShouldBe(model.DeviceIdentifier); + } - request.Address.ShouldNotBeNull(); - request.Address.AddressLine1.ShouldBe(model.Address.AddressLine1); - request.Address.AddressLine2.ShouldBe(model.Address.AddressLine2); - request.Address.AddressLine3.ShouldBe(model.Address.AddressLine3); - request.Address.AddressLine4.ShouldBe(model.Address.AddressLine4); - request.Address.Town.ShouldBe(model.Address.Town); - request.Address.Region.ShouldBe(model.Address.Region); - request.Address.Country.ShouldBe(model.Address.Country); - request.Address.PostalCode.ShouldBe(model.Address.PostalCode); + [Fact] + public void ModelFactory_ConvertFrom_AddMerchantDeviceModel_ModelIsNull_ErrorThrown(){ + AddMerchantDeviceModel model = null; - request.Name.ShouldBe(model.MerchantName); - request.SettlementSchedule.ShouldBe(expectedSettlementSchedule); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); } [Fact] - public void ModelFactory_ConvertFrom_CreateMerchantModel_NullModel_ErrorThrown() - { - CreateMerchantModel model = null; + public void ModelFactory_ConvertFrom_AddMerchantDeviceResponse_IsConverted(){ + AddMerchantDeviceResponse response = new AddMerchantDeviceResponse{ + MerchantId = TestData.MerchantId, + DeviceId = TestData.DeviceId, + EstateId = TestData.EstateId + }; - ModelFactory modelFactory = new ModelFactory(); + AddMerchantDeviceResponseModel model = ModelFactory.ConvertFrom(response); - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + model.ShouldNotBeNull(); + model.MerchantId.ShouldBe(response.MerchantId); + model.DeviceId.ShouldBe(response.DeviceId); + model.EstateId.ShouldBe(response.EstateId); } [Fact] - public void ModelFactory_ConvertFrom_MakeMerchantDepositModel_ModelIsConverted() - { - MakeMerchantDepositModel model = TestData.MakeMerchantDepositModel; + public void ModelFactory_ConvertFrom_AddMerchantDeviceResponse_ResponseIsNull_ErrorThrown(){ + AddMerchantDeviceResponse response = null; - ModelFactory modelFactory = new ModelFactory(); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); + } - MakeMerchantDepositRequest request = modelFactory.ConvertFrom(model); + [Fact] + public void ModelFactory_ConvertFrom_AddProductToContractModel_NullModel_ErrorThrown(){ + AddProductToContractModel model = null; - request.Reference.ShouldBe(model.Reference); - request.DepositDateTime.ShouldBe(model.DepositDateTime); - request.Amount.ShouldBe(model.Amount); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); } [Fact] - public void ModelFactory_ConvertFrom_MakeMerchantDepositModel_NullModel_ErrorThrown() - { - MakeMerchantDepositModel model = null; + public void ModelFactory_ConvertFrom_AddProductToContractModel_WithNullValue_IsConverted(){ + AddProductToContractModel model = TestData.AddProductToContractModelWithNullValue; - ModelFactory modelFactory = new ModelFactory(); + AddProductToContractRequest request = ModelFactory.ConvertFrom(model); - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + request.Value.ShouldBeNull(); + request.ProductName.ShouldBe(model.ProductName); + request.DisplayText.ShouldBe(model.DisplayText); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_ModelIsConverted() - { - EstateResponse response = TestData.EstateResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_AddProductToContractModel_WithValue_IsConverted(){ + AddProductToContractModel model = TestData.AddProductToContractModelWithValue; - EstateModel model = modelFactory.ConvertFrom(response); + AddProductToContractRequest request = ModelFactory.ConvertFrom(model); - model.EstateName.ShouldBe(response.EstateName); - model.EstateId.ShouldBe(response.EstateId); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - operatorModel.ShouldNotBeNull(); - operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); - operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); - operatorModel.Name.ShouldBe(o.Name); - }); - response.SecurityUsers.ForEach(u => - { - SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); - securityUserModel.ShouldNotBeNull(); - securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); - }); + request.Value.ShouldNotBeNull(); + request.Value.ShouldBe(model.Value); + request.ProductName.ShouldBe(model.ProductName); + request.DisplayText.ShouldBe(model.DisplayText); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_NullOperators_ModelIsConverted() - { - EstateResponse response = TestData.EstateResponse; - response.Operators = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_AddProductToContractResponse_IsConverted(){ + AddProductToContractResponse response = TestData.AddProductToContractResponse; - EstateModel model = modelFactory.ConvertFrom(response); + AddProductToContractResponseModel model = ModelFactory.ConvertFrom(response); - model.EstateName.ShouldBe(response.EstateName); + model.ProductId.ShouldBe(response.ProductId); + model.ContractId.ShouldBe(response.ContractId); model.EstateId.ShouldBe(response.EstateId); - model.Operators.ShouldBeNull(); - response.SecurityUsers.ForEach(u => - { - SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); - securityUserModel.ShouldNotBeNull(); - securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); - }); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_EmptyOperators_ModelIsConverted() - { - EstateResponse response = TestData.EstateResponse; - response.Operators = new List(); + public void ModelFactory_ConvertFrom_AddProductToContractResponse_NullResponse_ErrorThrown(){ + AddProductToContractResponse model = null; - ModelFactory modelFactory = new ModelFactory(); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); + } - EstateModel model = modelFactory.ConvertFrom(response); + [Fact] + public void ModelFactory_ConvertFrom_AddTransactionFeeForProductToContractResponse_IsConverted(){ + AddTransactionFeeForProductToContractResponse response = TestData.AddTransactionFeeForProductToContractResponse; + + AddTransactionFeeToContractProductResponseModel model = ModelFactory.ConvertFrom(response); - model.EstateName.ShouldBe(response.EstateName); model.EstateId.ShouldBe(response.EstateId); - model.Operators.ShouldBeNull(); - response.SecurityUsers.ForEach(u => - { - SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); - securityUserModel.ShouldNotBeNull(); - securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); - }); + model.ProductId.ShouldBe(response.ProductId); + model.TransactionFeeId.ShouldBe(response.TransactionFeeId); + model.ContractId.ShouldBe(response.ContractId); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_NullSecurityUsers_ModelIsConverted() - { - EstateResponse response = TestData.EstateResponse; - response.SecurityUsers = null; + public void ModelFactory_ConvertFrom_AddTransactionFeeForProductToContractResponse_NullResponse_ErrorThrown(){ + AddTransactionFeeForProductToContractResponse response = null; - ModelFactory modelFactory = new ModelFactory(); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); + } - EstateModel model = modelFactory.ConvertFrom(response); + [Fact] + public void ModelFactory_ConvertFrom_AddTransactionFeeToContractProductModel_IsConverted(){ + AddTransactionFeeToContractProductModel model = TestData.AddTransactionFeeToContractProductModel; - model.EstateName.ShouldBe(response.EstateName); - model.EstateId.ShouldBe(response.EstateId); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - operatorModel.ShouldNotBeNull(); - operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); - operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); - operatorModel.Name.ShouldBe(o.Name); - }); - model.SecurityUsers.ShouldBeNull(); + AddTransactionFeeForProductToContractRequest request = ModelFactory.ConvertFrom(model); + + CalculationType calculationType = + Enum.Parse(model.CalculationType.ToString(), true); + FeeType feeType = Enum.Parse(model.FeeType.ToString(), true); + + request.Value.ShouldBe(model.Value); + request.Description.ShouldBe(model.Description); + request.FeeType.ShouldBe(feeType); + request.CalculationType.ShouldBe(calculationType); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_EmptySecurityUsers_ModelIsConverted() - { - EstateResponse response = TestData.EstateResponse; - response.SecurityUsers = new List(); - ModelFactory modelFactory = new ModelFactory(); - - EstateModel model = modelFactory.ConvertFrom(response); + public void ModelFactory_ConvertFrom_AddTransactionFeeToContractProductModel_NullModel_ErrorThrown(){ + AddTransactionFeeToContractProductModel model = null; - model.EstateName.ShouldBe(response.EstateName); - model.EstateId.ShouldBe(response.EstateId); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - operatorModel.ShouldNotBeNull(); - operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); - operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); - operatorModel.Name.ShouldBe(o.Name); - }); - model.SecurityUsers.ShouldBeNull(); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); } [Fact] - public void ModelFactory_ConvertFrom_EstateResponse_NullResponse_ErrorThrown() - { - EstateResponse response = null; + public void ModelFactory_ConvertFrom_AssignOperatorResponse_IsConverted(){ + AssignOperatorResponse response = new AssignOperatorResponse{ + EstateId = TestData.EstateId, + MerchantId = TestData.MerchantId, + OperatorId = TestData.OperatorId + }; - ModelFactory modelFactory = new ModelFactory(); + AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = ModelFactory.ConvertFrom(response); - Should.Throw(() => { modelFactory.ConvertFrom(response); }); + assignOperatorToMerchantResponseModel.ShouldNotBeNull(); + assignOperatorToMerchantResponseModel.EstateId.ShouldBe(response.EstateId); + assignOperatorToMerchantResponseModel.MerchantId.ShouldBe(response.MerchantId); + assignOperatorToMerchantResponseModel.OperatorId.ShouldBe(response.OperatorId); } - [Theory] - [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Immediate,SettlementSchedule.Immediate)] - [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Weekly, SettlementSchedule.Weekly)] - [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Monthly, SettlementSchedule.Monthly)] - public void ModelFactory_ConvertFrom_MerchantResponse_ModelIsConverted(EstateManagement.DataTransferObjects.SettlementSchedule settlementSchedule, - Models.SettlementSchedule expectedSettlementSchedule) - { - MerchantResponse response = TestData.MerchantResponse(settlementSchedule); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + [Fact] + public void ModelFactory_ConvertFrom_AssignOperatorResponse_ModelIsNull_ErrorThrown(){ + AssignOperatorResponse response = null; - ModelFactory modelFactory = new ModelFactory(); + AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = ModelFactory.ConvertFrom(response); - MerchantModel model = modelFactory.ConvertFrom(response, merchantBalanceResponse); + assignOperatorToMerchantResponseModel.ShouldBeNull(); + } - model.MerchantId.ShouldBe(response.MerchantId); - model.SettlementSchedule.ShouldBe(expectedSettlementSchedule); - model.MerchantName.ShouldBe(response.MerchantName); - model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); + [Fact] + public void ModelFactory_ConvertFrom_AssignOperatorToMerchantModel_IsConverted(){ + AssignOperatorToMerchantModel model = new AssignOperatorToMerchantModel{ + MerchantNumber = TestData.MerchantNumber, + TerminalNumber = TestData.TerminalNumber, + OperatorId = TestData.OperatorId + }; + AssignOperatorRequest assignOperatorRequest = ModelFactory.ConvertFrom(model); - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + assignOperatorRequest.ShouldNotBeNull(); + assignOperatorRequest.MerchantNumber.ShouldBe(model.MerchantNumber); + assignOperatorRequest.TerminalNumber.ShouldBe(model.TerminalNumber); + assignOperatorRequest.OperatorId.ShouldBe(model.OperatorId); + } + [Fact] + public void ModelFactory_ConvertFrom_AssignOperatorToMerchantModel_ModelIsNull_ErrorThrown(){ + AssignOperatorToMerchantModel model = null; - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + AssignOperatorRequest assignOperatorRequest = ModelFactory.ConvertFrom(model); + + assignOperatorRequest.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullBalance_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_ContractResponse_EmptyProducts_IsConverted(){ + ContractResponse response = TestData.ContractResponseEmptyProducts; - MerchantModel model = modelFactory.ConvertFrom(response, merchantBalanceResponse); + ContractModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.Description.ShouldBe(response.Description); + model.OperatorId.ShouldBe(response.OperatorId); + model.OperatorName.ShouldBe(response.OperatorName); + model.OperatorName.ShouldBe(response.OperatorName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); + model.NumberOfProducts.ShouldBe(0); + model.ContractProducts.ShouldBeEmpty(); + } - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + [Fact] + public void ModelFactory_ConvertFrom_ContractResponse_IsConverted(){ + ContractResponse response = TestData.ContractResponse; + ContractModel model = ModelFactory.ConvertFrom(response); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(0); - model.AvailableBalance.ShouldBe(0); + model.Description.ShouldBe(response.Description); + model.OperatorId.ShouldBe(response.OperatorId); + model.OperatorName.ShouldBe(response.OperatorName); + model.OperatorName.ShouldBe(response.OperatorName); + model.EstateId.ShouldBe(response.EstateId); + model.NumberOfProducts.ShouldBe(response.Products.Count); + model.ContractProducts.Count.ShouldBe(response.Products.Count); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullAddress_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Addresses = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_ContractResponse_NullProducts_IsConverted(){ + ContractResponse response = TestData.ContractResponseNullProducts; - MerchantModel model = modelFactory.ConvertFrom(response, merchantBalanceResponse); + ContractModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.Description.ShouldBe(response.Description); + model.OperatorId.ShouldBe(response.OperatorId); + model.OperatorName.ShouldBe(response.OperatorName); + model.OperatorName.ShouldBe(response.OperatorName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); - - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + model.NumberOfProducts.ShouldBe(0); + model.ContractProducts.ShouldBeEmpty(); + } + [Fact] + public void ModelFactory_ConvertFrom_ContractResponse_NullResponse_ErrorThrown(){ + ContractResponse response = null; - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.ShouldBeNull(); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_EmptyAddress_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Addresses = new List(); - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_ContractResponse_ProductWithEmptyFees_IsConverted(){ + ContractResponse response = TestData.ContractResponseProductWithEmptyFees; - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); + ContractModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.Description.ShouldBe(response.Description); + model.OperatorId.ShouldBe(response.OperatorId); + model.OperatorName.ShouldBe(response.OperatorName); + model.OperatorName.ShouldBe(response.OperatorName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); + model.NumberOfProducts.ShouldBe(response.Products.Count); + model.ContractProducts.Count.ShouldBe(response.Products.Count); + model.ContractProducts.Single().NumberOfTransactionFees.ShouldBe(0); + model.ContractProducts.Single().ContractProductTransactionFees.ShouldBeEmpty(); + } - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + [Fact] + public void ModelFactory_ConvertFrom_ContractResponse_ProductWithNullFees_IsConverted(){ + ContractResponse response = TestData.ContractResponseProductWithNullFees; + ContractModel model = ModelFactory.ConvertFrom(response); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.ShouldBeNull(); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + model.Description.ShouldBe(response.Description); + model.OperatorId.ShouldBe(response.OperatorId); + model.OperatorName.ShouldBe(response.OperatorName); + model.OperatorName.ShouldBe(response.OperatorName); + model.EstateId.ShouldBe(response.EstateId); + model.NumberOfProducts.ShouldBe(response.Products.Count); + model.ContractProducts.Count.ShouldBe(response.Products.Count); + model.ContractProducts.Single().NumberOfTransactionFees.ShouldBe(0); + model.ContractProducts.Single().ContractProductTransactionFees.ShouldBeEmpty(); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullContacts_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Contacts = null; + public void ModelFactory_ConvertFrom_ContractResponseList_IsConverted(){ + List responseList = new List{ + TestData.ContractResponse + }; - ModelFactory modelFactory = new ModelFactory(); + List model = ModelFactory.ConvertFrom(responseList); + model.ShouldHaveSingleItem(); + } - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); + [Fact] + public void ModelFactory_ConvertFrom_ContractResponseList_NullList_ErrorThrown(){ + List responseList = null; - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); - model.EstateId.ShouldBe(response.EstateId); - model.Contacts.ShouldBeNull(); + Should.Throw(() => { ModelFactory.ConvertFrom(responseList); }); + } - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + [Fact] + public void ModelFactory_ConvertFrom_CreateContractModel_IsConverted(){ + CreateContractModel model = TestData.CreateContractModel; + CreateContractRequest request = ModelFactory.ConvertFrom(model); - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + request.Description.ShouldBe(model.Description); + request.OperatorId.ShouldBe(model.OperatorId); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_EmptyContacts_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Contacts = new List(); + public void ModelFactory_ConvertFrom_CreateContractModel_NullModel_ErrorThrown(){ + CreateContractModel model = null; + + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); + } - ModelFactory modelFactory = new ModelFactory(); + [Fact] + public void ModelFactory_ConvertFrom_CreateContractResponse_IsConverted(){ + CreateContractResponse response = TestData.CreateContractResponse; - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); + CreateContractResponseModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.ShouldBeNull(); + model.OperatorId.ShouldBe(response.OperatorId); + model.ContractId.ShouldBe(response.ContractId); + } - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + [Fact] + public void ModelFactory_ConvertFrom_CreateContractResponse_NullResponse_ErrorThrown(){ + CreateContractResponse response = null; + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); + } - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + [Theory] + [InlineData(SettlementSchedule.Immediate, EstateManagement.DataTransferObjects.SettlementSchedule.Immediate)] + [InlineData(SettlementSchedule.Weekly, EstateManagement.DataTransferObjects.SettlementSchedule.Weekly)] + [InlineData(SettlementSchedule.Monthly, EstateManagement.DataTransferObjects.SettlementSchedule.Monthly)] + public void ModelFactory_ConvertFrom_CreateMerchantModel_ModelIsConverted(SettlementSchedule settlementSchedule, + EstateManagement.DataTransferObjects.SettlementSchedule expectedSettlementSchedule){ + CreateMerchantModel model = TestData.CreateMerchantModel(settlementSchedule); + + CreateMerchantRequest request = ModelFactory.ConvertFrom(model); + + request.Contact.ShouldNotBeNull(); + request.Contact.EmailAddress.ShouldBe(model.Contact.ContactEmailAddress); + request.Contact.PhoneNumber.ShouldBe(model.Contact.ContactPhoneNumber); + request.Contact.ContactName.ShouldBe(model.Contact.ContactName); + + request.Address.ShouldNotBeNull(); + request.Address.AddressLine1.ShouldBe(model.Address.AddressLine1); + request.Address.AddressLine2.ShouldBe(model.Address.AddressLine2); + request.Address.AddressLine3.ShouldBe(model.Address.AddressLine3); + request.Address.AddressLine4.ShouldBe(model.Address.AddressLine4); + request.Address.Town.ShouldBe(model.Address.Town); + request.Address.Region.ShouldBe(model.Address.Region); + request.Address.Country.ShouldBe(model.Address.Country); + request.Address.PostalCode.ShouldBe(model.Address.PostalCode); + + request.Name.ShouldBe(model.MerchantName); + request.SettlementSchedule.ShouldBe(expectedSettlementSchedule); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullOperators_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Operators = null; + public void ModelFactory_ConvertFrom_CreateMerchantModel_NullModel_ErrorThrown(){ + CreateMerchantModel model = null; + + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); + } + + [Fact] + public void ModelFactory_ConvertFrom_CreateMerchantResponse_ModelIsConverted(){ + CreateMerchantResponse response = TestData.CreateMerchantResponse; - ModelFactory modelFactory = new ModelFactory(); + CreateMerchantResponseModel model = ModelFactory.ConvertFrom(response); - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); - - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + model.AddressId.ShouldBe(response.AddressId); + model.ContactId.ShouldBe(response.ContactId); + } + [Fact] + public void ModelFactory_ConvertFrom_CreateMerchantResponse_NullResponse_ErrorThrown(){ + CreateMerchantResponse response = null; - model.Operators.ShouldBeNull(); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_EmptyOperators_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Operators = new List(); + public void ModelFactory_ConvertFrom_CreateOperatorModel_ModelIsConverted(){ + CreateOperatorModel model = TestData.CreateOperatorModel; - ModelFactory modelFactory = new ModelFactory(); + CreateOperatorRequest request = ModelFactory.ConvertFrom(model); - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); - - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); - model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); - - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + request.RequireCustomTerminalNumber.ShouldBe(model.RequireCustomTerminalNumber); + request.RequireCustomMerchantNumber.ShouldBe(model.RequireCustomMerchantNumber); + request.Name.ShouldBe(model.OperatorName); + } + [Fact] + public void ModelFactory_ConvertFrom_CreateOperatorModel_NullModel_ErrorThrown(){ + CreateOperatorModel model = null; - model.Operators.ShouldBeNull(); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullDevices_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Devices = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_CreateOperatorResponse_ModelIsConverted(){ + CreateOperatorResponse response = TestData.CreateOperatorResponse; - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); + CreateOperatorResponseModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.OperatorId.ShouldBe(response.OperatorId); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); + } - model.Devices.ShouldBeNull(); + [Fact] + public void ModelFactory_ConvertFrom_CreateOperatorResponse_NullResponse_ErrorThrown(){ + CreateOperatorResponse response = null; - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_EmptyDevices_ModelIsConverted() - { - MerchantResponse response = TestData.MerchantResponse(); - MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - response.Devices = new Dictionary(); - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_EstateResponse_EmptyOperators_ModelIsConverted(){ + EstateResponse response = TestData.EstateResponse; + response.Operators = new List(); - MerchantModel model = modelFactory.ConvertFrom(response,merchantBalanceResponse); + EstateModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.EstateName.ShouldBe(response.EstateName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); + model.Operators.ShouldBeNull(); + response.SecurityUsers.ForEach(u => { + SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); + securityUserModel.ShouldNotBeNull(); + securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); + }); + } - model.Devices.ShouldBeNull(); + [Fact] + public void ModelFactory_ConvertFrom_EstateResponse_EmptySecurityUsers_ModelIsConverted(){ + EstateResponse response = TestData.EstateResponse; + response.SecurityUsers = new List(); + + EstateModel model = ModelFactory.ConvertFrom(response); + model.EstateName.ShouldBe(response.EstateName); + model.EstateId.ShouldBe(response.EstateId); model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); + response.Operators.ForEach(o => { + EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + operatorModel.ShouldNotBeNull(); + operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); + operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); + operatorModel.Name.ShouldBe(o.Name); }); - model.Balance.ShouldBe(merchantBalanceResponse.Balance); - model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); + model.SecurityUsers.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponse_NullResponse_ErrorThrown() - { - MerchantResponse response = null; + public void ModelFactory_ConvertFrom_EstateResponse_ModelIsConverted(){ + EstateResponse response = TestData.EstateResponse; - ModelFactory modelFactory = new ModelFactory(); + EstateModel model = ModelFactory.ConvertFrom(response); - Should.Throw(() => { modelFactory.ConvertFrom(response,null); }); + model.EstateName.ShouldBe(response.EstateName); + model.EstateId.ShouldBe(response.EstateId); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + operatorModel.ShouldNotBeNull(); + operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); + operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); + operatorModel.Name.ShouldBe(o.Name); + }); + response.SecurityUsers.ForEach(u => { + SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); + securityUserModel.ShouldNotBeNull(); + securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); + }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponseList_ModelIsConverted() - { - List responseList = new List - { - TestData.MerchantResponse() - }; - - ModelFactory modelFactory = new ModelFactory(); - - List modelList = modelFactory.ConvertFrom(responseList); + public void ModelFactory_ConvertFrom_EstateResponse_NullOperators_ModelIsConverted(){ + EstateResponse response = TestData.EstateResponse; + response.Operators = null; - modelList.ShouldNotBeNull(); - modelList.ShouldNotBeEmpty(); - MerchantModel model = modelList.Single(); - MerchantResponse response = responseList.Single(); + EstateModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.MerchantName.ShouldBe(response.MerchantName); + model.EstateName.ShouldBe(response.EstateName); model.EstateId.ShouldBe(response.EstateId); - model.Contacts.Count.ShouldBe(response.Contacts.Count); - response.Contacts.ForEach(c => - { - // Find the contact in the view model - ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); - modelContact.ShouldNotBeNull(); - modelContact.ContactName.ShouldBe(c.ContactName); - modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); - modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); - }); - - model.Devices.Count.ShouldBe(response.Devices.Count); - foreach (KeyValuePair device in response.Devices) - { - response.Devices.ContainsKey(device.Key).ShouldBeTrue(); - response.Devices.ContainsValue(device.Value).ShouldBeTrue(); - } + model.Operators.ShouldBeNull(); + response.SecurityUsers.ForEach(u => { + SecurityUserModel securityUserModel = model.SecurityUsers.SingleOrDefault(su => su.SecurityUserId == u.SecurityUserId); + securityUserModel.ShouldNotBeNull(); + securityUserModel.EmailAddress.ShouldBe(u.EmailAddress); + }); + } + [Fact] + public void ModelFactory_ConvertFrom_EstateResponse_NullResponse_ErrorThrown(){ + EstateResponse response = null; - model.Operators.Count.ShouldBe(response.Operators.Count); - response.Operators.ForEach(o => - { - // Find the operator in the view model - MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); - modelOperator.ShouldNotBeNull(); - modelOperator.Name.ShouldBe(o.Name); - modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); - modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); - }); - model.Addresses.Count.ShouldBe(response.Addresses.Count); - response.Addresses.ForEach(a => - { - // Find the operator in the view model - AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); - modelAddress.ShouldNotBeNull(); - modelAddress.AddressLine1.ShouldBe(a.AddressLine1); - modelAddress.AddressLine2.ShouldBe(a.AddressLine2); - modelAddress.AddressLine3.ShouldBe(a.AddressLine3); - modelAddress.AddressLine4.ShouldBe(a.AddressLine4); - modelAddress.Country.ShouldBe(a.Country); - modelAddress.PostalCode.ShouldBe(a.PostalCode); - modelAddress.Region.ShouldBe(a.Region); - modelAddress.Town.ShouldBe(a.Town); - }); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_MerchantResponseList_NullResponse_ErrorThrown() - { - List responseList = null; + public void ModelFactory_ConvertFrom_EstateResponse_NullSecurityUsers_ModelIsConverted(){ + EstateResponse response = TestData.EstateResponse; + response.SecurityUsers = null; - ModelFactory modelFactory = new ModelFactory(); + EstateModel model = ModelFactory.ConvertFrom(response); - Should.Throw(() => { modelFactory.ConvertFrom(responseList); }); + model.EstateName.ShouldBe(response.EstateName); + model.EstateId.ShouldBe(response.EstateId); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + EstateOperatorModel operatorModel = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + operatorModel.ShouldNotBeNull(); + operatorModel.RequireCustomMerchantNumber.ShouldBe(o.RequireCustomMerchantNumber); + operatorModel.RequireCustomTerminalNumber.ShouldBe(o.RequireCustomTerminalNumber); + operatorModel.Name.ShouldBe(o.Name); + }); + model.SecurityUsers.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_CreateMerchantResponse_ModelIsConverted() - { - CreateMerchantResponse response = TestData.CreateMerchantResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_FileDetails_IsConverted(){ + FileDetails response = TestData.FileDetails; - CreateMerchantResponseModel model = modelFactory.ConvertFrom(response); + FileDetailsModel model = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); + model.ShouldNotBeNull(); + model.UserId.ShouldBe(response.UserId); model.EstateId.ShouldBe(response.EstateId); - model.AddressId.ShouldBe(response.AddressId); - model.ContactId.ShouldBe(response.ContactId); + model.FileId.ShouldBe(response.FileId); + model.FileImportLogId.ShouldBe(response.FileImportLogId); + model.FileLocation.ShouldBe(response.FileLocation); + model.FileProfileId.ShouldBe(response.FileProfileId); + model.MerchantId.ShouldBe(response.MerchantId); + model.ProcessingCompleted.ShouldBe(response.ProcessingCompleted); + model.ProcessingSummary.ShouldNotBeNull(); + model.ProcessingSummary.IgnoredLines.ShouldBe(response.ProcessingSummary.IgnoredLines); + model.ProcessingSummary.FailedLines.ShouldBe(response.ProcessingSummary.FailedLines); + model.ProcessingSummary.NotProcessedLines.ShouldBe(response.ProcessingSummary.NotProcessedLines); + model.ProcessingSummary.RejectedLines.ShouldBe(response.ProcessingSummary.RejectedLines); + model.ProcessingSummary.SuccessfullyProcessedLines.ShouldBe(response.ProcessingSummary.SuccessfullyProcessedLines); + model.ProcessingSummary.TotalLines.ShouldBe(response.ProcessingSummary.TotalLines); + model.FileLines.ShouldNotBeNull(); + model.FileLines.ShouldNotBeEmpty(); + + foreach (FileLine responseFileLine in response.FileLines){ + FileLineModel line = model.FileLines.SingleOrDefault(f => f.LineNumber == responseFileLine.LineNumber); + line.ShouldNotBeNull(); + line.LineData.ShouldBe(responseFileLine.LineData); + line.TransactionId.ShouldBe(responseFileLine.TransactionId); + line.RejectionReason.ShouldBe(responseFileLine.RejectionReason); + line.ProcessingResult.ToString().ShouldBe(responseFileLine.ProcessingResult.ToString()); + } } [Fact] - public void ModelFactory_ConvertFrom_CreateMerchantResponse_NullResponse_ErrorThrown() - { - CreateMerchantResponse response = null; + public void ModelFactory_ConvertFrom_FileDetails_NullDetails_IsConverted(){ + FileDetails response = null; - ModelFactory modelFactory = new ModelFactory(); + FileDetailsModel model = ModelFactory.ConvertFrom(response); - Should.Throw(() => { modelFactory.ConvertFrom(response); }); + model.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_MakeMerchantDepositResponse_ModelIsConverted() - { - MakeMerchantDepositResponse response = TestData.MakeMerchantDepositResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_FileImportLogList_IsConverted(){ + FileImportLogList response = TestData.FileImportLogList; - MakeMerchantDepositResponseModel model = modelFactory.ConvertFrom(response); + List modelList = ModelFactory.ConvertFrom(response); - model.MerchantId.ShouldBe(response.MerchantId); - model.EstateId.ShouldBe(response.EstateId); - model.DepositId.ShouldBe(response.DepositId); - } - - [Fact] - public void ModelFactory_ConvertFrom_MakeMerchantDepositResponse_NullResponse_ErrorThrown() - { - MakeMerchantDepositResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(response); }); - } - - [Fact] - public void ModelFactory_ConvertFrom_CreateOperatorModel_ModelIsConverted() - { - CreateOperatorModel model = TestData.CreateOperatorModel; - - ModelFactory modelFactory = new ModelFactory(); - - CreateOperatorRequest request = modelFactory.ConvertFrom(model); - - request.RequireCustomTerminalNumber.ShouldBe(model.RequireCustomTerminalNumber); - request.RequireCustomMerchantNumber.ShouldBe(model.RequireCustomMerchantNumber); - request.Name.ShouldBe(model.OperatorName); - } - - [Fact] - public void ModelFactory_ConvertFrom_CreateOperatorModel_NullModel_ErrorThrown() - { - CreateOperatorModel model = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(model); }); - } + modelList.ShouldNotBeNull(); + modelList.ShouldNotBeEmpty(); - [Fact] - public void ModelFactory_ConvertFrom_CreateOperatorResponse_ModelIsConverted() - { - CreateOperatorResponse response = TestData.CreateOperatorResponse; + foreach (FileImportLog responseFileImportLog in response.FileImportLogs){ + FileImportLogModel fileImportLogModel = modelList.SingleOrDefault(m => m.FileImportLogId == responseFileImportLog.FileImportLogId); - ModelFactory modelFactory = new ModelFactory(); + fileImportLogModel.ShouldNotBeNull(); + fileImportLogModel.ImportLogDateTime.ShouldBe(responseFileImportLog.ImportLogDateTime); + fileImportLogModel.ImportLogDate.ShouldBe(responseFileImportLog.ImportLogDate); + fileImportLogModel.ImportLogTime.ShouldBe(responseFileImportLog.ImportLogTime); + fileImportLogModel.FileCount.ShouldBe(responseFileImportLog.FileCount); + fileImportLogModel.Files.ShouldNotBeNull(); + fileImportLogModel.Files.ShouldNotBeEmpty(); - CreateOperatorResponseModel model = modelFactory.ConvertFrom(response); + foreach (FileImportLogFile responseFileImportLogFile in responseFileImportLog.Files){ + FileImportLogFileModel fileImportLogFileModel = fileImportLogModel.Files.SingleOrDefault(f => f.FileId == responseFileImportLogFile.FileId); - model.OperatorId.ShouldBe(response.OperatorId); - model.EstateId.ShouldBe(response.EstateId); + fileImportLogFileModel.ShouldNotBeNull(); + fileImportLogFileModel.FileId.ShouldBe(responseFileImportLogFile.FileId); + fileImportLogFileModel.FileImportLogId.ShouldBe(responseFileImportLogFile.FileImportLogId); + fileImportLogFileModel.FilePath.ShouldBe(responseFileImportLogFile.FilePath); + fileImportLogFileModel.FileProfileId.ShouldBe(responseFileImportLogFile.FileProfileId); + fileImportLogFileModel.FileUploadedDateTime.ShouldBe(responseFileImportLogFile.FileUploadedDateTime); + fileImportLogFileModel.MerchantId.ShouldBe(responseFileImportLogFile.MerchantId); + fileImportLogFileModel.OriginalFileName.ShouldBe(responseFileImportLogFile.OriginalFileName); + fileImportLogFileModel.UserId.ShouldBe(responseFileImportLogFile.UserId); + } + } } [Fact] - public void ModelFactory_ConvertFrom_CreateOperatorResponse_NullResponse_ErrorThrown() - { - CreateOperatorResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_FileImportLogList_ResponseIsNull_IsConverted(){ + FileImportLogList response = null; - Should.Throw(() => { modelFactory.ConvertFrom(response); }); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_CreateContractModel_IsConverted() - { - CreateContractModel model = TestData.CreateContractModel; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MakeMerchantDepositModel_ModelIsConverted(){ + MakeMerchantDepositModel model = TestData.MakeMerchantDepositModel; - CreateContractRequest request = modelFactory.ConvertFrom(model); + MakeMerchantDepositRequest request = ModelFactory.ConvertFrom(model); - request.Description.ShouldBe(model.Description); - request.OperatorId.ShouldBe(model.OperatorId); + request.Reference.ShouldBe(model.Reference); + request.DepositDateTime.ShouldBe(model.DepositDateTime); + request.Amount.ShouldBe(model.Amount); } [Fact] - public void ModelFactory_ConvertFrom_CreateContractModel_NullModel_ErrorThrown() - { - CreateContractModel model = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MakeMerchantDepositModel_NullModel_ErrorThrown(){ + MakeMerchantDepositModel model = null; - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + Should.Throw(() => { ModelFactory.ConvertFrom(model); }); } [Fact] - public void ModelFactory_ConvertFrom_CreateContractResponse_IsConverted() - { - CreateContractResponse response = TestData.CreateContractResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MakeMerchantDepositResponse_ModelIsConverted(){ + MakeMerchantDepositResponse response = TestData.MakeMerchantDepositResponse; - CreateContractResponseModel model = modelFactory.ConvertFrom(response); + MakeMerchantDepositResponseModel model = ModelFactory.ConvertFrom(response); + model.MerchantId.ShouldBe(response.MerchantId); model.EstateId.ShouldBe(response.EstateId); - model.OperatorId.ShouldBe(response.OperatorId); - model.ContractId.ShouldBe(response.ContractId); - } - - [Fact] - public void ModelFactory_ConvertFrom_CreateContractResponse_NullResponse_ErrorThrown() - { - CreateContractResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(response); }); + model.DepositId.ShouldBe(response.DepositId); } [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_IsConverted() - { - ContractResponse response = TestData.ContractResponse; - - ModelFactory modelFactory = new ModelFactory(); - - ContractModel model = modelFactory.ConvertFrom(response); + public void ModelFactory_ConvertFrom_MakeMerchantDepositResponse_NullResponse_ErrorThrown(){ + MakeMerchantDepositResponse response = null; - model.Description.ShouldBe(response.Description); - model.OperatorId.ShouldBe(response.OperatorId); - model.OperatorName.ShouldBe(response.OperatorName); - model.OperatorName.ShouldBe(response.OperatorName); - model.EstateId.ShouldBe(response.EstateId); - model.NumberOfProducts.ShouldBe(response.Products.Count); - model.ContractProducts.Count.ShouldBe(response.Products.Count); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_NullProducts_IsConverted() - { - ContractResponse response = TestData.ContractResponseNullProducts; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_EmptyResponse_ErrorThrown(){ + List response = new List(); - ContractModel model = modelFactory.ConvertFrom(response); + List model = ModelFactory.ConvertFrom(response); - model.Description.ShouldBe(response.Description); - model.OperatorId.ShouldBe(response.OperatorId); - model.OperatorName.ShouldBe(response.OperatorName); - model.OperatorName.ShouldBe(response.OperatorName); - model.EstateId.ShouldBe(response.EstateId); - model.NumberOfProducts.ShouldBe(0); - model.ContractProducts.ShouldBeEmpty(); + model.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_EmptyProducts_IsConverted() - { - ContractResponse response = TestData.ContractResponseEmptyProducts; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_ModelIsConverted(){ + List response = TestData.MerchantBalanceChangedEntryResponseList; - ContractModel model = modelFactory.ConvertFrom(response); + List model = ModelFactory.ConvertFrom(response); - model.Description.ShouldBe(response.Description); - model.OperatorId.ShouldBe(response.OperatorId); - model.OperatorName.ShouldBe(response.OperatorName); - model.OperatorName.ShouldBe(response.OperatorName); - model.EstateId.ShouldBe(response.EstateId); - model.NumberOfProducts.ShouldBe(0); - model.ContractProducts.ShouldBeEmpty(); + model.ShouldNotBeNull(); + model.ShouldNotBeEmpty(); + model.Count.ShouldBe(response.Count); } [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_ProductWithNullFees_IsConverted() - { - ContractResponse response = TestData.ContractResponseProductWithNullFees; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_NullResponse_ErrorThrown(){ + List response = null; - ContractModel model = modelFactory.ConvertFrom(response); + List model = ModelFactory.ConvertFrom(response); - model.Description.ShouldBe(response.Description); - model.OperatorId.ShouldBe(response.OperatorId); - model.OperatorName.ShouldBe(response.OperatorName); - model.OperatorName.ShouldBe(response.OperatorName); - model.EstateId.ShouldBe(response.EstateId); - model.NumberOfProducts.ShouldBe(response.Products.Count); - model.ContractProducts.Count.ShouldBe(response.Products.Count); - model.ContractProducts.Single().NumberOfTransactionFees.ShouldBe(0); - model.ContractProducts.Single().ContractProductTransactionFees.ShouldBeEmpty(); + model.ShouldBeNull(); } [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_ProductWithEmptyFees_IsConverted() - { - ContractResponse response = TestData.ContractResponseProductWithEmptyFees; + public void ModelFactory_ConvertFrom_MerchantBalanceResponse_IsConverted(){ + MerchantBalanceResponse response = new MerchantBalanceResponse{ + MerchantId = TestData.MerchantId, + AvailableBalance = TestData.AvailableBalance, + Balance = TestData.Balance, + EstateId = TestData.EstateId + }; - ModelFactory modelFactory = new ModelFactory(); + MerchantBalanceModel model = ModelFactory.ConvertFrom(response); - ContractModel model = modelFactory.ConvertFrom(response); - - model.Description.ShouldBe(response.Description); - model.OperatorId.ShouldBe(response.OperatorId); - model.OperatorName.ShouldBe(response.OperatorName); - model.OperatorName.ShouldBe(response.OperatorName); + model.ShouldNotBeNull(); + model.MerchantId.ShouldBe(response.MerchantId); + model.AvailableBalance.ShouldBe(response.AvailableBalance); + model.Balance.ShouldBe(response.Balance); model.EstateId.ShouldBe(response.EstateId); - model.NumberOfProducts.ShouldBe(response.Products.Count); - model.ContractProducts.Count.ShouldBe(response.Products.Count); - model.ContractProducts.Single().NumberOfTransactionFees.ShouldBe(0); - model.ContractProducts.Single().ContractProductTransactionFees.ShouldBeEmpty(); - } - - [Fact] - public void ModelFactory_ConvertFrom_ContractResponse_NullResponse_ErrorThrown() - { - ContractResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(response); }); - } - - [Fact] - public void ModelFactory_ConvertFrom_ContractResponseList_IsConverted() - { - List responseList = new List - { - TestData.ContractResponse - }; - - ModelFactory modelFactory = new ModelFactory(); - - List model = modelFactory.ConvertFrom(responseList); - model.ShouldHaveSingleItem(); - } - - [Fact] - public void ModelFactory_ConvertFrom_ContractResponseList_NullList_ErrorThrown() - { - List responseList = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(responseList); }); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddProductToContractModel_WithValue_IsConverted() - { - AddProductToContractModel model = TestData.AddProductToContractModelWithValue; - - ModelFactory modelFactory = new ModelFactory(); - - AddProductToContractRequest request = modelFactory.ConvertFrom(model); - - request.Value.ShouldNotBeNull(); - request.Value.ShouldBe(model.Value); - request.ProductName.ShouldBe(model.ProductName); - request.DisplayText.ShouldBe(model.DisplayText); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddProductToContractModel_WithNullValue_IsConverted() - { - AddProductToContractModel model = TestData.AddProductToContractModelWithNullValue; - - ModelFactory modelFactory = new ModelFactory(); - - AddProductToContractRequest request = modelFactory.ConvertFrom(model); - - request.Value.ShouldBeNull(); - request.ProductName.ShouldBe(model.ProductName); - request.DisplayText.ShouldBe(model.DisplayText); } [Fact] - public void ModelFactory_ConvertFrom_AddProductToContractModel_NullModel_ErrorThrown() - { - AddProductToContractModel model = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantBalanceResponse_ResponseIsNull_ErrorThrown(){ + MerchantBalanceResponse response = null; - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + Should.Throw(() => { ModelFactory.ConvertFrom(response); }); } [Fact] - public void ModelFactory_ConvertFrom_AddProductToContractResponse_IsConverted() - { - AddProductToContractResponse response = TestData.AddProductToContractResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_EmptyAddress_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Addresses = new List(); - AddProductToContractResponseModel model = modelFactory.ConvertFrom(response); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - model.ProductId.ShouldBe(response.ProductId); - model.ContractId.ShouldBe(response.ContractId); + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddProductToContractResponse_NullResponse_ErrorThrown() - { - AddProductToContractResponse model = null; + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - ModelFactory modelFactory = new ModelFactory(); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.ShouldBeNull(); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_AddTransactionFeeToContractProductModel_IsConverted() - { - AddTransactionFeeToContractProductModel model = TestData.AddTransactionFeeToContractProductModel; - - ModelFactory modelFactory = new ModelFactory(); - - AddTransactionFeeForProductToContractRequest request = modelFactory.ConvertFrom(model); - - EstateManagement.DataTransferObjects.CalculationType calculationType = - Enum.Parse(model.CalculationType.ToString(), true); - EstateManagement.DataTransferObjects.FeeType feeType = Enum.Parse(model.FeeType.ToString(), true); + public void ModelFactory_ConvertFrom_MerchantResponse_EmptyContacts_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Contacts = new List(); - request.Value.ShouldBe(model.Value); - request.Description.ShouldBe(model.Description); - request.FeeType.ShouldBe(feeType); - request.CalculationType.ShouldBe(calculationType); - } + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - [Fact] - public void ModelFactory_ConvertFrom_AddTransactionFeeToContractProductModel_NullModel_ErrorThrown() - { - AddTransactionFeeToContractProductModel model = null; + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.ShouldBeNull(); - ModelFactory modelFactory = new ModelFactory(); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - Should.Throw(() => { modelFactory.ConvertFrom(model); }); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_AddTransactionFeeForProductToContractResponse_IsConverted() - { - AddTransactionFeeForProductToContractResponse response = TestData.AddTransactionFeeForProductToContractResponse; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_EmptyDevices_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Devices = new Dictionary(); - AddTransactionFeeToContractProductResponseModel model = modelFactory.ConvertFrom(response); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); - model.ProductId.ShouldBe(response.ProductId); - model.TransactionFeeId.ShouldBe(response.TransactionFeeId); - model.ContractId.ShouldBe(response.ContractId); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddTransactionFeeForProductToContractResponse_NullResponse_ErrorThrown() - { - AddTransactionFeeForProductToContractResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(response); }); - } - - [Fact] - public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_ModelIsConverted() - { - List response = TestData.MerchantBalanceChangedEntryResponseList; - - ModelFactory modelFactory = new ModelFactory(); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - List model = modelFactory.ConvertFrom(response); + model.Devices.ShouldBeNull(); - model.ShouldNotBeNull(); - model.ShouldNotBeEmpty(); - model.Count.ShouldBe(response.Count); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_NullResponse_ErrorThrown() - { - List response = null; - - ModelFactory modelFactory = new ModelFactory(); - - List model = modelFactory.ConvertFrom(response); - - model.ShouldBeNull(); - } + public void ModelFactory_ConvertFrom_MerchantResponse_EmptyOperators_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Operators = new List(); - [Fact] - public void ModelFactory_ConvertFrom_MerchantBalanceHistoryResponseList_EmptyResponse_ErrorThrown() - { - List response = new List(); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - ModelFactory modelFactory = new ModelFactory(); + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - List model = modelFactory.ConvertFrom(response); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - model.ShouldBeNull(); + model.Operators.ShouldBeNull(); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } - [Fact] - public void ModelFactory_ConvertFrom_FileImportLogList_IsConverted() - { - FileImportLogList response = TestData.FileImportLogList; - - ModelFactory modelFactory = new ModelFactory(); - - List modelList = modelFactory.ConvertFrom(response); - - modelList.ShouldNotBeNull(); - modelList.ShouldNotBeEmpty(); - - foreach (FileImportLog responseFileImportLog in response.FileImportLogs) - { - FileImportLogModel fileImportLogModel = modelList.SingleOrDefault(m => m.FileImportLogId == responseFileImportLog.FileImportLogId); - - fileImportLogModel.ShouldNotBeNull(); - fileImportLogModel.ImportLogDateTime.ShouldBe(responseFileImportLog.ImportLogDateTime); - fileImportLogModel.ImportLogDate.ShouldBe(responseFileImportLog.ImportLogDate); - fileImportLogModel.ImportLogTime.ShouldBe(responseFileImportLog.ImportLogTime); - fileImportLogModel.FileCount.ShouldBe(responseFileImportLog.FileCount); - fileImportLogModel.Files.ShouldNotBeNull(); - fileImportLogModel.Files.ShouldNotBeEmpty(); - - foreach (FileImportLogFile responseFileImportLogFile in responseFileImportLog.Files) - { - FileImportLogFileModel fileImportLogFileModel = fileImportLogModel.Files.SingleOrDefault(f => f.FileId == responseFileImportLogFile.FileId); + [Theory] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Immediate, SettlementSchedule.Immediate)] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Weekly, SettlementSchedule.Weekly)] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Monthly, SettlementSchedule.Monthly)] + public void ModelFactory_ConvertFrom_MerchantResponse_ModelIsConverted(EstateManagement.DataTransferObjects.SettlementSchedule settlementSchedule, + SettlementSchedule expectedSettlementSchedule){ + MerchantResponse response = TestData.MerchantResponse(settlementSchedule); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; - fileImportLogFileModel.ShouldNotBeNull(); - fileImportLogFileModel.FileId.ShouldBe(responseFileImportLogFile.FileId); - fileImportLogFileModel.FileImportLogId.ShouldBe(responseFileImportLogFile.FileImportLogId); - fileImportLogFileModel.FilePath.ShouldBe(responseFileImportLogFile.FilePath); - fileImportLogFileModel.FileProfileId.ShouldBe(responseFileImportLogFile.FileProfileId); - fileImportLogFileModel.FileUploadedDateTime.ShouldBe(responseFileImportLogFile.FileUploadedDateTime); - fileImportLogFileModel.MerchantId.ShouldBe(responseFileImportLogFile.MerchantId); - fileImportLogFileModel.OriginalFileName.ShouldBe(responseFileImportLogFile.OriginalFileName); - fileImportLogFileModel.UserId.ShouldBe(responseFileImportLogFile.UserId); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - } + model.MerchantId.ShouldBe(response.MerchantId); + model.SettlementSchedule.ShouldBe(expectedSettlementSchedule); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); } + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_FileImportLogList_ResponseIsNull_IsConverted() - { - FileImportLogList response = null; - - ModelFactory modelFactory = new ModelFactory(); - - Should.Throw(() => { modelFactory.ConvertFrom(response); }); - } - - [Fact] - public void ModelFactory_ConvertFrom_FileDetails_IsConverted() - { - FileDetails response = TestData.FileDetails; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_NullAddress_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Addresses = null; - FileDetailsModel model = modelFactory.ConvertFrom(response); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - model.ShouldNotBeNull(); - model.UserId.ShouldBe(response.UserId); - model.EstateId.ShouldBe(response.EstateId); - model.FileId.ShouldBe(response.FileId); - model.FileImportLogId.ShouldBe(response.FileImportLogId); - model.FileLocation.ShouldBe(response.FileLocation); - model.FileProfileId.ShouldBe(response.FileProfileId); model.MerchantId.ShouldBe(response.MerchantId); - model.ProcessingCompleted.ShouldBe(response.ProcessingCompleted); - model.ProcessingSummary.ShouldNotBeNull(); - model.ProcessingSummary.IgnoredLines.ShouldBe(response.ProcessingSummary.IgnoredLines); - model.ProcessingSummary.FailedLines.ShouldBe(response.ProcessingSummary.FailedLines); - model.ProcessingSummary.NotProcessedLines.ShouldBe(response.ProcessingSummary.NotProcessedLines); - model.ProcessingSummary.RejectedLines.ShouldBe(response.ProcessingSummary.RejectedLines); - model.ProcessingSummary.SuccessfullyProcessedLines.ShouldBe(response.ProcessingSummary.SuccessfullyProcessedLines); - model.ProcessingSummary.TotalLines.ShouldBe(response.ProcessingSummary.TotalLines); - model.FileLines.ShouldNotBeNull(); - model.FileLines.ShouldNotBeEmpty(); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - foreach (FileLine responseFileLine in response.FileLines) - { - var line = model.FileLines.SingleOrDefault(f => f.LineNumber == responseFileLine.LineNumber); - line.ShouldNotBeNull(); - line.LineData.ShouldBe(responseFileLine.LineData); - line.TransactionId.ShouldBe(responseFileLine.TransactionId); - line.RejectionReason.ShouldBe(responseFileLine.RejectionReason); - line.ProcessingResult.ToString().ShouldBe(responseFileLine.ProcessingResult.ToString()); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); } + + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.ShouldBeNull(); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_FileDetails_NullDetails_IsConverted() - { - FileDetails response = null; - - ModelFactory modelFactory = new ModelFactory(); - - FileDetailsModel model = modelFactory.ConvertFrom(response); + public void ModelFactory_ConvertFrom_MerchantResponse_NullBalance_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = null; - model.ShouldBeNull(); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddMerchantDeviceModel_IsConverted() - { - AddMerchantDeviceModel model = new AddMerchantDeviceModel - { - DeviceIdentifier = TestData.DeviceIdentifier - }; + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - ModelFactory modelFactory = new ModelFactory(); + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - AddMerchantDeviceRequest apiRequest = modelFactory.ConvertFrom(model); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - apiRequest.ShouldNotBeNull(); - apiRequest.DeviceIdentifier.ShouldBe(model.DeviceIdentifier); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(0); + model.AvailableBalance.ShouldBe(0); } [Fact] - public void ModelFactory_ConvertFrom_AddMerchantDeviceModel_ModelIsNull_ErrorThrown() - { - AddMerchantDeviceModel model = null; + public void ModelFactory_ConvertFrom_MerchantResponse_NullContacts_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Contacts = null; + + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); + + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.ShouldBeNull(); - ModelFactory modelFactory = new ModelFactory(); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - Should.Throw(() => - { - modelFactory.ConvertFrom(model); - }); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_AddMerchantDeviceResponse_IsConverted() - { - AddMerchantDeviceResponse response = new AddMerchantDeviceResponse - { - MerchantId = TestData.MerchantId, - DeviceId = TestData.DeviceId, - EstateId = TestData.EstateId - }; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_NullDevices_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Devices = null; - AddMerchantDeviceResponseModel model = modelFactory.ConvertFrom(response); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - model.ShouldNotBeNull(); model.MerchantId.ShouldBe(response.MerchantId); - model.DeviceId.ShouldBe(response.DeviceId); + model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); - } - - [Fact] - public void ModelFactory_ConvertFrom_AddMerchantDeviceResponse_ResponseIsNull_ErrorThrown() - { - AddMerchantDeviceResponse response = null; + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - ModelFactory modelFactory = new ModelFactory(); + model.Devices.ShouldBeNull(); - Should.Throw(() => - { - modelFactory.ConvertFrom(response); - }); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } - //MerchantBalanceResponse - [Fact] - public void ModelFactory_ConvertFrom_MerchantBalanceResponse_IsConverted() - { - MerchantBalanceResponse response = new MerchantBalanceResponse - { - MerchantId = TestData.MerchantId, - AvailableBalance = TestData.AvailableBalance, - Balance = TestData.Balance, - EstateId = TestData.EstateId - }; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_NullOperators_ModelIsConverted(){ + MerchantResponse response = TestData.MerchantResponse(); + MerchantBalanceResponse merchantBalanceResponse = TestData.MerchantBalanceResponse; + response.Operators = null; - var model = modelFactory.ConvertFrom(response); + MerchantModel model = ModelFactory.ConvertFrom(response, merchantBalanceResponse); - model.ShouldNotBeNull(); model.MerchantId.ShouldBe(response.MerchantId); - model.AvailableBalance.ShouldBe(response.AvailableBalance); - model.Balance.ShouldBe(response.Balance); + model.MerchantName.ShouldBe(response.MerchantName); model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); + + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } + + model.Operators.ShouldBeNull(); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); + model.Balance.ShouldBe(merchantBalanceResponse.Balance); + model.AvailableBalance.ShouldBe(merchantBalanceResponse.AvailableBalance); } [Fact] - public void ModelFactory_ConvertFrom_MerchantBalanceResponse_ResponseIsNull_ErrorThrown() - { - MerchantBalanceResponse response = null; - - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponse_NullResponse_ErrorThrown(){ + MerchantResponse response = null; - Should.Throw(() => - { - modelFactory.ConvertFrom(response); - }); + Should.Throw(() => { ModelFactory.ConvertFrom(response, null); }); } [Fact] - public void ModelFactory_ConvertFrom_AssignOperatorToMerchantModel_IsConverted() - { - AssignOperatorToMerchantModel model = new AssignOperatorToMerchantModel - { - MerchantNumber = TestData.MerchantNumber, - TerminalNumber = TestData.TerminalNumber, - OperatorId = TestData.OperatorId - }; - ModelFactory modelFactory = new ModelFactory(); + public void ModelFactory_ConvertFrom_MerchantResponseList_ModelIsConverted(){ + List responseList = new List{ + TestData.MerchantResponse() + }; - AssignOperatorRequest assignOperatorRequest = modelFactory.ConvertFrom(model); + List modelList = ModelFactory.ConvertFrom(responseList); - assignOperatorRequest.ShouldNotBeNull(); - assignOperatorRequest.MerchantNumber.ShouldBe(model.MerchantNumber); - assignOperatorRequest.TerminalNumber.ShouldBe(model.TerminalNumber); - assignOperatorRequest.OperatorId.ShouldBe(model.OperatorId); - } + modelList.ShouldNotBeNull(); + modelList.ShouldNotBeEmpty(); + MerchantModel model = modelList.Single(); + MerchantResponse response = responseList.Single(); - [Fact] - public void ModelFactory_ConvertFrom_AssignOperatorToMerchantModel_ModelIsNull_ErrorThrown() - { - AssignOperatorToMerchantModel model = null; - ModelFactory modelFactory = new ModelFactory(); + model.MerchantId.ShouldBe(response.MerchantId); + model.MerchantName.ShouldBe(response.MerchantName); + model.EstateId.ShouldBe(response.EstateId); + model.Contacts.Count.ShouldBe(response.Contacts.Count); + response.Contacts.ForEach(c => { + // Find the contact in the view model + ContactModel modelContact = model.Contacts.SingleOrDefault(mc => mc.ContactId == c.ContactId); + modelContact.ShouldNotBeNull(); + modelContact.ContactName.ShouldBe(c.ContactName); + modelContact.ContactPhoneNumber.ShouldBe(c.ContactPhoneNumber); + modelContact.ContactEmailAddress.ShouldBe(c.ContactEmailAddress); + }); - AssignOperatorRequest assignOperatorRequest = modelFactory.ConvertFrom(model); + model.Devices.Count.ShouldBe(response.Devices.Count); + foreach (KeyValuePair device in response.Devices){ + response.Devices.ContainsKey(device.Key).ShouldBeTrue(); + response.Devices.ContainsValue(device.Value).ShouldBeTrue(); + } - assignOperatorRequest.ShouldBeNull(); + model.Operators.Count.ShouldBe(response.Operators.Count); + response.Operators.ForEach(o => { + // Find the operator in the view model + MerchantOperatorModel modelOperator = model.Operators.SingleOrDefault(mo => mo.OperatorId == o.OperatorId); + modelOperator.ShouldNotBeNull(); + modelOperator.Name.ShouldBe(o.Name); + modelOperator.TerminalNumber.ShouldBe(o.TerminalNumber); + modelOperator.MerchantNumber.ShouldBe(o.MerchantNumber); + }); + model.Addresses.Count.ShouldBe(response.Addresses.Count); + response.Addresses.ForEach(a => { + // Find the operator in the view model + AddressModel modelAddress = model.Addresses.SingleOrDefault(ma => ma.AddressId == a.AddressId); + modelAddress.ShouldNotBeNull(); + modelAddress.AddressLine1.ShouldBe(a.AddressLine1); + modelAddress.AddressLine2.ShouldBe(a.AddressLine2); + modelAddress.AddressLine3.ShouldBe(a.AddressLine3); + modelAddress.AddressLine4.ShouldBe(a.AddressLine4); + modelAddress.Country.ShouldBe(a.Country); + modelAddress.PostalCode.ShouldBe(a.PostalCode); + modelAddress.Region.ShouldBe(a.Region); + modelAddress.Town.ShouldBe(a.Town); + }); } [Fact] - public void ModelFactory_ConvertFrom_AssignOperatorResponse_IsConverted() - { - AssignOperatorResponse response= new AssignOperatorResponse - { - EstateId = TestData.EstateId, - MerchantId = TestData.MerchantId, - OperatorId = TestData.OperatorId - }; - ModelFactory modelFactory = new ModelFactory(); - - AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = modelFactory.ConvertFrom(response); + public void ModelFactory_ConvertFrom_MerchantResponseList_NullResponse_ErrorThrown(){ + List responseList = null; - assignOperatorToMerchantResponseModel.ShouldNotBeNull(); - assignOperatorToMerchantResponseModel.EstateId.ShouldBe(response.EstateId); - assignOperatorToMerchantResponseModel.MerchantId.ShouldBe(response.MerchantId); - assignOperatorToMerchantResponseModel.OperatorId.ShouldBe(response.OperatorId); + Should.Throw(() => { ModelFactory.ConvertFrom(responseList); }); } - [Fact] - public void ModelFactory_ConvertFrom_AssignOperatorResponse_ModelIsNull_ErrorThrown() - { - AssignOperatorResponse response = null; - ModelFactory modelFactory = new ModelFactory(); + [Theory] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.Failed, BusinessLogic.Models.FileLineProcessingResult.Failed)] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.Ignored, BusinessLogic.Models.FileLineProcessingResult.Ignored)] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.NotProcessed, BusinessLogic.Models.FileLineProcessingResult.NotProcessed)] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.Rejected, BusinessLogic.Models.FileLineProcessingResult.Rejected)] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.Successful, BusinessLogic.Models.FileLineProcessingResult.Successful)] + [InlineData(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult.Unknown, BusinessLogic.Models.FileLineProcessingResult.Unknown)] + [InlineData((FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult)99, BusinessLogic.Models.FileLineProcessingResult.Unknown)] - AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = modelFactory.ConvertFrom(response); + public void ViewModelFactory_ConvertFrom_FileLineProcessingResult_ResultConverted(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult processingResult, + BusinessLogic.Models.FileLineProcessingResult expectedResult) + { + FileLineProcessingResult result = ModelFactory.ConvertFrom(processingResult); + result.ShouldBe(expectedResult); + } - assignOperatorToMerchantResponseModel.ShouldBeNull(); + [Theory] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Immediate, Models.SettlementSchedule.Immediate)] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Monthly, Models.SettlementSchedule.Monthly)] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.NotSet, Models.SettlementSchedule.Immediate)] + [InlineData(EstateManagement.DataTransferObjects.SettlementSchedule.Weekly, Models.SettlementSchedule.Weekly)] + public void ModelFactory_ConvertFrom_SettlementSchedule_IsConverted(EstateManagement.DataTransferObjects.SettlementSchedule settlementSchedule, Models.SettlementSchedule expectedResult){ + SettlementSchedule result = ModelFactory.ConvertFrom(settlementSchedule); + result.ShouldBe(expectedResult); } + + #endregion } -} +} \ No newline at end of file diff --git a/EstateAdministrationUI.BusinessLogic/Factories/IModelFactory.cs b/EstateAdministrationUI.BusinessLogic/Factories/IModelFactory.cs deleted file mode 100644 index 972ff53..0000000 --- a/EstateAdministrationUI.BusinessLogic/Factories/IModelFactory.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace EstateAdministrationUI.BusinessLogic.Factories -{ - using System.Collections.Generic; - using EstateManagement.DataTransferObjects.Requests; - using EstateManagement.DataTransferObjects.Responses; - using FileProcessor.DataTransferObjects.Responses; - using Models; - using TransactionProcessor.DataTransferObjects; - - /// - /// - /// - public interface IModelFactory - { - #region Methods - - EstateModel ConvertFrom(EstateResponse source); - - MerchantBalanceModel ConvertFrom(MerchantBalanceResponse source); - - CreateOperatorRequest ConvertFrom(CreateOperatorModel source); - - CreateContractRequest ConvertFrom(CreateContractModel source); - - CreateOperatorResponseModel ConvertFrom(CreateOperatorResponse source); - - List ConvertFrom(List source); - - List ConvertFrom(List source); - - ContractModel ConvertFrom(ContractResponse source); - - MerchantModel ConvertFrom(MerchantResponse merchantResponse, MerchantBalanceResponse merchantBalanceResponse); - - CreateMerchantResponseModel ConvertFrom(CreateMerchantResponse source); - - CreateMerchantRequest ConvertFrom(CreateMerchantModel source); - - MakeMerchantDepositRequest ConvertFrom(MakeMerchantDepositModel source); - - List ConvertFrom(FileImportLogList source); - - FileImportLogModel ConvertFrom(FileImportLog source); - - MakeMerchantDepositResponseModel ConvertFrom(MakeMerchantDepositResponse source); - - CreateContractResponseModel ConvertFrom(CreateContractResponse source); - - AddProductToContractRequest ConvertFrom(AddProductToContractModel source); - - AddMerchantDeviceRequest ConvertFrom(AddMerchantDeviceModel source); - - AddMerchantDeviceResponseModel ConvertFrom(AddMerchantDeviceResponse source); - - AddProductToContractResponseModel ConvertFrom(AddProductToContractResponse source); - - AddTransactionFeeForProductToContractRequest ConvertFrom(AddTransactionFeeToContractProductModel source); - - AddTransactionFeeToContractProductResponseModel ConvertFrom(AddTransactionFeeForProductToContractResponse source); - - List ConvertFrom(List merchantBalanceHistory); - - FileDetailsModel ConvertFrom(FileDetails source); - - AssignOperatorRequest ConvertFrom(AssignOperatorToMerchantModel source); - - AssignOperatorToMerchantResponseModel ConvertFrom(AssignOperatorResponse source); - - #endregion - } -} \ No newline at end of file diff --git a/EstateAdministrationUI.BusinessLogic/Factories/ModelFactory.cs b/EstateAdministrationUI.BusinessLogic/Factories/ModelFactory.cs index dca2951..0617399 100644 --- a/EstateAdministrationUI.BusinessLogic/Factories/ModelFactory.cs +++ b/EstateAdministrationUI.BusinessLogic/Factories/ModelFactory.cs @@ -13,21 +13,12 @@ using FileLineProcessingResult = Models.FileLineProcessingResult; using SettlementSchedule = EstateManagement.DataTransferObjects.SettlementSchedule; using TransactionProcessor.DataTransferObjects; - /// - /// - /// - /// - public class ModelFactory : IModelFactory + + public static class ModelFactory { #region Methods - - /// - /// Converts from. - /// - /// The source. - /// - /// source - public EstateModel ConvertFrom(EstateResponse source) + + public static EstateModel ConvertFrom(EstateResponse source) { if (source == null) { @@ -38,19 +29,13 @@ public EstateModel ConvertFrom(EstateResponse source) { EstateId = source.EstateId, EstateName = source.EstateName, - Operators = this.ConvertOperators(source.Operators), - SecurityUsers = this.ConvertSecurityUsers(source.SecurityUsers) + Operators = ConvertOperators(source.Operators), + SecurityUsers = ConvertSecurityUsers(source.SecurityUsers) }; return model; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public MerchantBalanceModel ConvertFrom(MerchantBalanceResponse source) + public static MerchantBalanceModel ConvertFrom(MerchantBalanceResponse source) { if (source == null) { @@ -67,14 +52,8 @@ public MerchantBalanceModel ConvertFrom(MerchantBalanceResponse source) return model; } - - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateOperatorRequest ConvertFrom(CreateOperatorModel source) + + public static CreateOperatorRequest ConvertFrom(CreateOperatorModel source) { if (source == null) { @@ -91,13 +70,7 @@ public CreateOperatorRequest ConvertFrom(CreateOperatorModel source) return apiRequest; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateContractRequest ConvertFrom(CreateContractModel source) + public static CreateContractRequest ConvertFrom(CreateContractModel source) { if (source == null) { @@ -113,13 +86,7 @@ public CreateContractRequest ConvertFrom(CreateContractModel source) return apiRequest; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateOperatorResponseModel ConvertFrom(CreateOperatorResponse source) + public static CreateOperatorResponseModel ConvertFrom(CreateOperatorResponse source) { if (source == null) { @@ -135,13 +102,7 @@ public CreateOperatorResponseModel ConvertFrom(CreateOperatorResponse source) return createOperatorResponseModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateContractResponseModel ConvertFrom(CreateContractResponse source) + public static CreateContractResponseModel ConvertFrom(CreateContractResponse source) { if (source == null) { @@ -158,13 +119,7 @@ public CreateContractResponseModel ConvertFrom(CreateContractResponse source) return createOperatorResponseModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public AddProductToContractRequest ConvertFrom(AddProductToContractModel source) + public static AddProductToContractRequest ConvertFrom(AddProductToContractModel source) { if (source == null) { @@ -182,7 +137,7 @@ public AddProductToContractRequest ConvertFrom(AddProductToContractModel source) return addProductToContractRequest; } - public AddMerchantDeviceRequest ConvertFrom(AddMerchantDeviceModel source) + public static AddMerchantDeviceRequest ConvertFrom(AddMerchantDeviceModel source) { if (source == null) { @@ -197,13 +152,7 @@ public AddMerchantDeviceRequest ConvertFrom(AddMerchantDeviceModel source) return addMerchantDeviceRequest; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public AddMerchantDeviceResponseModel ConvertFrom(AddMerchantDeviceResponse source) + public static AddMerchantDeviceResponseModel ConvertFrom(AddMerchantDeviceResponse source) { if (source == null) { @@ -220,13 +169,7 @@ public AddMerchantDeviceResponseModel ConvertFrom(AddMerchantDeviceResponse sour return addMerchantDeviceResponseModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public AddProductToContractResponseModel ConvertFrom(AddProductToContractResponse source) + public static AddProductToContractResponseModel ConvertFrom(AddProductToContractResponse source) { if (source == null) { @@ -243,13 +186,7 @@ public AddProductToContractResponseModel ConvertFrom(AddProductToContractRespons return addProductToContractResponseModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public AddTransactionFeeForProductToContractRequest ConvertFrom(AddTransactionFeeToContractProductModel source) + public static AddTransactionFeeForProductToContractRequest ConvertFrom(AddTransactionFeeToContractProductModel source) { if (source == null) { @@ -271,13 +208,7 @@ public AddTransactionFeeForProductToContractRequest ConvertFrom(AddTransactionFe } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public AddTransactionFeeToContractProductResponseModel ConvertFrom(AddTransactionFeeForProductToContractResponse source) + public static AddTransactionFeeToContractProductResponseModel ConvertFrom(AddTransactionFeeForProductToContractResponse source) { if (source == null) { @@ -294,13 +225,8 @@ public AddTransactionFeeToContractProductResponseModel ConvertFrom(AddTransactio return addTransactionFeeToContractProductResponseModel; } - - /// - /// Converts from. - /// - /// The source. - /// - public List ConvertFrom(List source) + + public static List ConvertFrom(List source) { if (source == null || source.Any() == false) { @@ -331,12 +257,7 @@ public List ConvertFrom(List - /// Converts from. - /// - /// The source. - /// - public FileDetailsModel ConvertFrom(FileDetails source) + public static FileDetailsModel ConvertFrom(FileDetails source) { if (source == null) { @@ -371,7 +292,7 @@ public FileDetailsModel ConvertFrom(FileDetails source) { LineData = sourceFileLine.LineData, LineNumber = sourceFileLine.LineNumber, - ProcessingResult = this.ConvertFrom(sourceFileLine.ProcessingResult), + ProcessingResult = ConvertFrom(sourceFileLine.ProcessingResult), RejectionReason = sourceFileLine.RejectionReason, TransactionId = sourceFileLine.TransactionId }); @@ -380,12 +301,7 @@ public FileDetailsModel ConvertFrom(FileDetails source) return model; } - /// - /// Converts from. - /// - /// The source. - /// - public AssignOperatorRequest ConvertFrom(AssignOperatorToMerchantModel source) + public static AssignOperatorRequest ConvertFrom(AssignOperatorToMerchantModel source) { if (source == null) { @@ -402,12 +318,7 @@ public AssignOperatorRequest ConvertFrom(AssignOperatorToMerchantModel source) return assignOperatorRequest; } - /// - /// Converts from. - /// - /// The source. - /// - public AssignOperatorToMerchantResponseModel ConvertFrom(AssignOperatorResponse source) + public static AssignOperatorToMerchantResponseModel ConvertFrom(AssignOperatorResponse source) { if (source == null) { @@ -424,12 +335,7 @@ public AssignOperatorToMerchantResponseModel ConvertFrom(AssignOperatorResponse return assignOperatorToMerchantResponseModel; } - /// - /// Converts from. - /// - /// The dto. - /// - private FileLineProcessingResult ConvertFrom(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult dto) + public static FileLineProcessingResult ConvertFrom(FileProcessor.DataTransferObjects.Responses.FileLineProcessingResult dto) { FileLineProcessingResult model = FileLineProcessingResult.Unknown; switch (dto) @@ -460,13 +366,7 @@ private FileLineProcessingResult ConvertFrom(FileProcessor.DataTransferObjects.R return model; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public List ConvertFrom(List source) + public static List ConvertFrom(List source) { if (source == null) { @@ -477,21 +377,15 @@ public List ConvertFrom(List source) foreach (MerchantResponse merchantResponse in source) { - MerchantModel merchantModel = this.ConvertFrom(merchantResponse, null); + MerchantModel merchantModel = ConvertFrom(merchantResponse, null); models.Add(merchantModel); } return models; } - - /// - /// Converts from. - /// - /// The source. - /// - /// source - public List ConvertFrom(List source) + + public static List ConvertFrom(List source) { if (source == null) { @@ -502,7 +396,7 @@ public List ConvertFrom(List source) foreach (ContractResponse contractResponse in source) { - ContractModel contractModel = this.ConvertFrom(contractResponse); + ContractModel contractModel = ConvertFrom(contractResponse); models.Add(contractModel); } @@ -510,13 +404,7 @@ public List ConvertFrom(List source) return models; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public ContractModel ConvertFrom(ContractResponse source) + public static ContractModel ConvertFrom(ContractResponse source) { if (source == null) { @@ -575,13 +463,7 @@ public ContractModel ConvertFrom(ContractResponse source) return contractModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public MerchantModel ConvertFrom(MerchantResponse merchantResponse, MerchantBalanceResponse merchantBalanceResponse) + public static MerchantModel ConvertFrom(MerchantResponse merchantResponse, MerchantBalanceResponse merchantBalanceResponse) { if (merchantResponse == null) { @@ -655,13 +537,7 @@ public MerchantModel ConvertFrom(MerchantResponse merchantResponse, MerchantBala return merchantModel; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateMerchantResponseModel ConvertFrom(CreateMerchantResponse source) + public static CreateMerchantResponseModel ConvertFrom(CreateMerchantResponse source) { if (source == null) { @@ -677,13 +553,7 @@ public CreateMerchantResponseModel ConvertFrom(CreateMerchantResponse source) }; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public CreateMerchantRequest ConvertFrom(CreateMerchantModel source) + public static CreateMerchantRequest ConvertFrom(CreateMerchantModel source) { if (source == null) { @@ -716,7 +586,7 @@ public CreateMerchantRequest ConvertFrom(CreateMerchantModel source) return apiRequest; } - private SettlementSchedule ConvertFrom(Models.SettlementSchedule settlementSchedule) + public static SettlementSchedule ConvertFrom(Models.SettlementSchedule settlementSchedule) { return settlementSchedule switch { @@ -726,7 +596,7 @@ private SettlementSchedule ConvertFrom(Models.SettlementSchedule settlementSched }; } - private Models.SettlementSchedule ConvertFrom(SettlementSchedule settlementSchedule) + public static Models.SettlementSchedule ConvertFrom(SettlementSchedule settlementSchedule) { return settlementSchedule switch { @@ -737,13 +607,7 @@ private Models.SettlementSchedule ConvertFrom(SettlementSchedule settlementSched }; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public MakeMerchantDepositRequest ConvertFrom(MakeMerchantDepositModel source) + public static MakeMerchantDepositRequest ConvertFrom(MakeMerchantDepositModel source) { if (source == null) { @@ -760,13 +624,7 @@ public MakeMerchantDepositRequest ConvertFrom(MakeMerchantDepositModel source) return apiRequest; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public List ConvertFrom(FileImportLogList source) + public static List ConvertFrom(FileImportLogList source) { if (source == null) { @@ -779,19 +637,14 @@ public List ConvertFrom(FileImportLogList source) { foreach (FileImportLog sourceFileImportLog in source.FileImportLogs) { - models.Add(this.ConvertFrom(sourceFileImportLog)); + models.Add(ConvertFrom(sourceFileImportLog)); } } return models; } - /// - /// Converts from. - /// - /// The source. - /// - public FileImportLogModel ConvertFrom(FileImportLog source) + public static FileImportLogModel ConvertFrom(FileImportLog source) { FileImportLogModel model = new FileImportLogModel { @@ -824,13 +677,7 @@ public FileImportLogModel ConvertFrom(FileImportLog source) return model; } - /// - /// Converts from. - /// - /// The source. - /// - /// source - public MakeMerchantDepositResponseModel ConvertFrom(MakeMerchantDepositResponse source) + public static MakeMerchantDepositResponseModel ConvertFrom(MakeMerchantDepositResponse source) { if (source == null) { @@ -845,13 +692,7 @@ public MakeMerchantDepositResponseModel ConvertFrom(MakeMerchantDepositResponse }; } - /// - /// Converts the operators. - /// - /// The estate response operators. - /// - /// estateResponseOperators - private List ConvertOperators(List estateResponseOperators) + public static List ConvertOperators(List estateResponseOperators) { if (estateResponseOperators == null || estateResponseOperators.Any() == false) { @@ -873,13 +714,7 @@ private List ConvertOperators(List return models; } - /// - /// Converts the security users. - /// - /// The estate response security users. - /// - /// estateResponseSecurityUsers - private List ConvertSecurityUsers(List estateResponseSecurityUsers) + public static List ConvertSecurityUsers(List estateResponseSecurityUsers) { if (estateResponseSecurityUsers == null || estateResponseSecurityUsers.Any() == false) { diff --git a/EstateAdministrationUI.BusinessLogic/Services/ApiClient.cs b/EstateAdministrationUI.BusinessLogic/Services/ApiClient.cs index c34b56c..cb8dd23 100644 --- a/EstateAdministrationUI.BusinessLogic/Services/ApiClient.cs +++ b/EstateAdministrationUI.BusinessLogic/Services/ApiClient.cs @@ -1,10 +1,8 @@ namespace EstateAdministrationUI.Services{ using System; using System.Collections.Generic; - using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; - using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using BusinessLogic.Factories; @@ -31,8 +29,6 @@ public class ApiClient : IApiClient{ private readonly IFileProcessorClient FileProcessorClient; - private readonly IModelFactory ModelFactory; - private readonly ITransactionProcessorClient TransactionProcessorClient; #endregion @@ -41,12 +37,10 @@ public class ApiClient : IApiClient{ public ApiClient(IEstateClient estateClient, IFileProcessorClient fileProcessorClient, - ITransactionProcessorClient transactionProcessorClient, - IModelFactory modelFactory){ + ITransactionProcessorClient transactionProcessorClient){ this.EstateClient = estateClient; this.FileProcessorClient = fileProcessorClient; this.TransactionProcessorClient = transactionProcessorClient; - this.ModelFactory = modelFactory; } #endregion @@ -54,18 +48,17 @@ public ApiClient(IEstateClient estateClient, #region Methods public async Task AddDeviceToMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, AddMerchantDeviceModel merchantDeviceModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - AddMerchantDeviceRequest apiRequest = this.ModelFactory.ConvertFrom(merchantDeviceModel); + AddMerchantDeviceRequest apiRequest = ModelFactory.ConvertFrom(merchantDeviceModel); AddMerchantDeviceResponse apiResponse = await this.EstateClient.AddDeviceToMerchant(accessToken, estateId, merchantId, apiRequest, cancellationToken); - AddMerchantDeviceResponseModel addMerchantDeviceResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + AddMerchantDeviceResponseModel addMerchantDeviceResponseModel = ModelFactory.ConvertFrom(apiResponse); return addMerchantDeviceResponseModel; } @@ -76,18 +69,17 @@ public async Task AddDeviceToMerchant(String acc } public async Task AddProductToContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, AddProductToContractModel addProductToContractModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - AddProductToContractRequest apiRequest = this.ModelFactory.ConvertFrom(addProductToContractModel); + AddProductToContractRequest apiRequest = ModelFactory.ConvertFrom(addProductToContractModel); AddProductToContractResponse apiResponse = await this.EstateClient.AddProductToContract(accessToken, estateId, contractId, apiRequest, cancellationToken); - AddProductToContractResponseModel addProductToContractResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + AddProductToContractResponseModel addProductToContractResponseModel = ModelFactory.ConvertFrom(apiResponse); return addProductToContractResponseModel; } @@ -98,21 +90,20 @@ public async Task AddProductToContract(String } public async Task AddTransactionFeeToContractProduct(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, Guid contractProductId, AddTransactionFeeToContractProductModel addTransactionFeeToContractProductModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - AddTransactionFeeForProductToContractRequest apiRequest = this.ModelFactory.ConvertFrom(addTransactionFeeToContractProductModel); + AddTransactionFeeForProductToContractRequest apiRequest = ModelFactory.ConvertFrom(addTransactionFeeToContractProductModel); AddTransactionFeeForProductToContractResponse apiResponse = await this.EstateClient.AddTransactionFeeForProductToContract(accessToken, estateId, contractId, contractProductId, apiRequest, cancellationToken); - AddTransactionFeeToContractProductResponseModel addTransactionFeeToContractProductResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + AddTransactionFeeToContractProductResponseModel addTransactionFeeToContractProductResponseModel = ModelFactory.ConvertFrom(apiResponse); return addTransactionFeeToContractProductResponseModel; } @@ -123,18 +114,17 @@ public async Task AddTransactio } public async Task AssignOperatorToMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, AssignOperatorToMerchantModel assignOperatorToMerchantModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - AssignOperatorRequest apiRequest = this.ModelFactory.ConvertFrom(assignOperatorToMerchantModel); + AssignOperatorRequest apiRequest = ModelFactory.ConvertFrom(assignOperatorToMerchantModel); AssignOperatorResponse apiResponse = await this.EstateClient.AssignOperatorToMerchant(accessToken, estateId, merchantId, apiRequest, cancellationToken); - AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + AssignOperatorToMerchantResponseModel assignOperatorToMerchantResponseModel = ModelFactory.ConvertFrom(apiResponse); return assignOperatorToMerchantResponseModel; } @@ -145,17 +135,16 @@ public async Task AssignOperatorToMerchan } public async Task CreateContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateContractModel createContractModel, CancellationToken cancellationToken){ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - try{ - CreateContractRequest apiRequest = this.ModelFactory.ConvertFrom(createContractModel); + CreateContractRequest apiRequest = ModelFactory.ConvertFrom(createContractModel); CreateContractResponse apiResponse = await this.EstateClient.CreateContract(accessToken, estateId, apiRequest, cancellationToken); - CreateContractResponseModel createContractResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + CreateContractResponseModel createContractResponseModel = ModelFactory.ConvertFrom(apiResponse); return createContractResponseModel; } @@ -166,17 +155,16 @@ public async Task CreateContract(String accessToken } public async Task CreateMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateMerchantModel createMerchantModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - CreateMerchantRequest apiRequest = this.ModelFactory.ConvertFrom(createMerchantModel); + CreateMerchantRequest apiRequest = ModelFactory.ConvertFrom(createMerchantModel); CreateMerchantResponse apiResponse = await this.EstateClient.CreateMerchant(accessToken, estateId, apiRequest, cancellationToken); - CreateMerchantResponseModel createMerchantResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + CreateMerchantResponseModel createMerchantResponseModel = ModelFactory.ConvertFrom(apiResponse); return createMerchantResponseModel; } @@ -187,17 +175,16 @@ public async Task CreateMerchant(String accessToken } public async Task CreateOperator(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateOperatorModel createOperatorModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - CreateOperatorRequest apiRequest = this.ModelFactory.ConvertFrom(createOperatorModel); + CreateOperatorRequest apiRequest = ModelFactory.ConvertFrom(createOperatorModel); CreateOperatorResponse apiResponse = await this.EstateClient.CreateOperator(accessToken, estateId, apiRequest, cancellationToken); - CreateOperatorResponseModel createOperatorResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + CreateOperatorResponseModel createOperatorResponseModel = ModelFactory.ConvertFrom(apiResponse); return createOperatorResponseModel; } @@ -208,15 +195,14 @@ public async Task CreateOperator(String accessToken } public async Task GetContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - ContractResponse contract = await this.EstateClient.GetContract(accessToken, estateId, contractId, true, true, cancellationToken); - return this.ModelFactory.ConvertFrom(contract); + return ModelFactory.ConvertFrom(contract); } catch(Exception e){ Logger.LogError(e); @@ -225,16 +211,15 @@ public async Task GetContract(String accessToken, } public async Task GetContractProduct(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, Guid contractProductId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - ContractResponse contract = await this.EstateClient.GetContract(accessToken, estateId, contractId, true, true, cancellationToken); - ContractModel contractModel = this.ModelFactory.ConvertFrom(contract); + ContractModel contractModel = ModelFactory.ConvertFrom(contract); return contractModel.ContractProducts.SingleOrDefault(cp => cp.ContractProductId == contractProductId); } @@ -244,7 +229,7 @@ public async Task GetContractProduct(String accessToken, } } - public async Task> GetContractProductTypeList(String accessToken, ClaimsIdentity claimsIdentity, CancellationToken cancellationToken){ + public async Task> GetContractProductTypeList(String accessToken, CancellationToken cancellationToken){ return new List{ new(){ Description = "Mobile Topup", @@ -262,14 +247,13 @@ public async Task> GetContractProductTypeList(Str } public async Task> GetContracts(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - List contracts = await this.EstateClient.GetContracts(accessToken, estateId, cancellationToken); - return this.ModelFactory.ConvertFrom(contracts); + return ModelFactory.ConvertFrom(contracts); } catch(Exception ex){ Logger.LogError(ex); @@ -278,14 +262,13 @@ public async Task> GetContracts(String accessToken, } public async Task GetEstate(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - EstateResponse estate = await this.EstateClient.GetEstate(accessToken, estateId, cancellationToken); - return this.ModelFactory.ConvertFrom(estate); + return ModelFactory.ConvertFrom(estate); } catch(Exception e){ Logger.LogError(e); @@ -294,15 +277,14 @@ public async Task GetEstate(String accessToken, } public async Task GetFileDetails(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid fileId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - FileDetails fileDetails = await this.FileProcessorClient.GetFile(accessToken, estateId, fileId, cancellationToken); - FileDetailsModel model = this.ModelFactory.ConvertFrom(fileDetails); + FileDetailsModel model = ModelFactory.ConvertFrom(fileDetails); return model; } @@ -313,15 +295,14 @@ public async Task GetFileDetails(String accessToken, } public async Task GetFileImportLog(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid fileImportLogId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - FileImportLog fileImportLog = await this.FileProcessorClient.GetFileImportLog(accessToken, fileImportLogId, estateId, null, cancellationToken); - return this.ModelFactory.ConvertFrom(fileImportLog); + return ModelFactory.ConvertFrom(fileImportLog); } catch(Exception e){ Logger.LogError(e); @@ -330,18 +311,17 @@ public async Task GetFileImportLog(String accessToken, } public async Task> GetFileImportLogs(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid? merchantId, DateTime startDate, DateTime endDate, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - FileImportLogList fileImportLogs = await this.FileProcessorClient.GetFileImportLogs(accessToken, estateId, startDate, endDate, merchantId, cancellationToken); - List fileImportLogModels = this.ModelFactory.ConvertFrom(fileImportLogs); + List fileImportLogModels = ModelFactory.ConvertFrom(fileImportLogs); return fileImportLogModels; } @@ -352,16 +332,15 @@ public async Task> GetFileImportLogs(String accessToken } public async Task GetMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - MerchantResponse merchant = await this.EstateClient.GetMerchant(accessToken, estateId, merchantId, cancellationToken); MerchantBalanceResponse merchantBalance = await this.TransactionProcessorClient.GetMerchantBalance(accessToken, estateId, merchantId, cancellationToken); - return this.ModelFactory.ConvertFrom(merchant, merchantBalance); + return ModelFactory.ConvertFrom(merchant, merchantBalance); } catch(Exception ex){ Logger.LogError(ex); @@ -370,15 +349,14 @@ public async Task GetMerchant(String accessToken, } public async Task GetMerchantBalance(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - MerchantBalanceResponse merchantBalance = await this.TransactionProcessorClient.GetMerchantBalance(accessToken, estateId, merchantId, cancellationToken); - return this.ModelFactory.ConvertFrom(merchantBalance); + return ModelFactory.ConvertFrom(merchantBalance); } catch(Exception ex){ Logger.LogError(ex); @@ -387,18 +365,17 @@ public async Task GetMerchantBalance(String accessToken, } public async Task> GetMerchantBalanceHistory(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, DateTime startDate, DateTime endDate, CancellationToken cancellationToken){ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - try{ List merchantBalanceHistory = await this.TransactionProcessorClient.GetMerchantBalanceHistory(accessToken, estateId, merchantId, startDate, endDate, cancellationToken); - return this.ModelFactory.ConvertFrom(merchantBalanceHistory); + return ModelFactory.ConvertFrom(merchantBalanceHistory); } catch(Exception ex){ Logger.LogError(ex); @@ -407,14 +384,13 @@ public async Task> GetMerchantBalanceHistory(String } public async Task> GetMerchants(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - List merchants = await this.EstateClient.GetMerchants(accessToken, estateId, cancellationToken); - return this.ModelFactory.ConvertFrom(merchants); + return ModelFactory.ConvertFrom(merchants); } catch(Exception e){ Logger.LogError(e); @@ -423,18 +399,17 @@ public async Task> GetMerchants(String accessToken, } public async Task MakeMerchantDeposit(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, MakeMerchantDepositModel makeMerchantDepositModel, CancellationToken cancellationToken){ try{ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - - MakeMerchantDepositRequest apiRequest = this.ModelFactory.ConvertFrom(makeMerchantDepositModel); + MakeMerchantDepositRequest apiRequest = ModelFactory.ConvertFrom(makeMerchantDepositModel); MakeMerchantDepositResponse apiResponse = await this.EstateClient.MakeMerchantDeposit(accessToken, estateId, merchantId, apiRequest, cancellationToken); - MakeMerchantDepositResponseModel makeMerchantDepositResponseModel = this.ModelFactory.ConvertFrom(apiResponse); + MakeMerchantDepositResponseModel makeMerchantDepositResponseModel = ModelFactory.ConvertFrom(apiResponse); return makeMerchantDepositResponseModel; } @@ -445,15 +420,14 @@ public async Task MakeMerchantDeposit(String a } public async Task UploadFile(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, + Guid userId, Guid fileProfileId, Byte[] fileData, String fileName, CancellationToken cancellationToken){ - Guid estateId = ApiClient.GetClaimValue(claimsIdentity, ApiClient.EstateIdClaimType); - Guid userId = ApiClient.GetClaimValue(claimsIdentity, "sub"); - UploadFileRequest apiRequest = new UploadFileRequest{ EstateId = estateId, FileProfileId = fileProfileId, @@ -466,22 +440,6 @@ public async Task UploadFile(String accessToken, return apiResponse; } - private static T GetClaimValue(ClaimsIdentity claimsIdentity, - String claimType){ - if (!claimsIdentity.HasClaim(x => x.Type.ToLower() == claimType.ToLower())){ - throw new InvalidOperationException($"User {claimsIdentity.Name} does not have Claim [{claimType}]"); - } - - Claim claim = claimsIdentity.Claims.Single(x => x.Type.ToLower() == claimType.ToLower()); - return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(claim.Value); - } - - #endregion - - #region Others - - private const String EstateIdClaimType = "estateId"; - #endregion } } \ No newline at end of file diff --git a/EstateAdministrationUI.BusinessLogic/Services/IApiClient.cs b/EstateAdministrationUI.BusinessLogic/Services/IApiClient.cs index 0a81f0e..920ed0f 100644 --- a/EstateAdministrationUI.BusinessLogic/Services/IApiClient.cs +++ b/EstateAdministrationUI.BusinessLogic/Services/IApiClient.cs @@ -1,7 +1,6 @@ namespace EstateAdministrationUI.Services{ using System; using System.Collections.Generic; - using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using BusinessLogic.Models; @@ -13,19 +12,22 @@ public interface IApiClient{ #region Methods Task AddDeviceToMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, AddMerchantDeviceModel merchantDeviceModel, CancellationToken cancellationToken); Task AddProductToContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, AddProductToContractModel addProductToContractModel, CancellationToken cancellationToken); Task AddTransactionFeeToContractProduct(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, Guid contractProductId, AddTransactionFeeToContractProductModel @@ -33,94 +35,112 @@ Task AddTransactionFeeToContrac CancellationToken cancellationToken); Task AssignOperatorToMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, AssignOperatorToMerchantModel assignOperatorToMerchantModel, CancellationToken cancellationToken); Task CreateContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateContractModel createContractModel, CancellationToken cancellationToken); Task CreateMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateMerchantModel createMerchantModel, CancellationToken cancellationToken); Task CreateOperator(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CreateOperatorModel createOperatorModel, CancellationToken cancellationToken); Task GetContract(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, CancellationToken cancellationToken); Task GetContractProduct(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid contractId, Guid contractProductId, CancellationToken cancellationToken); - Task> GetContractProductTypeList(String accessToken, ClaimsIdentity claimsIdentity, CancellationToken cancellationToken); + Task> GetContractProductTypeList(String accessToken, CancellationToken cancellationToken); Task> GetContracts(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken); Task GetEstate(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken); Task GetFileDetails(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid fileId, CancellationToken cancellationToken); Task GetFileImportLog(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid fileImportLogId, CancellationToken cancellationToken); Task> GetFileImportLogs(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid? merchantId, DateTime startDate, DateTime endDate, CancellationToken cancellationToken); Task GetMerchant(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, CancellationToken cancellationToken); Task GetMerchantBalance(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, CancellationToken cancellationToken); Task> GetMerchantBalanceHistory(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, DateTime startDate, DateTime endDate, CancellationToken cancellationToken); Task> GetMerchants(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, CancellationToken cancellationToken); Task MakeMerchantDeposit(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, MakeMerchantDepositModel makeMerchantDepositModel, CancellationToken cancellationToken); Task UploadFile(String accessToken, - ClaimsIdentity claimsIdentity, + Guid actionId, + Guid estateId, Guid merchantId, + Guid userId, Guid fileProfileId, Byte[] fileData, String fileName, diff --git a/EstateAdministrationUI.Tests/FactoryTests/ViewModelFactoryTests.cs b/EstateAdministrationUI.Tests/FactoryTests/ViewModelFactoryTests.cs index 3c419a2..f4d00fa 100644 --- a/EstateAdministrationUI.Tests/FactoryTests/ViewModelFactoryTests.cs +++ b/EstateAdministrationUI.Tests/FactoryTests/ViewModelFactoryTests.cs @@ -12,6 +12,7 @@ namespace EstateAdministrationUI.Tests.FactoryTests using Shouldly; using Testing; using Xunit; + using FileLineProcessingResult = Areas.Estate.Models.FileLineProcessingResult; public class ViewModelFactoryTests { @@ -20,9 +21,7 @@ public void ViewModelFactory_ConvertFrom_EstateModel_ModelIsConverted() { EstateModel model = TestData.EstateModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - EstateViewModel viewModel = viewModelFactory.ConvertFrom(model); + EstateViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.EstateId.ShouldBe(model.EstateId); viewModel.EstateName.ShouldBe(model.EstateName); @@ -33,9 +32,7 @@ public void ViewModelFactory_ConvertFrom_EstateModel_NullModel_ErrorThrown() { EstateModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(model); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(model); }); } [Theory] @@ -47,9 +44,7 @@ public void ViewModelFactory_ConvertFrom_CreateMerchantViewModel_ModelIsConverte { CreateMerchantViewModel viewModel = TestData.CreateMerchantViewModel(settlementSchedule); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - CreateMerchantModel model = viewModelFactory.ConvertFrom(viewModel); + CreateMerchantModel model = ViewModelFactory.ConvertFrom(viewModel); model.MerchantName.ShouldBe(viewModel.MerchantName); model.SettlementSchedule.ShouldBe(expectedSettlementSchedule); @@ -72,9 +67,7 @@ public void ViewModelFactory_ConvertFrom_CreateMerchantViewModel_NullModel_Error { CreateMerchantViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(viewModel); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(viewModel); }); } [Theory] @@ -85,9 +78,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_ModelIsConverted(Settleme { MerchantModel model = TestData.MerchantModel(settlementSchedule); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -148,9 +139,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_NullOperators_ModelIsConv MerchantModel model = TestData.MerchantModel(); model.Operators = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -202,9 +191,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_EmptyOperators_ModelIsCon MerchantModel model = TestData.MerchantModel(); model.Operators = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -255,9 +242,8 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_NullDevices_ModelIsConver { MerchantModel model = TestData.MerchantModel(); model.Devices = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -311,9 +297,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_EmptyDevices_ModelIsConve MerchantModel model = TestData.MerchantModel(); model.Devices = new Dictionary(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -366,9 +350,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_NullAddresses_ModelIsConv { MerchantModel model = TestData.MerchantModel(); model.Addresses = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -412,9 +394,8 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_EmptyAddresses_ModelIsCon { MerchantModel model = TestData.MerchantModel(); model.Addresses = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -459,9 +440,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_NullContacts_ModelIsConve MerchantModel model = TestData.MerchantModel(); model.Contacts = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -512,9 +491,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_EmptyContacts_ModelIsConv MerchantModel model = TestData.MerchantModel(); model.Contacts = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(model); //viewModel.Balance.ShouldBe(model.Balance); viewModel.MerchantId.ShouldBe(model.MerchantId); @@ -564,9 +541,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModel_NullModel_ErrorThrown() { MerchantModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(model); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(model); }); } [Fact] @@ -577,9 +552,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_ModelIsConverted() TestData.MerchantModel() }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -604,9 +577,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantFirstAddressI }; modelList.First().Addresses[0] = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -631,9 +602,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithNullAddre }; modelList.First().Addresses = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -658,9 +627,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithEmptyAddr }; modelList.First().Addresses = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -685,9 +652,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantFirstContactI }; modelList.First().Contacts[0] = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -712,9 +677,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithNullConta }; modelList.First().Contacts = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -739,9 +702,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithEmptyCont }; modelList.First().Contacts = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -766,9 +727,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithNullDevic }; modelList.First().Devices = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -793,9 +752,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithEmptyDevi }; modelList.First().Devices = new Dictionary(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -820,9 +777,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantFirstOperator }; modelList.First().Operators[0] = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -847,9 +802,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithNullOpera }; modelList.First().Operators = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -874,9 +827,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_MerchantWithEmptyOper }; modelList.First().Operators = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(modelList); + List viewModelList = ViewModelFactory.ConvertFrom(modelList); MerchantListViewModel viewModel = viewModelList.SingleOrDefault(); viewModel.ShouldNotBeNull(); @@ -897,9 +848,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_NullModel_ErrorThrown { List modelList = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(modelList); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(modelList); }); } [Fact] @@ -907,9 +856,7 @@ public void ViewModelFactory_ConvertFrom_MerchantModelList_EmptyModel_ErrorThrow { List modelList = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(modelList); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(modelList); }); } [Fact] @@ -917,9 +864,7 @@ public void ViewModelFactory_ConvertFrom_MakeMerchantDepositViewModel_ModelIsCon { MakeMerchantDepositViewModel viewModel = TestData.MakeMerchantDepositViewModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MakeMerchantDepositModel model = viewModelFactory.ConvertFrom(viewModel); + MakeMerchantDepositModel model = ViewModelFactory.ConvertFrom(viewModel); model.MerchantId.ShouldBe(Guid.Parse(viewModel.MerchantId)); model.DepositDateTime.ShouldBe(DateTime.ParseExact(viewModel.DepositDate, "dd/MM/yyyy", null)); @@ -932,9 +877,7 @@ public void ViewModelFactory_ConvertFrom_MakeMerchantDepositViewModel_NullModel_ { MakeMerchantDepositViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(viewModel); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(viewModel); }); } [Fact] @@ -942,9 +885,7 @@ public void ViewModelFactory_ConvertFrom_CreateOperatorViewModel_ModelIsConverte { CreateOperatorViewModel viewModel = TestData.CreateOperatorViewModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - CreateOperatorModel model = viewModelFactory.ConvertFrom(viewModel); + CreateOperatorModel model = ViewModelFactory.ConvertFrom(viewModel); model.OperatorName.ShouldBe(viewModel.OperatorName); model.RequireCustomTerminalNumber.ShouldBe(viewModel.RequireCustomTerminalNumber); @@ -956,9 +897,7 @@ public void ViewModelFactory_ConvertFrom_CreateOperatorViewModel_NullModel_Error { CreateOperatorViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(viewModel); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(viewModel); }); } [Fact] @@ -966,9 +905,7 @@ public void ViewModelFactory_ConvertFrom_EstateOperatorModel_ModelIsConverted() { EstateOperatorModel model = TestData.EstateOperatorModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - OperatorListViewModel viewModel = viewModelFactory.ConvertFrom(TestData.EstateId, model); + OperatorListViewModel viewModel = ViewModelFactory.ConvertFrom(TestData.EstateId, model); viewModel.EstateId.ShouldBe(TestData.EstateId); viewModel.OperatorName.ShouldBe(model.Name); @@ -982,9 +919,7 @@ public void ViewModelFactory_ConvertFrom_EstateOperatorModel_NullModel_ErrorThro { EstateOperatorModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - Should.Throw(() => { viewModelFactory.ConvertFrom(TestData.EstateId, model); }); + Should.Throw(() => { ViewModelFactory.ConvertFrom(TestData.EstateId, model); }); } [Fact] @@ -995,9 +930,7 @@ public void ViewModelFactory_ConvertFrom_EstateOperatorModelList_ModelIsConverte TestData.EstateOperatorModel }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModelList = viewModelFactory.ConvertFrom(TestData.EstateId, modelList); + List viewModelList = ViewModelFactory.ConvertFrom(TestData.EstateId, modelList); viewModelList.ShouldNotBeNull(); viewModelList.ShouldNotBeEmpty(); @@ -1014,11 +947,9 @@ public void ViewModelFactory_ConvertFrom_EstateOperatorModelList_EmptyList_Error { List modelList = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(TestData.EstateId, modelList); + ViewModelFactory.ConvertFrom(TestData.EstateId, modelList); }); } @@ -1027,11 +958,9 @@ public void ViewModelFactory_ConvertFrom_EstateOperatorModelList_NullList_ErrorT { List modelList = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(TestData.EstateId, modelList); + ViewModelFactory.ConvertFrom(TestData.EstateId, modelList); }); } @@ -1040,9 +969,7 @@ public void ViewModelFactory_ConvertFrom_CreateContractViewModel_IsConverted() { CreateContractViewModel viewModel = TestData.CreateContractViewModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - CreateContractModel model = viewModelFactory.ConvertFrom(viewModel); + CreateContractModel model = ViewModelFactory.ConvertFrom(viewModel); model.OperatorId.ShouldBe(viewModel.OperatorId); model.Description.ShouldBe(viewModel.ContractDescription); @@ -1053,11 +980,9 @@ public void ViewModelFactory_ConvertFrom_CreateContractViewModel_NullModel_Error { CreateContractViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(viewModel); + ViewModelFactory.ConvertFrom(viewModel); }); } @@ -1066,9 +991,7 @@ public void ViewModelFactory_ConvertFrom_ContractModel_IsConverted() { ContractModel model = TestData.ContractModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ContractId.ShouldBe(model.ContractId); viewModel.Description.ShouldBe(model.Description); @@ -1080,9 +1003,7 @@ public void ViewModelFactory_ConvertFrom_ContractModel_NullProducts_IsConverted( { ContractModel model = TestData.ContractModelNullProducts; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ContractId.ShouldBe(model.ContractId); viewModel.Description.ShouldBe(model.Description); @@ -1094,9 +1015,7 @@ public void ViewModelFactory_ConvertFrom_ContractModel_EmptyProducts_IsConverted { ContractModel model = TestData.ContractModelEmptyProducts; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ContractId.ShouldBe(model.ContractId); viewModel.Description.ShouldBe(model.Description); @@ -1108,9 +1027,7 @@ public void ViewModelFactory_ConvertFrom_ContractModel_ProductWithNullValue_IsCo { ContractModel model = TestData.ContractModelWithNullValueProduct; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ContractId.ShouldBe(model.ContractId); viewModel.Description.ShouldBe(model.Description); @@ -1122,11 +1039,9 @@ public void ViewModelFactory_ConvertFrom_ContractModel_NullModel_ErrorThrown() { ContractModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(model); + ViewModelFactory.ConvertFrom(model); }); } @@ -1139,9 +1054,7 @@ public void ViewModelFactory_ConvertFrom_ContractProductModel_IsConverted(Int32 { ContractProductModel model = TestData.ContractProductModel(productType); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductTransactionFeesListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductTransactionFeesListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.Description.ShouldBe(model.Description); viewModel.Value.ShouldBe(model.Value.ToString()); @@ -1156,9 +1069,7 @@ public void ViewModelFactory_ConvertFrom_ContractProductModel_NullValue_IsConver { ContractProductModel model = TestData.ContractProductModelNullValue; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductTransactionFeesListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductTransactionFeesListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.Description.ShouldBe(model.Description); viewModel.Value.ShouldBe("Variable"); @@ -1173,9 +1084,7 @@ public void ViewModelFactory_ConvertFrom_ContractProductModel_NullFees_IsConvert { ContractProductModel model = TestData.ContractProductModelNullFees; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductTransactionFeesListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductTransactionFeesListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.Description.ShouldBe(model.Description); viewModel.Value.ShouldBe(model.Value.ToString()); @@ -1190,9 +1099,7 @@ public void ViewModelFactory_ConvertFrom_ContractProductModel_EmptyFees_IsConver { ContractProductModel model = TestData.ContractProductModelEmptyFeeList; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - ContractProductTransactionFeesListViewModel viewModel = viewModelFactory.ConvertFrom(model); + ContractProductTransactionFeesListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.Description.ShouldBe(model.Description); viewModel.Value.ShouldBe(model.Value.ToString()); @@ -1207,11 +1114,9 @@ public void ViewModelFactory_ConvertFrom_ContractProductModel_NullModel_ErrorThr { ContractProductModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(model); + ViewModelFactory.ConvertFrom(model); }); } @@ -1223,9 +1128,7 @@ public void ViewModelFactory_ConvertFrom_ContractModelList_IsConverted() TestData.ContractModel }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModels = viewModelFactory.ConvertFrom(modelList); + List viewModels = ViewModelFactory.ConvertFrom(modelList); viewModels.ShouldHaveSingleItem(); ContractListViewModel viewModel = viewModels.Single(); @@ -1237,11 +1140,9 @@ public void ViewModelFactory_ConvertFrom_ContractModelList_NullList_ErrorThrown( { List modelList = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(modelList); + ViewModelFactory.ConvertFrom(modelList); }); } @@ -1250,9 +1151,7 @@ public void ViewModelFactory_ConvertFrom_CreateContractProductViewModel_WithValu { CreateContractProductViewModel viewModel = TestData.CreateContractProductViewModelWithValue; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - AddProductToContractModel model = viewModelFactory.ConvertFrom(viewModel); + AddProductToContractModel model = ViewModelFactory.ConvertFrom(viewModel); model.Value.ShouldBe(viewModel.Value); model.DisplayText.ShouldBe(viewModel.DisplayText); @@ -1265,9 +1164,7 @@ public void ViewModelFactory_ConvertFrom_CreateContractProductViewModel_WithNull { CreateContractProductViewModel viewModel = TestData.CreateContractProductViewModelWithNullValue; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - AddProductToContractModel model = viewModelFactory.ConvertFrom(viewModel); + AddProductToContractModel model = ViewModelFactory.ConvertFrom(viewModel); model.Value.ShouldBeNull(); model.DisplayText.ShouldBe(viewModel.DisplayText); @@ -1280,11 +1177,9 @@ public void ViewModelFactory_ConvertFrom_CreateContractProductViewModel_NullView { CreateContractProductViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(viewModel); + ViewModelFactory.ConvertFrom(viewModel); }); } @@ -1293,9 +1188,7 @@ public void ViewModelFactory_ConvertFrom_CreateContractProductTransactionFeeView { CreateContractProductTransactionFeeViewModel viewModel = TestData.CreateContractProductTransactionFeeViewModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - AddTransactionFeeToContractProductModel model = viewModelFactory.ConvertFrom(viewModel); + AddTransactionFeeToContractProductModel model = ViewModelFactory.ConvertFrom(viewModel); model.Value.ShouldBe(viewModel.Value); model.CalculationType.ShouldBe((CalculationType)(viewModel.CalculationType -1)); @@ -1308,11 +1201,9 @@ public void ViewModelFactory_ConvertFrom_CreateContractProductTransactionFeeView { CreateContractProductTransactionFeeViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(viewModel); + ViewModelFactory.ConvertFrom(viewModel); }); } @@ -1321,9 +1212,7 @@ public void ViewModelFactory_CovertFrom_MerchantBalanceHistoryModel_IsConverted( { List model = TestData.MerchantBalanceHistoryList; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantBalanceHistoryListViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantBalanceHistoryListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.MerchantBalanceHistoryViewModels.Count.ShouldBe(model.Count); } @@ -1333,9 +1222,7 @@ public void ViewModelFactory_CovertFrom_MerchantBalanceHistoryModel_ModelIsNull_ { List model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantBalanceHistoryListViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantBalanceHistoryListViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.MerchantBalanceHistoryViewModels.ShouldBeNull(); } @@ -1349,9 +1236,7 @@ public void ViewModelFactory_CovertFrom_FileImportLogModelList_IsConverted() }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModel = viewModelFactory.ConvertFrom(modelList); + List viewModel = ViewModelFactory.ConvertFrom(modelList); viewModel.ShouldNotBeNull(); viewModel.Count.ShouldBe(modelList.Count); @@ -1385,9 +1270,7 @@ public void ViewModelFactory_CovertFrom_FileImportLogModelList_NullModel_IsConve { List modelList = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModel = viewModelFactory.ConvertFrom(modelList); + List viewModel = ViewModelFactory.ConvertFrom(modelList); viewModel.ShouldNotBeNull(); viewModel.ShouldBeEmpty(); @@ -1398,9 +1281,7 @@ public void ViewModelFactory_CovertFrom_FileImportLogModel_NullModel_IsConverted { FileImportLogModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - FileImportLogViewModel viewModel = viewModelFactory.ConvertFrom(model); + FileImportLogViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ShouldBeNull(); } @@ -1410,9 +1291,7 @@ public void ViewModelFactory_CovertFrom_FileImportLogModelList_EmptyModelList_Is { List modelList = new List(); - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List viewModel = viewModelFactory.ConvertFrom(modelList); + List viewModel = ViewModelFactory.ConvertFrom(modelList); viewModel.ShouldNotBeNull(); viewModel.ShouldBeEmpty(); @@ -1423,9 +1302,7 @@ public void ViewModelFactory_ConvertFrom_FileDetails_IsConverted() { FileDetailsModel model = TestData.FileDetailsModel; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - FileDetailsViewModel viewModel = viewModelFactory.ConvertFrom(model); + FileDetailsViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ShouldNotBeNull(); viewModel.UserId.ShouldBe(model.UserId); @@ -1463,9 +1340,7 @@ public void ViewModelFactory_ConvertFrom_FileDetails_NullDetails_IsConverted() { FileDetailsModel response = null; - ViewModelFactory modelFactory = new ViewModelFactory(); - - FileDetailsViewModel viewModel = modelFactory.ConvertFrom(response); + FileDetailsViewModel viewModel = ViewModelFactory.ConvertFrom(response); viewModel.ShouldBeNull(); } @@ -1481,9 +1356,7 @@ public void ViewModelFactory_ConvertFrom_MerchantBalanceModel_ModelIsConverted() MerchantId = TestData.MerchantId }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - MerchantBalanceViewModel viewModel = viewModelFactory.ConvertFrom(model); + MerchantBalanceViewModel viewModel = ViewModelFactory.ConvertFrom(model); viewModel.ShouldNotBeNull(); viewModel.EstateId.ShouldBe(model.EstateId); @@ -1497,11 +1370,9 @@ public void ViewModelFactory_ConvertFrom_MerchantBalanceModel_NullModel_ErrorThr { MerchantBalanceModel model = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(model); + ViewModelFactory.ConvertFrom(model); }); } @@ -1514,9 +1385,7 @@ public void ViewModelFactory_ConvertFrom_AddMerchantDeviceViewModel_ModelIsConve MerchantId = TestData.MerchantId }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - AddMerchantDeviceModel model = viewModelFactory.ConvertFrom(viewModel); + AddMerchantDeviceModel model = ViewModelFactory.ConvertFrom(viewModel); model.ShouldNotBeNull(); model.DeviceIdentifier.ShouldBe(viewModel.DeviceIdentifier); @@ -1527,11 +1396,9 @@ public void ViewModelFactory_ConvertFrom_AddMerchantDeviceViewModel_NullModel_Er { AddMerchantDeviceViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(viewModel); + ViewModelFactory.ConvertFrom(viewModel); }); } @@ -1546,9 +1413,7 @@ public void ViewModelFactory_ConvertFrom_AssignOperatorToMerchantViewModel_Model TerminalNumber = TestData.TerminalNumber }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - AssignOperatorToMerchantModel model = viewModelFactory.ConvertFrom(viewModel); + AssignOperatorToMerchantModel model = ViewModelFactory.ConvertFrom(viewModel); model.ShouldNotBeNull(); model.OperatorId.ShouldBe(viewModel.OperatorId); @@ -1561,11 +1426,9 @@ public void ViewModelFactory_ConvertFrom_AssignOperatorToMerchantViewModel_NullM { AssignOperatorToMerchantViewModel viewModel = null; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - Should.Throw(() => { - viewModelFactory.ConvertFrom(viewModel); + ViewModelFactory.ConvertFrom(viewModel); }); } @@ -1578,14 +1441,37 @@ public void ViewModelFactory_ConvertFrom_ContractProductTypeModelList_ListConver } }; - ViewModelFactory viewModelFactory = new ViewModelFactory(); - - List contractProductTypeViewModels = viewModelFactory.ConvertFrom(modelList); + List contractProductTypeViewModels = ViewModelFactory.ConvertFrom(modelList); contractProductTypeViewModels.Count.ShouldBe(modelList.Count); contractProductTypeViewModels.Single().Description.ShouldBe(modelList.Single().Description); contractProductTypeViewModels.Single().ProductType.ShouldBe(modelList.Single().ProductType.ToString()); + } + + [Theory] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.Failed, FileLineProcessingResult.Failed, "Failed")] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.Ignored, FileLineProcessingResult.Ignored, "Ignored")] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.NotProcessed, FileLineProcessingResult.NotProcessed, "Not Processed")] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.Rejected, FileLineProcessingResult.Rejected, "Rejected")] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.Successful, FileLineProcessingResult.Successful, "Successful")] + [InlineData(BusinessLogic.Models.FileLineProcessingResult.Unknown, FileLineProcessingResult.Unknown, "Unknown")] + [InlineData((BusinessLogic.Models.FileLineProcessingResult)99, FileLineProcessingResult.Unknown, "Unknown")] + + public void ViewModelFactory_ConvertFrom_FileLineProcessingResult_ResultConverted(BusinessLogic.Models.FileLineProcessingResult processingResult, + FileLineProcessingResult expectedResult, String stringResult){ + (FileLineProcessingResult result, String stringResult) result = ViewModelFactory.ConvertFrom(processingResult); + result.result.ShouldBe(expectedResult); + result.stringResult.ShouldBe(stringResult); + } + + [Theory] + [InlineData(ProductType.BillPayment, "Bill Payment")] + [InlineData(ProductType.MobileTopup, "Mobile Topup")] + [InlineData(ProductType.Voucher, "Voucher")] + public void ViewModelFactory_GetProductTypeName_TypeConverted(ProductType productType, String expectedValue){ + String result = ViewModelFactory.GetProductTypeName(productType); + result.ShouldBe(expectedValue); } } } diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/ContractController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/ContractController.cs index 0432703..e9a2c43 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/ContractController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/ContractController.cs @@ -35,25 +35,14 @@ public class ContractController : Controller /// private readonly IApiClient ApiClient; - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; - + #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public ContractController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + + public ContractController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion @@ -90,11 +79,14 @@ public async Task CreateContract(CreateContractViewModel viewMode { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - CreateContractModel createContractModel = this.ViewModelFactory.ConvertFrom(viewModel); + CreateContractModel createContractModel = ViewModelFactory.ConvertFrom(viewModel); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); // All good with model, call the client to create the golf club CreateContractResponseModel createContractResponseModel = - await this.ApiClient.CreateContract(accessToken, this.User.Identity as ClaimsIdentity, createContractModel, cancellationToken); + await this.ApiClient.CreateContract(accessToken, Guid.Empty, + estateId, createContractModel, cancellationToken); // Merchant Created, redirect to the Merchant List screen return this.RedirectToAction("GetContractList", "Contract") @@ -144,12 +136,15 @@ public async Task CreateContractProduct(CreateContractProductView { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - AddProductToContractModel addProductToContractModel = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + AddProductToContractModel addProductToContractModel = ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client AddProductToContractResponseModel addProductToContractResponse = await this.ApiClient.AddProductToContract(accessToken, - this.User.Identity as ClaimsIdentity, + Guid.Empty, + estateId, viewModel.ContractId, addProductToContractModel, cancellationToken); @@ -209,12 +204,15 @@ public async Task CreateContractProductTransactionFee(CreateContr { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - AddTransactionFeeToContractProductModel addTransactionFeeToContractProductModel = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + AddTransactionFeeToContractProductModel addTransactionFeeToContractProductModel = ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client AddTransactionFeeToContractProductResponseModel addTransactionFeeToContractProductResponse = await this.ApiClient.AddTransactionFeeToContractProduct(accessToken, - this.User.Identity as ClaimsIdentity, + Guid.Empty, + estateId, viewModel.ContractId, viewModel.ContractProductId, addTransactionFeeToContractProductModel, @@ -269,9 +267,12 @@ public async Task GetContractListAsJson(CancellationToken cancell String searchValue = this.HttpContext.Request.Form["search[value]"].FirstOrDefault(); String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - List contractList = await this.ApiClient.GetContracts(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + List contractList = await this.ApiClient.GetContracts(accessToken, Guid.Empty, + estateId, cancellationToken); - List contractViewModels = this.ViewModelFactory.ConvertFrom(contractList); + List contractViewModels = ViewModelFactory.ConvertFrom(contractList); Logger.LogDebug($"contract list count is {contractViewModels.Count}"); @@ -305,9 +306,12 @@ public async Task GetContractProductsList([FromQuery] Guid contra { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - ContractModel contract = await this.ApiClient.GetContract(accessToken, this.User.Identity as ClaimsIdentity, contractId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); - ContractProductListViewModel viewModel = this.ViewModelFactory.ConvertFrom(contract); + ContractModel contract = await this.ApiClient.GetContract(accessToken, Guid.Empty, + estateId, contractId, cancellationToken); + + ContractProductListViewModel viewModel = ViewModelFactory.ConvertFrom(contract); return this.View("ContractProductsList", viewModel); } @@ -335,9 +339,12 @@ public async Task GetContractProductsListAsJson([FromQuery] Guid String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - ContractModel contract = await this.ApiClient.GetContract(accessToken, this.User.Identity as ClaimsIdentity, contractId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + ContractModel contract = await this.ApiClient.GetContract(accessToken, Guid.Empty, + estateId, contractId, cancellationToken); - ContractProductListViewModel contractProductListViewModel = this.ViewModelFactory.ConvertFrom(contract); + ContractProductListViewModel contractProductListViewModel = ViewModelFactory.ConvertFrom(contract); Expression> whereClause = c => c.ProductName.Contains(searchValue, StringComparison.OrdinalIgnoreCase) || c.DisplayText.Contains(searchValue, StringComparison.OrdinalIgnoreCase); @@ -366,10 +373,13 @@ public async Task GetContractProductTransactionFeesList([FromQuer { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + ContractProductModel contractProduct = - await this.ApiClient.GetContractProduct(accessToken, this.User.Identity as ClaimsIdentity, contractId, contractProductId, cancellationToken); + await this.ApiClient.GetContractProduct(accessToken, Guid.Empty, + estateId, contractId, contractProductId, cancellationToken); - ContractProductTransactionFeesListViewModel viewModel = this.ViewModelFactory.ConvertFrom(contractProduct); + ContractProductTransactionFeesListViewModel viewModel = ViewModelFactory.ConvertFrom(contractProduct); return this.View("ContractProductTransactionFeesList", viewModel); } @@ -399,10 +409,13 @@ public async Task GetContractProductTransactionFeesListAsJson([Fr String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + ContractProductModel contractProduct = - await this.ApiClient.GetContractProduct(accessToken, this.User.Identity as ClaimsIdentity, contractId, contractProductId, cancellationToken); + await this.ApiClient.GetContractProduct(accessToken, Guid.Empty, + estateId, contractId, contractProductId, cancellationToken); - ContractProductTransactionFeesListViewModel contractProductTransactionFeesViewModel = this.ViewModelFactory.ConvertFrom(contractProduct); + ContractProductTransactionFeesListViewModel contractProductTransactionFeesViewModel = ViewModelFactory.ConvertFrom(contractProduct); Expression> whereClause = c => c.Description.Contains(searchValue, StringComparison.OrdinalIgnoreCase) || @@ -429,9 +442,12 @@ public async Task GetOperatorListAsJson(CancellationToken cancell { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - EstateModel estate = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + EstateModel estate = await this.ApiClient.GetEstate(accessToken, Guid.Empty, + estateId, cancellationToken); - List operatorViewModels = this.ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); + List operatorViewModels = ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); return this.Json(operatorViewModels); } @@ -448,9 +464,9 @@ public async Task GetContractProductTypeListAsJson(CancellationTo { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - List contractProductTypeList= await this.ApiClient.GetContractProductTypeList(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + List contractProductTypeList= await this.ApiClient.GetContractProductTypeList(accessToken, cancellationToken); - List contractProductTypeViewModels = this.ViewModelFactory.ConvertFrom(contractProductTypeList); + List contractProductTypeViewModels = ViewModelFactory.ConvertFrom(contractProductTypeList); return this.Json(contractProductTypeViewModels); } diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/EstateController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/EstateController.cs index 4ddb248..ceabdb1 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/EstateController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/EstateController.cs @@ -25,26 +25,15 @@ public class EstateController : Controller /// The API client /// private readonly IApiClient ApiClient; - - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; + #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public EstateController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + + public EstateController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion @@ -63,9 +52,12 @@ public async Task GetEstate(CancellationToken cancellationToken) { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - EstateModel estateDetails = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + EstateModel estateDetails = await this.ApiClient.GetEstate(accessToken, Guid.Empty, + estateId, cancellationToken); - return this.View("EstateDetails", this.ViewModelFactory.ConvertFrom(estateDetails)); + return this.View("EstateDetails", ViewModelFactory.ConvertFrom(estateDetails)); } catch(Exception ex) { diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/FileProcessingController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/FileProcessingController.cs index 1776750..6ae1eba 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/FileProcessingController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/FileProcessingController.cs @@ -35,25 +35,12 @@ public class FileProcessingController : Controller /// private readonly IApiClient ApiClient; - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; - #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public FileProcessingController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + public FileProcessingController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion @@ -74,9 +61,12 @@ public async Task GetFileDetails([FromQuery] Guid fileId, { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - FileDetailsModel fileDetailsModel = await this.ApiClient.GetFileDetails(accessToken, this.User.Identity as ClaimsIdentity, fileId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); - return this.View("FileDetails", this.ViewModelFactory.ConvertFrom(fileDetailsModel)); + FileDetailsModel fileDetailsModel = await this.ApiClient.GetFileDetails(accessToken, Guid.Empty, + estateId, fileId, cancellationToken); + + return this.View("FileDetails", ViewModelFactory.ConvertFrom(fileDetailsModel)); } catch(Exception e) { @@ -99,10 +89,13 @@ public async Task GetFileImportLog([FromQuery] Guid fileImportLog { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + FileImportLogModel fileImportLogModel = - await this.ApiClient.GetFileImportLog(accessToken, this.User.Identity as ClaimsIdentity, fileImportLogId, cancellationToken); + await this.ApiClient.GetFileImportLog(accessToken, Guid.Empty, + estateId, fileImportLogId, cancellationToken); - return this.View("FileImportLog", this.ViewModelFactory.ConvertFrom(fileImportLogModel)); + return this.View("FileImportLog", ViewModelFactory.ConvertFrom(fileImportLogModel)); } catch(Exception e) { @@ -125,10 +118,13 @@ public async Task GetFileImportLogFileListAsJson([FromQuery] Guid { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + FileImportLogModel fileImportLogModel = - await this.ApiClient.GetFileImportLog(accessToken, this.User.Identity as ClaimsIdentity, fileImportLogId, cancellationToken); + await this.ApiClient.GetFileImportLog(accessToken, Guid.Empty, + estateId, fileImportLogId, cancellationToken); - FileImportLogViewModel viewModel = this.ViewModelFactory.ConvertFrom(fileImportLogModel); + FileImportLogViewModel viewModel = ViewModelFactory.ConvertFrom(fileImportLogModel); return this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.Files)); } @@ -187,9 +183,12 @@ public async Task GetFileImportLogListAsJson(CancellationToken ca String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List importLogFileModelList = - await this.ApiClient.GetFileImportLogs(accessToken, this.User.Identity as ClaimsIdentity, merchantId, startDateTime, endDateTime, cancellationToken); - List importLogFileViewModelList = this.ViewModelFactory.ConvertFrom(importLogFileModelList); + await this.ApiClient.GetFileImportLogs(accessToken, Guid.Empty, + estateId, merchantId, startDateTime, endDateTime, cancellationToken); + List importLogFileViewModelList = ViewModelFactory.ConvertFrom(importLogFileModelList); return this.Json(Helpers.GetDataForDataTable(this.Request.Form, importLogFileViewModelList)); } @@ -214,9 +213,12 @@ public async Task GetFileLineListAsJson([FromQuery] Guid fileId, { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - FileDetailsModel fileDetailsModel = await this.ApiClient.GetFileDetails(accessToken, this.User.Identity as ClaimsIdentity, fileId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + FileDetailsModel fileDetailsModel = await this.ApiClient.GetFileDetails(accessToken, Guid.Empty, + estateId, fileId, cancellationToken); - FileDetailsViewModel viewModel = this.ViewModelFactory.ConvertFrom(fileDetailsModel); + FileDetailsViewModel viewModel = ViewModelFactory.ConvertFrom(fileDetailsModel); return this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.FileLines)); } @@ -262,9 +264,12 @@ public async Task GetMerchantListAsJson(CancellationToken cancella { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - var merchantModelList = await this.ApiClient.GetMerchants(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + var merchantModelList = await this.ApiClient.GetMerchants(accessToken, Guid.Empty, + estateId, cancellationToken); - var merchantViewModelList = this.ViewModelFactory.ConvertFrom(merchantModelList); + var merchantViewModelList = ViewModelFactory.ConvertFrom(merchantModelList); return this.Json(merchantViewModelList); } @@ -302,6 +307,8 @@ public async Task PostUploadFile(CancellationToken cancellationTo } IFormFileCollection files = this.HttpContext.Request.Form.Files; + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + Guid userId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, "sub"); Guid merchantId = Guid.Parse(this.Request.Form["merchantId"]); Guid fileProfileId = Guid.Parse(this.Request.Form["fileProfileId"]); IFormFile file = files.First(); @@ -312,8 +319,10 @@ public async Task PostUploadFile(CancellationToken cancellationTo await file.CopyToAsync(ms, cancellationToken); Byte[] fileBytes = ms.ToArray(); Guid fileId = await this.ApiClient.UploadFile(accessToken, - this.User.Identity as ClaimsIdentity, + Guid.Empty, + estateId, merchantId, + userId, fileProfileId, fileBytes, file.FileName, diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs index e23ac2f..e660552 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs @@ -35,29 +35,18 @@ public class HomeController : Controller /// The API client /// private readonly IApiClient ApiClient; - - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; + private readonly IConfigurationService ConfigurationService; #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. + public HomeController(IApiClient apiClient, - IViewModelFactory viewModelFactory, IConfigurationService configurationService) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; this.ConfigurationService = configurationService; } diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/MerchantController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/MerchantController.cs index e965aad..d04229f 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/MerchantController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/MerchantController.cs @@ -31,26 +31,14 @@ public class MerchantController : Controller /// The API client /// private readonly IApiClient ApiClient; - - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; - + #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public MerchantController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + + public MerchantController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion @@ -87,11 +75,15 @@ public async Task GetOperatorListAsJson(Guid merchantId, Cancella { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - EstateModel estate = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + EstateModel estate = await this.ApiClient.GetEstate(accessToken, Guid.Empty, + estateId, cancellationToken); - List operatorViewModels = this.ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); + List operatorViewModels = ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); - MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, this.User.Identity as ClaimsIdentity, merchantId, cancellationToken); + MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, Guid.Empty, + estateId, merchantId, cancellationToken); List availableOperators = new List(); foreach (OperatorListViewModel operatorListViewModel in operatorViewModels) @@ -121,12 +113,15 @@ public async Task AssignOperatorToMerchant(AssignOperatorToMercha String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - AssignOperatorToMerchantModel model = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + AssignOperatorToMerchantModel model = ViewModelFactory.ConvertFrom(viewModel); try { - await this.ApiClient.AssignOperatorToMerchant(accessToken, this.User.Identity as ClaimsIdentity, viewModel.MerchantId, model, cancellationToken); + await this.ApiClient.AssignOperatorToMerchant(accessToken, Guid.Empty, + estateId, viewModel.MerchantId, model, cancellationToken); return this.RedirectToAction("GetMerchant", new @@ -162,11 +157,14 @@ public async Task AddMerchantDevice(AddMerchantDeviceViewModel vi String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - AddMerchantDeviceModel model = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + AddMerchantDeviceModel model = ViewModelFactory.ConvertFrom(viewModel); try { - await this.ApiClient.AddDeviceToMerchant(accessToken, this.User.Identity as ClaimsIdentity, viewModel.MerchantId, model, cancellationToken); + await this.ApiClient.AddDeviceToMerchant(accessToken, Guid.Empty, + estateId, viewModel.MerchantId, model, cancellationToken); return this.RedirectToAction("GetMerchant", new @@ -201,11 +199,14 @@ public async Task CreateMerchant(CreateMerchantViewModel viewMode { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - CreateMerchantModel createMerchantModel = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + CreateMerchantModel createMerchantModel = ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client to create the merchant CreateMerchantResponseModel createMerchantResponse = - await this.ApiClient.CreateMerchant(accessToken, this.User.Identity as ClaimsIdentity, createMerchantModel, cancellationToken); + await this.ApiClient.CreateMerchant(accessToken, Guid.Empty, + estateId, createMerchantModel, cancellationToken); // TODO: Investigate some kind of spinner... await Task.Delay(TimeSpan.FromSeconds(30)); @@ -243,9 +244,12 @@ public async Task GetMerchant([FromQuery] Guid merchantId, { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, this.User.Identity as ClaimsIdentity, merchantId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, Guid.Empty, + estateId, merchantId, cancellationToken); - return this.View("MerchantDetails", this.ViewModelFactory.ConvertFrom(merchantModel)); + return this.View("MerchantDetails", ViewModelFactory.ConvertFrom(merchantModel)); } catch(Exception e) { @@ -268,9 +272,12 @@ public async Task GetMerchantDeviceListAsJson([FromQuery] Guid me String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, this.User.Identity as ClaimsIdentity, merchantId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, Guid.Empty, + estateId, merchantId, cancellationToken); - MerchantViewModel viewModel = this.ViewModelFactory.ConvertFrom(merchantModel); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(merchantModel); return this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.Devices)); } @@ -306,9 +313,12 @@ public async Task GetMerchantListAsJson(CancellationToken cancell String searchValue = this.HttpContext.Request.Form["search[value]"].FirstOrDefault(); String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - List merchantList = await this.ApiClient.GetMerchants(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); - List merchantViewModels = this.ViewModelFactory.ConvertFrom(merchantList); + List merchantList = await this.ApiClient.GetMerchants(accessToken, Guid.Empty, + estateId, cancellationToken); + + List merchantViewModels = ViewModelFactory.ConvertFrom(merchantList); Expression> whereClause = m => m.MerchantName.Contains(searchValue, StringComparison.OrdinalIgnoreCase) || m.Town.Contains(searchValue, StringComparison.OrdinalIgnoreCase); @@ -336,9 +346,12 @@ public async Task GetMerchantOperatorListAsJson([FromQuery] Guid { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, this.User.Identity as ClaimsIdentity, merchantId, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + MerchantModel merchantModel = await this.ApiClient.GetMerchant(accessToken, Guid.Empty, + estateId, merchantId, cancellationToken); - MerchantViewModel viewModel = this.ViewModelFactory.ConvertFrom(merchantModel); + MerchantViewModel viewModel = ViewModelFactory.ConvertFrom(merchantModel); return this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.Operators)); } @@ -363,6 +376,8 @@ public async Task GetMerchantBalanceHistoryAsJson([FromQuery] Gui { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + // Start and End Date // Set the defaults DateTime startDateTime = DateTime.Now.AddDays(-1).Date; @@ -380,9 +395,10 @@ public async Task GetMerchantBalanceHistoryAsJson([FromQuery] Gui } List merchantBalanceHistory = - await this.ApiClient.GetMerchantBalanceHistory(accessToken, this.User.Identity as ClaimsIdentity, merchantId, startDateTime, endDateTime, cancellationToken); + await this.ApiClient.GetMerchantBalanceHistory(accessToken, Guid.Empty, + estateId, merchantId, startDateTime, endDateTime, cancellationToken); - MerchantBalanceHistoryListViewModel viewModel = this.ViewModelFactory.ConvertFrom(merchantBalanceHistory); + MerchantBalanceHistoryListViewModel viewModel = ViewModelFactory.ConvertFrom(merchantBalanceHistory); // Search Value from (Search box) String searchValue = this.HttpContext.Request.Form["search[value]"].FirstOrDefault(); @@ -404,13 +420,16 @@ public async Task GetMerchantBalanceAsJson([FromQuery] Guid merch try { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + Logger.LogInformation("[GetMerchantBalanceAsJson] - About to get merchant balance"); - MerchantBalanceModel merchantBalance = await this.ApiClient.GetMerchantBalance(accessToken, this.User.Identity as ClaimsIdentity, merchantId, cancellationToken); + MerchantBalanceModel merchantBalance = await this.ApiClient.GetMerchantBalance(accessToken, Guid.Empty, + estateId, merchantId, cancellationToken); Logger.LogInformation($"[GetMerchantBalanceAsJson] - Got merchant balance model - [{merchantBalance.AvailableBalance}]"); - MerchantBalanceViewModel viewModel = this.ViewModelFactory.ConvertFrom(merchantBalance); + MerchantBalanceViewModel viewModel = ViewModelFactory.ConvertFrom(merchantBalance); Logger.LogInformation($"[GetMerchantBalanceAsJson] - Got merchant balance viewModel - [{merchantBalance.AvailableBalance}]"); return this.Json(viewModel); @@ -450,13 +469,15 @@ public async Task MakeMerchantDeposit(MakeMerchantDepositViewMode try { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); - MakeMerchantDepositModel makeMerchantDepositModel = this.ViewModelFactory.ConvertFrom(viewModel); + MakeMerchantDepositModel makeMerchantDepositModel = ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client to create the golf club MakeMerchantDepositResponseModel makeMerchantDepositResponseModel = await this.ApiClient.MakeMerchantDeposit(accessToken, - this.User.Identity as ClaimsIdentity, + Guid.Empty, + estateId, Guid.Parse(viewModel.MerchantId), makeMerchantDepositModel, cancellationToken); diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/OperatorController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/OperatorController.cs index 3b1c72d..2afbdcc 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/OperatorController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/OperatorController.cs @@ -29,26 +29,14 @@ public class OperatorController : Controller /// The API client /// private readonly IApiClient ApiClient; - - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; - + #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public OperatorController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + + public OperatorController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion @@ -79,11 +67,14 @@ public async Task CreateOperator(CreateOperatorViewModel viewMode { String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - CreateOperatorModel createOperatorModel = this.ViewModelFactory.ConvertFrom(viewModel); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + CreateOperatorModel createOperatorModel = ViewModelFactory.ConvertFrom(viewModel); // All good with model, call the client to create the operator CreateOperatorResponseModel createOperatorResponse = - await this.ApiClient.CreateOperator(accessToken, this.User.Identity as ClaimsIdentity, createOperatorModel, cancellationToken); + await this.ApiClient.CreateOperator(accessToken, Guid.Empty, + estateId, createOperatorModel, cancellationToken); // Operator Created, redirect to the Operator List screen return this.RedirectToAction("GetOperatorList", @@ -125,9 +116,12 @@ public async Task GetOperatorListAsJson(CancellationToken cancell String accessToken = await this.HttpContext.GetTokenAsync("access_token"); - EstateModel estate = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken); + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + EstateModel estate = await this.ApiClient.GetEstate(accessToken, Guid.Empty, + estateId, cancellationToken); - List operatorViewModels = this.ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); + List operatorViewModels = ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators); Expression> whereClause = m => m.OperatorName.Contains(searchValue, StringComparison.OrdinalIgnoreCase); diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs index 5411139..ea3b21b 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs @@ -28,26 +28,15 @@ public class ReportingController : Controller /// The API client /// private readonly IApiClient ApiClient; - - /// - /// The view model factory - /// - private readonly IViewModelFactory ViewModelFactory; + #endregion #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The API client. - /// The view model factory. - public ReportingController(IApiClient apiClient, - IViewModelFactory viewModelFactory) + + public ReportingController(IApiClient apiClient) { this.ApiClient = apiClient; - this.ViewModelFactory = viewModelFactory; } #endregion diff --git a/EstateAdministrationUI/Areas/Estate/Models/ContractProductTypeViewModel.cs b/EstateAdministrationUI/Areas/Estate/Models/ContractProductTypeViewModel.cs index 859c9e4..614ea3a 100644 --- a/EstateAdministrationUI/Areas/Estate/Models/ContractProductTypeViewModel.cs +++ b/EstateAdministrationUI/Areas/Estate/Models/ContractProductTypeViewModel.cs @@ -2,6 +2,9 @@ namespace EstateAdministrationUI.Areas.Estate.Models { + using System.Diagnostics.CodeAnalysis; + + [ExcludeFromCodeCoverage] public class ContractProductTypeViewModel { public String ProductType { get; set; } diff --git a/EstateAdministrationUI/Bootstrapper/FactoryRegistry.cs b/EstateAdministrationUI/Bootstrapper/FactoryRegistry.cs deleted file mode 100644 index d05b504..0000000 --- a/EstateAdministrationUI/Bootstrapper/FactoryRegistry.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace EstateAdministrationUI.Bootstrapper; - -using BusinessLogic.Factories; -using Factories; -using Lamar; -using Microsoft.Extensions.DependencyInjection; -using System.Diagnostics.CodeAnalysis; - -[ExcludeFromCodeCoverage] -public class FactoryRegistry : ServiceRegistry -{ - public FactoryRegistry() - { - this.AddSingleton(); - this.AddSingleton(); - } -} \ No newline at end of file diff --git a/EstateAdministrationUI/Common/Helpers.cs b/EstateAdministrationUI/Common/Helpers.cs index 02c7153..b90a1ba 100644 --- a/EstateAdministrationUI/Common/Helpers.cs +++ b/EstateAdministrationUI/Common/Helpers.cs @@ -2,9 +2,11 @@ { using System; using System.Collections.Generic; + using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; + using System.Security.Claims; using Areas.Estate.Models; using BusinessLogic.Common; using Microsoft.AspNetCore.Http; @@ -13,6 +15,21 @@ [ExcludeFromCodeCoverage] public class Helpers { + public const String EstateIdClaimType = "estateId"; + + public static T GetClaimValue(ClaimsIdentity claimsIdentity, + String claimType) + { + if (!claimsIdentity.HasClaim(x => x.Type.ToLower() == claimType.ToLower())) + { + throw new InvalidOperationException($"User {claimsIdentity.Name} does not have Claim [{claimType}]"); + } + + Claim claim = claimsIdentity.Claims.Single(x => x.Type.ToLower() == claimType.ToLower()); + return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(claim.Value); + } + + /// /// Gets the data for data table. /// diff --git a/EstateAdministrationUI/Factories/IViewModelFactory.cs b/EstateAdministrationUI/Factories/IViewModelFactory.cs deleted file mode 100644 index c0a49d9..0000000 --- a/EstateAdministrationUI/Factories/IViewModelFactory.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace EstateAdministrationUI.Factories{ - using System; - using System.Collections.Generic; - using Areas.Estate.Models; - using BusinessLogic.Models; - - /// - /// - /// - public interface IViewModelFactory{ - #region Methods - - AssignOperatorToMerchantModel ConvertFrom(AssignOperatorToMerchantViewModel assignOperatorToMerchantViewModel); - - MerchantBalanceViewModel ConvertFrom(MerchantBalanceModel merchantBalanceModel); - - AddMerchantDeviceModel ConvertFrom(AddMerchantDeviceViewModel addMerchantDeviceViewModel); - - EstateViewModel ConvertFrom(EstateModel estateModel); - - ContractProductListViewModel ConvertFrom(ContractModel contractModel); - - ContractProductTransactionFeesListViewModel ConvertFrom(ContractProductModel contractProduct); - - CreateOperatorModel ConvertFrom(CreateOperatorViewModel createOperatorViewModel); - - CreateContractModel ConvertFrom(CreateContractViewModel createContractViewModel); - - List ConvertFrom(Guid estateId, - List estateOperatorModels); - - OperatorListViewModel ConvertFrom(Guid estateId, - EstateOperatorModel estateOperatorModel); - - CreateMerchantModel ConvertFrom(CreateMerchantViewModel createMerchantViewModel); - - List ConvertFrom(List merchantModels); - - List ConvertFrom(List contractModels); - - MerchantViewModel ConvertFrom(MerchantModel merchantModel); - - MerchantBalanceHistoryListViewModel ConvertFrom(List merchantBalanceModel); - - MakeMerchantDepositModel ConvertFrom(MakeMerchantDepositViewModel makeMerchantDepositViewModel); - - AddProductToContractModel ConvertFrom(CreateContractProductViewModel createContractProductViewModel); - - AddTransactionFeeToContractProductModel ConvertFrom(CreateContractProductTransactionFeeViewModel createContractProductTransactionFeeViewModel); - - List ConvertFrom(List models); - - FileImportLogViewModel ConvertFrom(FileImportLogModel model); - - FileDetailsViewModel ConvertFrom(FileDetailsModel model); - - List ConvertFrom(List contractProductTypeModels); - - #endregion - } -} \ No newline at end of file diff --git a/EstateAdministrationUI/Factories/ViewModelFactory.cs b/EstateAdministrationUI/Factories/ViewModelFactory.cs index eedc55b..d9d393f 100644 --- a/EstateAdministrationUI/Factories/ViewModelFactory.cs +++ b/EstateAdministrationUI/Factories/ViewModelFactory.cs @@ -8,17 +8,12 @@ using LamarCodeGeneration.Frames; using NuGet.Protocol.Core.Types; using FileLineProcessingResult = Areas.Estate.Models.FileLineProcessingResult; - - /// - /// - /// - /// - /// - public class ViewModelFactory : IViewModelFactory + + public static class ViewModelFactory { #region Methods - public AssignOperatorToMerchantModel ConvertFrom(AssignOperatorToMerchantViewModel assignOperatorToMerchantViewModel) + public static AssignOperatorToMerchantModel ConvertFrom(AssignOperatorToMerchantViewModel assignOperatorToMerchantViewModel) { if (assignOperatorToMerchantViewModel == null) { @@ -35,7 +30,7 @@ public AssignOperatorToMerchantModel ConvertFrom(AssignOperatorToMerchantViewMod return model; } - public MerchantBalanceViewModel ConvertFrom(MerchantBalanceModel merchantBalanceModel) + public static MerchantBalanceViewModel ConvertFrom(MerchantBalanceModel merchantBalanceModel) { if (merchantBalanceModel == null) { @@ -53,7 +48,7 @@ public MerchantBalanceViewModel ConvertFrom(MerchantBalanceModel merchantBalance return viewModel; } - public AddMerchantDeviceModel ConvertFrom(AddMerchantDeviceViewModel addMerchantDeviceViewModel) + public static AddMerchantDeviceModel ConvertFrom(AddMerchantDeviceViewModel addMerchantDeviceViewModel) { if (addMerchantDeviceViewModel == null) { @@ -67,7 +62,7 @@ public AddMerchantDeviceModel ConvertFrom(AddMerchantDeviceViewModel addMerchant return model; } - public EstateViewModel ConvertFrom(EstateModel estateModel) + public static EstateViewModel ConvertFrom(EstateModel estateModel) { if (estateModel == null) { @@ -83,7 +78,7 @@ public EstateViewModel ConvertFrom(EstateModel estateModel) return viewModel; } - public ContractProductListViewModel ConvertFrom(ContractModel contractModel) + public static ContractProductListViewModel ConvertFrom(ContractModel contractModel) { if (contractModel == null) { @@ -118,7 +113,7 @@ public ContractProductListViewModel ConvertFrom(ContractModel contractModel) return viewModel; } - private String GetProductTypeName(ProductType productType) => + public static String GetProductTypeName(ProductType productType) => productType switch{ ProductType.BillPayment => "Bill Payment", ProductType.MobileTopup => "Mobile Topup", @@ -126,7 +121,7 @@ productType switch{ _ => "Not Set" }; - public ContractProductTransactionFeesListViewModel ConvertFrom(ContractProductModel contractProduct) + public static ContractProductTransactionFeesListViewModel ConvertFrom(ContractProductModel contractProduct) { if (contractProduct == null) { @@ -164,7 +159,7 @@ public ContractProductTransactionFeesListViewModel ConvertFrom(ContractProductMo return viewModel; } - public CreateOperatorModel ConvertFrom(CreateOperatorViewModel createOperatorViewModel) + public static CreateOperatorModel ConvertFrom(CreateOperatorViewModel createOperatorViewModel) { if (createOperatorViewModel == null) { @@ -181,7 +176,7 @@ public CreateOperatorModel ConvertFrom(CreateOperatorViewModel createOperatorVie return createOperatorModel; } - public CreateContractModel ConvertFrom(CreateContractViewModel createContractViewModel) + public static CreateContractModel ConvertFrom(CreateContractViewModel createContractViewModel) { if (createContractViewModel == null) { @@ -197,8 +192,8 @@ public CreateContractModel ConvertFrom(CreateContractViewModel createContractVie return createContractModel; } - public List ConvertFrom(Guid estateId, - List estateOperatorModels) + public static List ConvertFrom(Guid estateId, + List estateOperatorModels) { if (estateOperatorModels == null || estateOperatorModels.Any() == false) { @@ -207,13 +202,13 @@ public List ConvertFrom(Guid estateId, List viewModels = new List(); - estateOperatorModels.ForEach(eo => viewModels.Add(this.ConvertFrom(estateId, eo))); + estateOperatorModels.ForEach(eo => viewModels.Add(ConvertFrom(estateId, eo))); return viewModels; } - public OperatorListViewModel ConvertFrom(Guid estateId, - EstateOperatorModel estateOperatorModel) + public static OperatorListViewModel ConvertFrom(Guid estateId, + EstateOperatorModel estateOperatorModel) { if (estateOperatorModel == null) { @@ -232,7 +227,7 @@ public OperatorListViewModel ConvertFrom(Guid estateId, return viewModel; } - public CreateMerchantModel ConvertFrom(CreateMerchantViewModel createMerchantViewModel) + public static CreateMerchantModel ConvertFrom(CreateMerchantViewModel createMerchantViewModel) { if (createMerchantViewModel == null) { @@ -269,7 +264,7 @@ public CreateMerchantModel ConvertFrom(CreateMerchantViewModel createMerchantVie return createMerchantModel; } - public List ConvertFrom(List merchantModels) + public static List ConvertFrom(List merchantModels) { if (merchantModels == null || merchantModels.Any() == false) { @@ -301,7 +296,7 @@ public List ConvertFrom(List merchantModel return viewModels; } - public List ConvertFrom(List contractModels) + public static List ConvertFrom(List contractModels) { if (contractModels == null) { @@ -326,7 +321,7 @@ public List ConvertFrom(List contractModel return viewModels; } - public MerchantViewModel ConvertFrom(MerchantModel merchantModel) + public static MerchantViewModel ConvertFrom(MerchantModel merchantModel) { if (merchantModel == null) { @@ -341,15 +336,15 @@ public MerchantViewModel ConvertFrom(MerchantModel merchantModel) viewModel.Balance = merchantModel.Balance; viewModel.SettlementSchedule = (Int32)merchantModel.SettlementSchedule; viewModel.AvailableBalance = merchantModel.AvailableBalance; - viewModel.Addresses = this.ConvertFrom(merchantModel.Addresses); - viewModel.Contacts = this.ConvertFrom(merchantModel.Contacts); - viewModel.Operators = this.ConvertFrom(merchantModel.Operators); - viewModel.Devices = this.ConvertFrom(merchantModel.Devices); + viewModel.Addresses = ConvertFrom(merchantModel.Addresses); + viewModel.Contacts = ConvertFrom(merchantModel.Contacts); + viewModel.Operators = ConvertFrom(merchantModel.Operators); + viewModel.Devices = ConvertFrom(merchantModel.Devices); return viewModel; } - public MerchantBalanceHistoryListViewModel ConvertFrom(List merchantBalanceModel) + public static MerchantBalanceHistoryListViewModel ConvertFrom(List merchantBalanceModel) { if (merchantBalanceModel == null) { @@ -380,7 +375,7 @@ public MerchantBalanceHistoryListViewModel ConvertFrom(List ConvertFrom(List models) + public static List ConvertFrom(List models) { if (models == null || models.Any() == false) { @@ -445,13 +440,13 @@ public List ConvertFrom(List models) foreach (FileImportLogModel fileImportLogModel in models) { - viewModels.Add(this.ConvertFrom(fileImportLogModel)); + viewModels.Add(ConvertFrom(fileImportLogModel)); } return viewModels; } - public FileImportLogViewModel ConvertFrom(FileImportLogModel model) + public static FileImportLogViewModel ConvertFrom(FileImportLogModel model) { if (model == null) { @@ -489,7 +484,7 @@ public FileImportLogViewModel ConvertFrom(FileImportLogModel model) return viewModel; } - public FileDetailsViewModel ConvertFrom(FileDetailsModel model) + public static FileDetailsViewModel ConvertFrom(FileDetailsModel model) { if (model == null) { @@ -532,7 +527,7 @@ public FileDetailsViewModel ConvertFrom(FileDetailsModel model) }; // Translate the processing result - (FileLineProcessingResult result, String stringResult) processingResult = this.ConvertFrom(modelFileLine.ProcessingResult); + (FileLineProcessingResult result, String stringResult) processingResult = ConvertFrom(modelFileLine.ProcessingResult); fileLineViewModel.ProcessingResult = processingResult.result; fileLineViewModel.ProcessingResultString = processingResult.stringResult; @@ -545,7 +540,7 @@ public FileDetailsViewModel ConvertFrom(FileDetailsModel model) return viewModel; } - public List ConvertFrom(List contractProductTypeModels){ + public static List ConvertFrom(List contractProductTypeModels){ List result = new List(); foreach (ContractProductTypeModel contractProductTypeModel in contractProductTypeModels){ @@ -557,9 +552,8 @@ public List ConvertFrom(List ConvertFrom(List ConvertFrom(Dictionary deviceModels) + private static Dictionary ConvertFrom(Dictionary deviceModels) { Dictionary viewModels = new Dictionary(); @@ -605,7 +599,7 @@ private Dictionary ConvertFrom(Dictionary deviceMo return viewModels; } - private List ConvertFrom(List addressModels) + private static List ConvertFrom(List addressModels) { List viewModels = new List(); @@ -616,13 +610,13 @@ private List ConvertFrom(List addressModels) foreach (AddressModel model in addressModels) { - viewModels.Add(this.ConvertFrom(model)); + viewModels.Add(ConvertFrom(model)); } return viewModels; } - private AddressViewModel ConvertFrom(AddressModel addressModel) + private static AddressViewModel ConvertFrom(AddressModel addressModel) { return new AddressViewModel { @@ -638,7 +632,7 @@ private AddressViewModel ConvertFrom(AddressModel addressModel) }; } - private List ConvertFrom(List contactModels) + private static List ConvertFrom(List contactModels) { List viewModels = new List(); @@ -649,13 +643,13 @@ private List ConvertFrom(List contactModels) foreach (ContactModel model in contactModels) { - viewModels.Add(this.ConvertFrom(model)); + viewModels.Add(ConvertFrom(model)); } return viewModels; } - private ContactViewModel ConvertFrom(ContactModel contactModel) + private static ContactViewModel ConvertFrom(ContactModel contactModel) { return new ContactViewModel { @@ -666,7 +660,7 @@ private ContactViewModel ConvertFrom(ContactModel contactModel) }; } - private List ConvertFrom(List operatorModels) + private static List ConvertFrom(List operatorModels) { List viewModels = new List(); @@ -677,13 +671,13 @@ private List ConvertFrom(List foreach (MerchantOperatorModel model in operatorModels) { - viewModels.Add(this.ConvertFrom(model)); + viewModels.Add(ConvertFrom(model)); } return viewModels; } - private MerchantOperatorViewModel ConvertFrom(MerchantOperatorModel operatorModel) + private static MerchantOperatorViewModel ConvertFrom(MerchantOperatorModel operatorModel) { return new MerchantOperatorViewModel { diff --git a/EstateAdministrationUI/Startup.cs b/EstateAdministrationUI/Startup.cs index 84dfcb6..fd3895e 100644 --- a/EstateAdministrationUI/Startup.cs +++ b/EstateAdministrationUI/Startup.cs @@ -65,7 +65,6 @@ public void ConfigureContainer(ServiceRegistry services) services.IncludeRegistry(); services.IncludeRegistry(); - services.IncludeRegistry(); Startup.Container = new Container(services); }