コード例 #1
0
        public void TestOrganisationsIndexView()
        {
            ViewResult result = _organisationsController.Index() as ViewResult;

            Assert.IsNotNull(result);
            var organisations = result.Model as List <OrganisationViewModel>;

            Assert.AreEqual(1, organisations.Count);
        }
コード例 #2
0
        public async Task Index()
        {
            var organisation = new Organisation()
            {
                Id   = Guid.NewGuid(),
                Name = "organisation_1"
            };

            var items = new PagedItems <Organisation>()
            {
                TotalItems = 1,
                Items      = new List <Organisation>()
                {
                    organisation
                }
            };

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

            OrganisationQueryOptions queryOptions = null;

            service.Setup(c => c.GetOrganisations(It.IsAny <OrganisationQueryOptions>()))
            .Callback((OrganisationQueryOptions options) => queryOptions = options)
            .ReturnsAsync(items);

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

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

            var result = await controller.Index();

            Assert.Equal(Scope.Branch, queryOptions.Scope.Scope);
            Assert.Equal("Name", queryOptions.SortOptions.Column);
            Assert.Equal(SortDirection.Ascending, queryOptions.SortOptions.Direction);
            Assert.Equal(0, queryOptions.PageOptions.Size);
            Assert.Equal(0, queryOptions.PageOptions.Number);

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

            Assert.Same(items, returnValue);
        }