Example #1
0
        public async Task ThenTheCharityRegistrationNumberShouldBeUsedToFindTheCharity()
        {
            //Arrange
            var model = new AddLegalEntityViewModel
            {
                OrganisationType          = OrganisationType.Charities,
                CharityRegistrationNumber = "12345"
            };

            //Act
            var result = await _controller.AddOrganisation(model);

            //Assert
            _orchestrator.Verify(x => x.GetCharityByRegistrationNumber(It.Is <string>(s => s == "12345"), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
        public async Task ThenIGetTheAddOrganisationView()
        {
            //Act
            var result = await _controller.AddOrganisation("ABC123") as ViewResult;

            //Assert
            _orchestrator.Verify(x => x.GetAddLegalEntityViewModel(It.Is <string>(s => s == "ABC123"), It.IsAny <string>()), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
        }
        public async Task ThenIShouldGetCompanyDetailsBackIfTheyExist()
        {
            //Arrange
            var viewModel = new OrganisationDetailsViewModel
            {
                HashedId        = "1",
                Name            = "Test Corp",
                ReferenceNumber = "0123456",
                DateOfInception = DateTime.Now,
                Address         = "1 Test Road, Test City, TE12 3ST",
                Status          = "active"
            };

            _orchestrator.Setup(x => x.GetLimitedCompanyByRegistrationNumber(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new OrchestratorResponse <OrganisationDetailsViewModel>
            {
                Data = viewModel
            });

            var username = "******";

            _owinWrapper.Setup(x => x.GetClaimValue(It.IsAny <string>())).Returns(username);

            var addModel = new AddLegalEntityViewModel
            {
                HashedAccountId      = viewModel.HashedId,
                OrganisationType     = OrganisationType.CompaniesHouse,
                CompaniesHouseNumber = viewModel.ReferenceNumber
            };

            //Act
            var result = await _controller.AddOrganisation(addModel) as ViewResult;

            //Assert
            Assert.IsNotNull(result);

            _orchestrator.Verify(x => x.GetLimitedCompanyByRegistrationNumber(viewModel.ReferenceNumber, viewModel.HashedId, username), Times.Once);

            var model = result.Model as OrchestratorResponse <OrganisationDetailsViewModel>;

            Assert.IsNotNull(model?.Data);
        }
        public async Task ThenOnModelValidationErrorsIAmReturnedToTheViewAndTheErrorsAreInTheErrorDictionary()
        {
            //Arrange
            var model = new AddLegalEntityViewModel();

            _controller.ModelState.AddModelError("OrganisationType", "Organisation Type Error Message");

            //Act
            var result = await _controller.AddOrganisation(model);

            //Assert
            var viewResult = result as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.AreEqual("", viewResult.ViewName);

            var viewModel = viewResult.Model as OrchestratorResponse <AddLegalEntityViewModel>;

            Assert.IsNotNull(viewModel);
            Assert.IsTrue(viewModel.Data.ErrorDictionary.ContainsKey("OrganisationType"));
        }