Esempio n. 1
0
        public void GetPage_ShouldWork()
        {
            var context = _contextFake.GetContext("GetPage_ShouldWork");

            var levels = new List <Level>()
            {
                new Level()
                {
                    Id = 1, Description = "Teste_1"
                },
                new Level()
                {
                    Id = 2, Description = "Teste_2"
                },
                new Level()
                {
                    Id = 3, Description = "Teste_3"
                }
            };

            context.Levels.AddRange(levels);
            context.SaveChanges();


            var levelsFind = context.Levels.ToList();
            var pageFilter = new PageFilter()
            {
                PageLength = 2,
                PageNumber = 1,
            };
            var expected = new Page <Level>()
            {
                Total      = levelsFind.Count(),
                TotalPages = 2,
                Results    = levelsFind.Take(2)
            };

            var repo   = new LevelRepository(context);
            var result = repo.GetPage(pageFilter);

            Assert.NotNull(result);
            Assert.Equal(expected.Total, result.Total);
            Assert.Equal(expected.TotalPages, result.TotalPages);
            Assert.Equal(expected.Results, result.Results, new LevelComparer());
        }