コード例 #1
0
        public async void UpdateAsync_ReturnsNull_WhenIdNotExist()
        {
            var       lunchModified = GetUserLunch();
            Exception exception     = null;

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsNull_WhenIdNotExist")))
            {
                var classUnderTest = new UserLunchService(context);
                try
                {
                    await classUnderTest.UpdateAsync(lunchModified);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
            }

            var notFoundException = Assert.IsType <NotFoundException>(exception);

            Assert.False(string.IsNullOrEmpty(notFoundException.Message));
        }
コード例 #2
0
        public async void UpdateAsync_ReturnsLunchModified_WhenIdExist()
        {
            var lunchId           = Guid.NewGuid();
            var userLunch         = GetUserLunch();
            var userLunchModified = new UserLunch
            {
                Id        = userLunch.Id,
                Approved  = !userLunch.Approved,
                LunchId   = lunchId,
                UserId    = "newUserId1",
                UpdatedBy = "updater"
            };

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsLunchModified_WhenIdExist")))
            {
                await context.Lunches.AddAsync(GetLunch(lunchId));

                await context.UserLunches.AddAsync(userLunch);

                await context.SaveChangesAsync();
            }

            UserLunch result = null;

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsLunchModified_WhenIdExist")))
            {
                var classUnderTest = new UserLunchService(context);
                result = await classUnderTest.UpdateAsync(userLunchModified);
            }

            Assert.NotNull(result);
            Assert.Equal(userLunchModified.Id, result.Id);
            Assert.NotEqual(userLunchModified.UpdatedOn, result.UpdatedOn);
            Assert.Equal(userLunchModified.UpdatedBy, result.UpdatedBy);
            Assert.Equal(userLunchModified.Approved, result.Approved);
            Assert.Equal(userLunchModified.UserId, result.UserId);
            Assert.Equal(userLunchModified.LunchId, result.LunchId);
        }