示例#1
0
        public ActionResult OrganisationSummary()
        {
            var entity       = SessionHelper.CurrentEntity;
            var organisation = entity.Organisation;


            var vm = new OrganisationSummaryViewModel(organisation);

            return(PartialView("OrganisationSummary", vm));
        }
        public async Task PostConfirmOrganisationDetails_ValidModel_ReturnsConfirmationView()
        {
            // Arrange
            IWeeeClient weeeClient = A.Fake<IWeeeClient>();
            
            ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>();

            OrganisationRegistrationController controller = new OrganisationRegistrationController(
                () => weeeClient,
                organisationSearcher);

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<CompleteRegistration>._))
                .Returns(Guid.NewGuid());

            OrganisationSummaryViewModel model = new OrganisationSummaryViewModel();

            // Act
            ActionResult result = await controller.ConfirmOrganisationDetails(model, Guid.NewGuid());

            // Assert
            var redirectToRouteResult = ((RedirectToRouteResult)result);

            Assert.Equal("Confirmation", redirectToRouteResult.RouteValues["action"]);
        }
        public async Task PostConfirmOrganisationDetails_WithInvalidModel_ReturnsView()
        {
            // Arrange
            IWeeeClient weeeClient = A.Dummy<IWeeeClient>();
            ISearcher<OrganisationSearchResult> organisationSearcher = A.Dummy<ISearcher<OrganisationSearchResult>>();

            OrganisationRegistrationController controller = new OrganisationRegistrationController(
                () => weeeClient,
                organisationSearcher);

            controller.ModelState.AddModelError("Key", "Error");

            OrganisationSummaryViewModel model = new OrganisationSummaryViewModel();

            // Act
            ActionResult result = await controller.ConfirmOrganisationDetails(model, Guid.NewGuid());

            // Assert
            ViewResult viewResult = result as ViewResult;
            Assert.False(viewResult.ViewData.ModelState.IsValid);
        }
        public async Task<ActionResult> ConfirmOrganisationDetails(OrganisationSummaryViewModel model, Guid organisationId)
        {
            if (!ModelState.IsValid)
            {
                return View("ReviewOrganisationDetails", model);
            }
            try
            {
                using (var client = apiClient())
                {
                    await
                        client.SendAsync(User.GetAccessToken(),
                            new CompleteRegistration(organisationId));
                }

                return RedirectToAction("Confirmation", new
                {
                    organisationName = model.OrganisationData.OrganisationType == OrganisationType.RegisteredCompany ? model.OrganisationData.Name : model.OrganisationData.TradingName
                });
            }
            catch (ApiBadRequestException ex)
            {
                this.HandleBadRequest(ex);

                if (ModelState.IsValid)
                {
                    throw;
                }
            }

            return await ReviewOrganisationDetails(organisationId);
        }
        public async Task<ActionResult> ReviewOrganisationDetails(Guid organisationId)
        {
            using (var client = apiClient())
            {
                var organisationExists =
                   await client.SendAsync(User.GetAccessToken(), new VerifyOrganisationExists(organisationId));

                if (!organisationExists)
                {
                    throw new ArgumentException("No organisation found for supplied organisation Id", "organisationId");
                }

                OrganisationData organisationData = await client.SendAsync(
                    User.GetAccessToken(),
                    new GetOrganisationInfo(organisationId));

                var model = new OrganisationSummaryViewModel()
                {
                    OrganisationData = organisationData,
                };

                return View(model);
            }
        }