public async Task GetRegisteredOfficeAddress_ApiThrowsException_ExceptionShouldNotBeCaught() { // Arrange IWeeeClient weeeClient = A.Fake<IWeeeClient>(); A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetOrganisationInfo>._)) .Throws<Exception>(); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); // Act Func<Task<ActionResult>> action = async () => await controller.RegisteredOfficeAddress(A.Dummy<Guid>()); // Assert await Assert.ThrowsAnyAsync<Exception>(action); }
public async Task GetRegisteredOfficeAddress_ApiReturnsOrganisationData_ReturnsViewWithModel() { // Arrange AddressData addressData = new AddressData(); addressData.Address1 = "Address Line 1"; OrganisationData organisationData = new OrganisationData(); organisationData.Id = new Guid("1B7329B9-DC7F-4621-8E97-FD97CDDDBA10"); organisationData.OrganisationType = OrganisationType.RegisteredCompany; organisationData.HasBusinessAddress = true; organisationData.BusinessAddress = addressData; IWeeeClient weeeClient = A.Fake<IWeeeClient>(); A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetOrganisationInfo>._)) .Returns(organisationData); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); // Act ActionResult result = await controller.RegisteredOfficeAddress(new Guid("1B7329B9-DC7F-4621-8E97-FD97CDDDBA10")); // Assert ViewResult viewResult = result as ViewResult; Assert.NotNull(viewResult); AddressViewModel viewModel = viewResult.Model as AddressViewModel; Assert.NotNull(viewModel); Assert.Equal(new Guid("1B7329B9-DC7F-4621-8E97-FD97CDDDBA10"), viewModel.OrganisationId); Assert.Equal(OrganisationType.RegisteredCompany, viewModel.OrganisationType); Assert.Equal("Address Line 1", viewModel.Address.Address1); }
public async Task PostRegisteredOfficeAddress_ModelStateIsInvalid_ReturnsViewModel() { // Arrange IWeeeClient weeeClient = A.Dummy<IWeeeClient>(); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); var model = new AddressViewModel(); controller.ModelState.AddModelError("Key", "Error"); // To make the model state invalid // Act ActionResult result = await controller.RegisteredOfficeAddress(model); // Assert ViewResult viewResult = result as ViewResult; Assert.NotNull(viewResult); Assert.Equal(model, viewResult.Model); }
public async Task PostRegisteredOfficeAddress_PrincipalPlaceOfBusinessIsValid_RedirectsToReviewOrganisationDetails() { // Arrange IWeeeClient weeeClient = A.Fake<IWeeeClient>(); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); AddressViewModel model = new AddressViewModel(); // Act ActionResult result = await controller.RegisteredOfficeAddress(model); // Assert RedirectToRouteResult redirectToRouteResult = result as RedirectToRouteResult; Assert.NotNull(redirectToRouteResult); Assert.Equal("ReviewOrganisationDetails", redirectToRouteResult.RouteValues["action"]); }
public async void PostRegisteredOfficeAddress_PrincipalPlaceOfBusinessIsValid_CallsApiToAddAddressToOrganisation() { // Arrange IWeeeClient weeeClient = A.Fake<IWeeeClient>(); ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>(); OrganisationRegistrationController controller = new OrganisationRegistrationController( () => weeeClient, organisationSearcher); AddressViewModel model = new AddressViewModel(); // Act ActionResult result = await controller.RegisteredOfficeAddress(model); // Assert A.CallTo(() => weeeClient.SendAsync(A<string>._, A<AddAddressToOrganisation>._)) .MustHaveHappened(Repeated.Exactly.Once); }