public async Task Index_Redirects_To_FrontEnd()
        {
            var frontendUrlMock = new Mock <IFrontendUrlService>();

            frontendUrlMock.Setup(x => x.ShouldRedirectOrganisationShow()).Returns(true);
            frontendUrlMock.Setup(x => x.RedirectToFrontend("/organisations")).Returns(new RedirectResult("frontend"));
            var controller = new OrganisationController(null, frontendUrlMock.Object);

            var result = await controller.Index();

            Assert.IsTrue(result is RedirectResult);
        }
コード例 #2
0
        public async void GetIndex_WithInactiveAndRejectedAssociation_ShowsOnlyInactiveAssociation()
        {
            // Arrange
            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetUserOrganisationsByStatus> ._))
            .Returns(new List <OrganisationUserData>
            {
                new OrganisationUserData
                {
                    OrganisationId = new Guid("EF4B78BA-3D73-4B99-A996-714677590A78"),
                    UserStatus     = UserStatus.Inactive,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 1",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                },
                new OrganisationUserData
                {
                    OrganisationId = new Guid("EF4B78BA-3D73-4B99-A996-714677590A78"),
                    UserStatus     = UserStatus.Rejected,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 1",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                }
            });

            OrganisationController controller = new OrganisationController(() => weeeClient);

            // Act
            ActionResult result = await controller.Index();

            // Assert
            Assert.IsAssignableFrom <ViewResultBase>(result);
            ViewResultBase viewResult = result as ViewResultBase;

            Assert.IsAssignableFrom <PendingOrganisationsViewModel>(viewResult.Model);
            PendingOrganisationsViewModel model = viewResult.Model as PendingOrganisationsViewModel;

            Assert.Equal(1, model.InaccessibleOrganisations.Count());
            OrganisationUserData result1 = model.InaccessibleOrganisations.First();

            Assert.Equal(UserStatus.Inactive, result1.UserStatus);
        }
コード例 #3
0
        public async void GetIndex_OneInactiveOrg_ShowsPendingView()
        {
            // Arrange
            Guid organisationId = new Guid("433DB128-12A1-44FB-B26A-8128F8E36598");

            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetUserOrganisationsByStatus> ._))
            .Returns(new List <OrganisationUserData>
            {
                new OrganisationUserData
                {
                    OrganisationId = organisationId,
                    UserStatus     = UserStatus.Pending,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 1",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                }
            });

            OrganisationController controller = new OrganisationController(() => weeeClient);

            // Act
            ActionResult result = await controller.Index();

            // Assert
            Assert.IsAssignableFrom <ViewResult>(result);

            ViewResult viewResult = result as ViewResult;

            Assert.Equal("PendingOrganisations", viewResult.ViewName);

            Assert.IsAssignableFrom <PendingOrganisationsViewModel>(viewResult.Model);

            PendingOrganisationsViewModel model = viewResult.Model as PendingOrganisationsViewModel;

            Assert.Equal(1, model.InaccessibleOrganisations.Count());

            Assert.Equal(organisationId, model.InaccessibleOrganisations.First().OrganisationId);
            Assert.Equal("Organisation Name 1", model.InaccessibleOrganisations.First().Organisation.OrganisationName);
        }
コード例 #4
0
        public async void GetIndex_NoOrganisations_RedirectsToCreateJoinOrganisation()
        {
            // Arrange
            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetUserOrganisationsByStatus> ._))
            .Returns(new List <OrganisationUserData>());

            OrganisationController controller = new OrganisationController(() => weeeClient);

            // Act
            ActionResult result = await controller.Index();

            // Assert
            Assert.IsAssignableFrom <RedirectToRouteResult>(result);

            RedirectToRouteResult redirectResult = result as RedirectToRouteResult;

            Assert.Equal(null, redirectResult.RouteValues["area"] as string, ignoreCase: true);
            Assert.Equal("organisationregistration", redirectResult.RouteValues["controller"] as string, ignoreCase: true);
            Assert.Equal("Search", redirectResult.RouteValues["action"] as string, ignoreCase: true);
        }
コード例 #5
0
        public async void GetIndex_OneActiveOrg_RedirectsToSchemeChooseActivity()
        {
            // Arrange
            Guid organisationId = new Guid("433DB128-12A1-44FB-B26A-8128F8E36598");

            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetUserOrganisationsByStatus> ._))
            .Returns(new List <OrganisationUserData>
            {
                new OrganisationUserData
                {
                    OrganisationId = organisationId,
                    UserStatus     = UserStatus.Active,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 1",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                }
            });

            OrganisationController controller = new OrganisationController(() => weeeClient);

            // Act
            ActionResult result = await controller.Index();

            // Assert
            Assert.IsAssignableFrom <RedirectToRouteResult>(result);

            RedirectToRouteResult redirectResult = result as RedirectToRouteResult;

            Assert.Equal("scheme", redirectResult.RouteValues["area"] as string, ignoreCase: true);
            Assert.Equal("home", redirectResult.RouteValues["controller"] as string, ignoreCase: true);
            Assert.Equal("chooseactivity", redirectResult.RouteValues["action"] as string, ignoreCase: true);
            Assert.Equal(organisationId, redirectResult.RouteValues["pcsId"]);
        }
コード例 #6
0
        public async void GetIndex_OneActiveOrg_And_OneInactiveOrg_ShowsYourOrganisationsView()
        {
            // Arrange
            Guid organisationId1 = new Guid("433DB128-12A1-44FB-B26A-8128F8E36598");
            Guid organisationId2 = new Guid("90F0D10D-BE4E-462C-A214-30B94C461F8B");

            IWeeeClient weeeClient = A.Fake <IWeeeClient>();

            A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetUserOrganisationsByStatus> ._))
            .Returns(new List <OrganisationUserData>
            {
                new OrganisationUserData
                {
                    OrganisationId = organisationId1,
                    UserStatus     = UserStatus.Active,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 1",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                },
                new OrganisationUserData
                {
                    OrganisationId = organisationId2,
                    UserStatus     = UserStatus.Pending,
                    Organisation   = new OrganisationData
                    {
                        OrganisationName   = "Organisation Name 2",
                        OrganisationStatus = OrganisationStatus.Complete,
                    }
                }
            });

            OrganisationController controller = new OrganisationController(() => weeeClient);

            // Act
            ActionResult result = await controller.Index();

            // Assert
            Assert.IsAssignableFrom <ViewResult>(result);

            ViewResult viewResult = result as ViewResult;

            Assert.Equal("YourOrganisations", viewResult.ViewName);

            Assert.IsAssignableFrom <YourOrganisationsViewModel>(viewResult.Model);

            YourOrganisationsViewModel model = viewResult.Model as YourOrganisationsViewModel;

            Assert.Equal(1, model.Organisations.Count);

            Assert.Equal(organisationId1, model.Organisations[0].OrganisationId);
            Assert.Equal("Organisation Name 1", model.Organisations[0].Organisation.OrganisationName);

            Assert.IsAssignableFrom <IEnumerable <OrganisationUserData> >(viewResult.ViewBag.InaccessibleOrganisations);

            IEnumerable <OrganisationUserData> inaccessibleOrganisations =
                viewResult.ViewBag.InaccessibleOrganisations as IEnumerable <OrganisationUserData>;

            Assert.Equal(1, inaccessibleOrganisations.Count());

            Assert.Equal(organisationId2, inaccessibleOrganisations.First().OrganisationId);
            Assert.Equal("Organisation Name 2", inaccessibleOrganisations.First().Organisation.OrganisationName);
        }