Ejemplo n.º 1
0
        public void Get_Ok()
        {
            const int numOrgs    = 5;
            const int numCourses = 6;

            LoadData(TestUserEmail1, numOrgs, numCourses);
            organisationsController.SetControllerContext(TestUserEmail1);
            var result = organisationsController.GetAll();

            result.Should().NotBeOfType <UnauthorizedResult>();
            result.Should().BeOfType <OkObjectResult>();

            var orgList = ((List <ProviderSummary>)((OkObjectResult)result).Value).ToList();

            orgList.All(c => c.TotalCourses == numCourses).Should().BeTrue();

            foreach (var org in orgList)
            {
                var orgResult = organisationsController.Get(org.ProviderCode);


                orgResult.Should().NotBeOfType <UnauthorizedResult>();
                orgResult.Should().BeOfType <OkObjectResult>();

                var orgItem = ((ProviderSummary)((OkObjectResult)orgResult).Value);

                orgItem.ProviderName.Should().Equals(org.ProviderName);
            }
        }
        public async Task Get()
        {
            var organisation = new OrganisationEdit()
            {
                Id     = Guid.NewGuid(),
                Name   = "organisation_1",
                Config = new Config()
            };

            var service     = new Mock <IOrganisationService>();
            var authService = TestHelper.MockAuthenticationService(Scope.Branch);

            service.Setup(c => c.GetOrganisation(It.IsAny <ScopeOptions>(), It.Is <Guid>(m => m == organisation.Id.Value)))
            .ReturnsAsync(organisation);

            var controller = new OrganisationsController(authService.Object, service.Object, null);

            controller.ControllerContext = TestHelper.GetControllerContext(new ClaimsPrincipal());

            var result = await controller.Get(organisation.Id.Value);

            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <OrganisationEdit>(okResult.Value);

            Assert.Same(organisation, returnValue);
        }