Пример #1
0
            public async Task AddContactGet_ReturnsViewModel(
                [Frozen] Mock <ICustomerService> customerService,
                EditCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                customerService.Setup(x => x.AddContact(
                                          It.IsAny <string>(), It.IsAny <string>()
                                          ))
                .ReturnsAsync(viewModel);

                //Act
                var actionResult = await sut.AddContact(
                    viewModel.AccountNumber,
                    viewModel.CustomerName
                    );

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

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

                customerService.Verify(x => x.AddContact(
                                           It.IsAny <string>(), It.IsAny <string>())
                                       );
            }
Пример #2
0
            public async Task AddContactPost_InvalidModelState_ReturnsViewModel(
                EditCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Arrange
                sut.ModelState.AddModelError("AccountNumber", "AW00000001");

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

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

                viewResult.Model.Should().Be(viewModel);
            }
Пример #3
0
            public async Task AddContactEmailAddressPost_ValidModelState_ReturnsRedirect(
                [Frozen] Mock <ICustomerService> customerService,
                EditCustomerContactViewModel viewModel,
                [Greedy] CustomerController sut
                )
            {
                //Act
                var actionResult = await sut.AddContact(viewModel);

                //Assert
                customerService.Verify(x => x.AddContact(
                                           It.IsAny <EditCustomerContactViewModel>()
                                           ));

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