public async Task <IActionResult> Update(Guid changeLogId, [FromBody] ChangeLog changeLog)
        {
            changeLog.Id = changeLogId;

            var result = await ChangeLogService.UpdateChangeLog(changeLog);

            if (!result.Success)
            {
                return(BadRequest(result.ValidationFailures));
            }

            return(Ok(result));
        }
Exemple #2
0
        public async Task UpdateChangeLog()
        {
            var options = TestHelper.GetDbContext("UpdateChangeLog");

            //Given
            var cl1 = new ChangeLogEntity {
                Id = Guid.NewGuid(), VersionNumber = "1.0", ReleaseDate = DateTime.Now.AddMonths(-2), Published = false, Log = "Log 1"
            };
            var cl2 = new ChangeLogEntity {
                Id = Guid.NewGuid(), VersionNumber = "2.0", ReleaseDate = DateTime.Now.AddMonths(-1), Published = false, Log = "Log 2"
            };

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

                context.SaveChanges();
            }

            var model = new ChangeLog()
            {
                Id            = cl2.Id,
                VersionNumber = "2.1",
                ReleaseDate   = DateTime.Now.AddMonths(-3),
                Log           = "Log 2 updated",
                Published     = true
            };

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

                //When
                var result = await service.UpdateChangeLog(model);

                //Then
                Assert.True(result.Success);

                var actual = await context.ChangeLog.FindAsync(model.Id);

                Assert.Equal(model.VersionNumber, actual.VersionNumber);
                Assert.Equal(model.ReleaseDate, actual.ReleaseDate);
                Assert.Equal(model.Published, actual.Published);
                Assert.Equal(model.Log, actual.Log);
            }
        }