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

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

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

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

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

            var contact = customerToUpdate.Contacts.FirstOrDefault(c =>
                                                                   c.ContactType == viewModel.ContactType &&
                                                                   c.ContactPerson.FullName() == viewModel.ContactName);

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

            var personEmailAddress = contact.ContactPerson.EmailAddresses.FirstOrDefault(c =>
                                                                                         c.EmailAddress == viewModel.EmailAddress
                                                                                         );

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

            contact.ContactPerson.EmailAddresses.Remove(personEmailAddress);

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

            logger.LogInformation("Customer updated successfully");
        }
コード例 #2
0
            public async Task DeleteContactEmailAddressGet_ReturnsViewModel(
                [Frozen] Mock <ICustomerService> customerService,
                DeleteContactEmailAddressViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                customerService.Setup(x => x.GetContactEmailAddressForDelete(
                                          It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()
                                          ))
                .ReturnsAsync(viewModel);

                //Act
                var actionResult = await sut.DeleteContactEmailAddress(
                    viewModel.AccountNumber,
                    viewModel.ContactType,
                    viewModel.ContactName,
                    viewModel.EmailAddress
                    );

                //Assert
                var viewResult = actionResult.Should().BeAssignableTo <ViewResult>().Subject;

                viewResult.Model.Should().Be(viewModel);

                customerService.Verify(x => x.GetContactEmailAddressForDelete(
                                           It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()
                                           ));
            }
コード例 #3
0
        public async Task <IActionResult> DeleteContactEmailAddress(DeleteContactEmailAddressViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await customerService.DeleteContactEmailAddress(viewModel);

                return(RedirectToAction("Detail", new { viewModel.AccountNumber }));
            }

            return(View(viewModel));
        }
コード例 #4
0
        public DeleteContactEmailAddressViewModel DeleteContactEmailAddress(string accountNumber, string contactType, string contactName, string emailAddress)
        {
            logger.LogInformation("DeleteContactEmailAddress called");

            var vm = new DeleteContactEmailAddressViewModel
            {
                AccountNumber = accountNumber,
                ContactType   = contactType,
                ContactName   = contactName,
                EmailAddress  = emailAddress
            };

            return(vm);
        }
コード例 #5
0
            public async Task DeleteContactEmailAddressPost_InvalidModelState_ReturnsViewModel(
                DeleteContactEmailAddressViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                sut.ModelState.AddModelError("AccountNumber", "AW00000001");

                //Act
                var actionResult = await sut.DeleteContactEmailAddress(viewModel);

                //Assert
                var viewResult = actionResult.Should().BeAssignableTo <ViewResult>().Subject;

                viewResult.Model.Should().Be(viewModel);
            }
コード例 #6
0
            public async Task DeleteContactEmailAddressPost_ValidModelState_ReturnsRedirect(
                [Frozen] Mock <ICustomerService> customerService,
                DeleteContactEmailAddressViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Act
                var actionResult = await sut.DeleteContactEmailAddress(viewModel);

                //Assert
                customerService.Verify(x => x.DeleteContactEmailAddress(
                                           It.IsAny <DeleteContactEmailAddressViewModel>()
                                           ));

                var redirectResult = actionResult.Should().BeAssignableTo <RedirectToActionResult>().Subject;

                redirectResult.ActionName.Should().Be("Detail");
                redirectResult.RouteValues.Count.Should().Be(1);
                redirectResult.RouteValues.ContainsKey("AccountNumber");
                redirectResult.RouteValues.Values.Contains(viewModel.AccountNumber);
            }