public async Task <IActionResult> Get()
        {
            var model = await ChangeLogService.GetLatestChangeLog();

            if (model == null)
            {
                return(NotFound());
            }

            return(Ok(model));
        }
예제 #2
0
        public async Task GetLatestChangeLog()
        {
            var options = TestHelper.GetDbContext("GetLatestChangeLog");

            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 = false, 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 actual = await service.GetLatestChangeLog();

                //Then
                Assert.Equal(cl2.Id, actual.Id);
                Assert.Equal(cl2.VersionNumber, actual.VersionNumber);
                Assert.Equal(cl2.ReleaseDate, actual.ReleaseDate);
                Assert.Equal(cl2.Published, actual.Published);
                Assert.Equal(cl2.Log, actual.Log);
            }
        }