public async Task <IActionResult> Index(string sortColumn, string sortDirection, int pageSize = 0, int pageNumber = 0, string filters = null)
        {
            var queryOptions = new ChangeLogQueryOptions(sortColumn, sortDirection, pageSize, pageNumber, filters);
            var pagedItems   = await ChangeLogService.GetChangeLogs(queryOptions);

            return(Ok(pagedItems));
        }
Exemplo n.º 2
0
        public async Task GetChangeLogs()
        {
            var options = TestHelper.GetDbContext("GetChangeLogs");

            var now = DateTime.Now;

            //Given
            var cl1 = new ChangeLogEntity {
                Id = Guid.NewGuid(), VersionNumber = "1.0", ReleaseDate = now.AddMonths(-2), Published = true, Log = "Log 1"
            };
            var cl2 = new ChangeLogEntity {
                Id = Guid.NewGuid(), VersionNumber = "2.0", ReleaseDate = now.AddMonths(-1), Published = true, Log = "Log 2"
            };
            var cl3 = new ChangeLogEntity {
                Id = Guid.NewGuid(), VersionNumber = "3.0", ReleaseDate = now, Published = true, Log = "Log 3"
            };

            using (var context = new DataContext(options))
            {
                //Jumbled order
                context.ChangeLog.Add(cl1);
                context.ChangeLog.Add(cl3);
                context.ChangeLog.Add(cl2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new ChangeLogService(context);

                //When
                var queryOptions = new ChangeLogQueryOptions("", "", 0, 0);
                var actual       = await service.GetChangeLogs(queryOptions);

                //Then
                Assert.Equal(3, actual.TotalItems);
                Assert.Equal(3, actual.Items.Count());

                var items = actual.Items.ToList();

                var actual1 = items[0];
                Assert.Equal(cl3.Id, actual1.Id);
                Assert.Equal(cl3.VersionNumber, actual1.VersionNumber);
                Assert.Equal(cl3.ReleaseDate, actual1.ReleaseDate);
                Assert.Equal(cl3.Published, actual1.Published);
                Assert.Equal(cl3.Log, actual1.Log);

                var actual2 = items[1];
                Assert.Equal(cl2.Id, actual2.Id);

                var actual3 = items[2];
                Assert.Equal(cl1.Id, actual3.Id);
            }
        }