public async Task DeleteContact(DeleteCustomerContactViewModel viewModel)
        {
            logger.LogInformation("DeleteContact 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);

            Guard.Against.Null(contact, nameof(contact));
            customerToUpdate.Contacts.Remove(contact);

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

            logger.LogInformation("Customer updated successfully");
        }
Example #2
0
            public async Task DeleteContactGet_ReturnsViewModel(
                [Frozen] Mock <ICustomerService> customerService,
                DeleteCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                customerService.Setup(x => x.GetCustomerContactForDelete(
                                          It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()
                                          ))
                .ReturnsAsync(viewModel);

                //Act
                var actionResult = await sut.DeleteContact(
                    viewModel.AccountNumber,
                    viewModel.ContactPerson.FullName(),
                    viewModel.ContactType
                    );

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

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

                customerService.Verify(x => x.GetCustomerContactForDelete(
                                           It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())
                                       );
            }
        public async Task <IActionResult> DeleteContact(DeleteCustomerContactViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await customerService.DeleteContact(viewModel);

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

            return(View(viewModel));
        }
Example #4
0
            public async Task DeleteContactPost_InvalidModelState_ReturnsViewModel(
                DeleteCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                sut.ModelState.AddModelError("AccountNumber", "AW00000001");

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

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

                viewResult.Model.Should().Be(viewModel);
            }
Example #5
0
        public async Task DeleteContact_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 DeleteCustomerContactViewModel
            {
                AccountNumber = "AW00000001",
                CustomerName  = "A Bike Store",
                ContactPerson = new PersonViewModel
                {
                    FirstName  = "Orlando",
                    MiddleName = "N.",
                    LastName   = "Gee"
                },
                ContactType = "Owner"
            };
            await svc.DeleteContact(viewModel);

            //Assert
            mockCustomerApi.Verify(x => x.UpdateCustomerAsync(
                                       It.IsAny <string>(),
                                       It.IsAny <customerApi.Models.UpdateCustomer.Customer>()
                                       ));
        }
Example #6
0
            public async Task DeleteContactPost_ValidModelState_ReturnsRedirect(
                [Frozen] Mock <ICustomerService> customerService,
                DeleteCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Act
                var actionResult = await sut.DeleteContact(viewModel);

                //Assert
                customerService.Verify(x => x.DeleteContact(
                                           It.IsAny <DeleteCustomerContactViewModel>()
                                           ));

                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);
            }