Esempio n. 1
0
        public void List_HappyPath()
        {
            var querystring = new NameValueCollection
            {
                { "draw", "1" },
                { "start", "0" },
                { "length", "10" },
                { "search[value]", "search" },
                { "search[regex]", "true" },
                { "order[0][column]", "1" },
                { "order[0][dir]", "asc" },
                { "columns[0][data]", "UserId" },
                { "columns[0][name]", "User" },
                { "columns[0][search][value]", "" },
                { "columns[0][search][regex]", "false" },
                { "columns[1][data]", "UserName" },
                { "columns[1][name]", "User Name" },
                { "columns[1][search][value]", "" },
                { "columns[1][search][regex]", "false" }
            };

            var count         = 32;
            var filteredCount = 24;
            var personsList   = new List <Person>();

            for (int i = 0; i < count; i++)
            {
                personsList.Add(new Person
                {
                    Id = i
                });
            }

            var whereClause = " WHERE UserId = 178";

            MockControllerContext.SetupGet(_ => _.HttpContext.Request.QueryString)
            .Returns(querystring);
            _repository.Setup(_ => _.GetCount(string.Empty))
            .Returns(count);
            _repository.Setup(_ => _.GetQuery(It.IsAny <string>()))
            .Returns(personsList);
            _ajaxHelper.Setup(_ => _.GetWhereClause(true, null))
            .Returns(whereClause);
            _repository.Setup(_ => _.GetCount(whereClause))
            .Returns(filteredCount);

            var contentResult = Assert.IsType <ContentResult>(_personController.List());

            Assert.Contains("\"draw\":0", contentResult.Content);
            Assert.Contains($"\"recordsTotal\":{count}", contentResult.Content);
            Assert.Contains($"\"recordsFiltered\":{filteredCount}", contentResult.Content);
            Assert.Contains($"\"Id\":{personsList.Last().Id}", contentResult.Content);
        }