예제 #1
0
        public void BranchReadIndexTest()
        {
            var result = controller.Index() as ViewResult;

            Console.WriteLine(result.ViewName);

            Assert.That(result.ViewName == "Index");
        }
        public async Task Index_GetAsync()
        {
            var options = new ListOptions
            {
                Filters = new Dictionary <string, string>
                {
                    { "name", "1" },
                    { "address", "2" }
                },
                SortKey   = "address",
                SortOrder = SortOrder.Descending
            };
            var returnUrlPath  = "/index";
            var returnUrlQuery = "?indexquery=indexquery";
            var returnUrl      = returnUrlPath + returnUrlQuery;

            var context = MakeContext(returnUrlPath, returnUrlQuery);
            var random  = new Random();

            for (int i = 0; i < 100; ++i)
            {
                await context.BranchesDao.CreateAsync(new Branch
                {
                    Id      = i,
                    Name    = "name" + random.Next(),
                    Address = "address" + random.Next()
                });
            }

            var controller = new BranchesController(context.BranchesDao)
            {
                TempData          = context.TempDataDictionary,
                ControllerContext = context.ControllerContext
            };

            var r = await controller.Index(options) as ViewResult;

            Assert.NotNull(r);
            Assert.Null(r.ViewName);
            var vm = r.Model as IndexViewModel;

            Assert.NotNull(vm);
            var expectedBranches = context.Branches
                                   .Where(b => b.Name.Contains(options.Filters["name"]))
                                   .Where(b => b.Address.Contains(options.Filters["address"]))
                                   .Order(options.SortKey, options.SortOrder)
                                   .ToPaginatedList(options.Page, BranchesController.PageSize);

            Assert.Equal(expectedBranches, vm.Branches);
            Assert.Same(options, vm.CurrentListOptions);
            Assert.Equal(returnUrl, vm.ReturnUrl);
        }
예제 #3
0
        public void Test1()
        {
            //arrange
            var MockRepo = new Mock <IBrancheService>();

            MockRepo.Setup(b => b.GetAll()).Returns(GetAllBranch());
            var controller = new BranchesController(MockRepo.Object);

            // act
            var result = controller.Index();

            // assert
            var viewResult       = Assert.IsType <ViewResult>(result);
            var viewResultModels = Assert.IsAssignableFrom <BranchIndexModel>(viewResult.ViewData.Model);

            Assert.Equal(4, viewResultModels.ListingModels.Count());
        }
예제 #4
0
        public async Task Index()
        {
            var branch = new Branch()
            {
                Id             = Guid.NewGuid(),
                OrganisationId = Guid.NewGuid(),
                Name           = "Branch1"
            };

            var pagedItems = new PagedItems <Branch>()
            {
                TotalItems = 1,
                Items      = new List <Branch>()
                {
                    branch
                }
            };

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

            BranchQueryOptions queryOptions = null;

            service.Setup(c => c.GetBranches(It.IsAny <BranchQueryOptions>()))
            .Callback((BranchQueryOptions options) => queryOptions = options)
            .ReturnsAsync(pagedItems);

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

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

            var result = await controller.Index($"organisationId={branch.OrganisationId}");

            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);

            Assert.Equal(branch.OrganisationId, queryOptions.OrganisationId);

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

            Assert.Same(pagedItems, returnValue);
        }