コード例 #1
0
        public async Task AddContactPhoneNumber(EditPhoneNumberViewModel viewModel)
        {
            logger.LogInformation("AddContactPhoneNumber called");

            logger.LogInformation("Getting customer for {AccountNumber}", viewModel.AccountNumber);
            var customer = await customerApiClient.GetCustomerAsync <Infrastructure.ApiClients.CustomerApi.Models.GetCustomer.StoreCustomer>(
                viewModel.AccountNumber
                );

            logger.LogInformation("Retrieved customer {@Customer}", customer);
            Guard.Against.Null(customer, nameof(customer));

            var customerToUpdate = mapper.Map <Infrastructure.ApiClients.CustomerApi.Models.UpdateCustomer.StoreCustomer>(customer);

            Guard.Against.Null(customerToUpdate, nameof(customerToUpdate));

            var contact = customerToUpdate.Contacts.FirstOrDefault(c => c.ContactPerson.FullName() == viewModel.PersonName);

            Guard.Against.Null(contact, nameof(contact));

            contact.ContactPerson.PhoneNumbers.Add(new Infrastructure.ApiClients.CustomerApi.Models.UpdateCustomer.PersonPhone
            {
                PhoneNumberType = viewModel.PhoneNumberType,
                PhoneNumber     = viewModel.PhoneNumber
            });

            logger.LogInformation("Updating customer {@Customer}", customer);
            await customerApiClient.UpdateCustomerAsync(viewModel.AccountNumber, customerToUpdate);

            logger.LogInformation("Customer updated successfully");
        }
コード例 #2
0
        public async Task AddIndividualCustomerPhoneNumber(EditPhoneNumberViewModel viewModel)
        {
            logger.LogInformation("AddIndividualCustomerPhoneNumber called");

            logger.LogInformation("Getting customer for {AccountNumber}", viewModel.AccountNumber);
            var customer = await customerApiClient.GetCustomerAsync <Web.Infrastructure.ApiClients.CustomerApi.Models.GetCustomer.IndividualCustomer>(
                viewModel.AccountNumber
                );

            logger.LogInformation("Retrieved customer {@Customer}", customer);
            Guard.Against.Null(customer, nameof(customer));

            var customerToUpdate = mapper.Map <Infrastructure.ApiClients.CustomerApi.Models.UpdateCustomer.IndividualCustomer>(customer);

            Guard.Against.Null(customerToUpdate, nameof(customerToUpdate));

            customerToUpdate.Person.PhoneNumbers.Add(new Infrastructure.ApiClients.CustomerApi.Models.UpdateCustomer.PersonPhone
            {
                PhoneNumberType = viewModel.PhoneNumberType,
                PhoneNumber     = viewModel.PhoneNumber
            });

            logger.LogInformation("Updating customer {@Customer}", customer);
            await customerApiClient.UpdateCustomerAsync(viewModel.AccountNumber, customerToUpdate);

            logger.LogInformation("Customer updated successfully");
        }
コード例 #3
0
        public EditPhoneNumberViewModel AddPhoneNumber(string accountNumber, string personName)
        {
            logger.LogInformation("AddPhoneNumber called");

            var vm = new EditPhoneNumberViewModel
            {
                IsNewPhoneNumber = true,
                AccountNumber    = accountNumber,
                PersonName       = personName
            };

            return(vm);
        }
コード例 #4
0
        public async Task AddContactPhoneNumber_OK()
        {
            //Arrange
            var mockLogger           = new Mock <ILogger <CustomerService> >();
            var mockCustomerApi      = new Mock <customerApi.ICustomerApiClient>();
            var mockReferenceDataApi = new Mock <referenceDataApi.IReferenceDataApiClient>();
            var mockSalesPersonApi   = new Mock <salesPersonApi.ISalesPersonApiClient>();

            mockCustomerApi
            .Setup(x => x.GetCustomerAsync <customerApi.Models.GetCustomer.StoreCustomer>(It.IsAny <string>()))
            .ReturnsAsync(new StoreCustomerBuilder()
                          .WithTestValues()
                          .Build()
                          );

            var svc = new CustomerService(
                mockLogger.Object,
                Mapper.CreateMapper(),
                mockCustomerApi.Object,
                mockReferenceDataApi.Object,
                mockSalesPersonApi.Object
                );

            //Act
            var viewModel = new EditPhoneNumberViewModel
            {
                IsNewPhoneNumber = true,
                AccountNumber    = "AW00000001",
                PersonName       = "Orlando N. Gee",
                PhoneNumberType  = "Cell",
                PhoneNumber      = "245-555-0173"
            };
            await svc.AddContactPhoneNumber(viewModel);

            //Assert
            mockCustomerApi.Verify(x => x.UpdateCustomerAsync(
                                       It.IsAny <string>(),
                                       It.IsAny <customerApi.Models.UpdateCustomer.Customer>()
                                       ));
        }