コード例 #1
0
        public async Task SaveChangesAsync()
        {
            // Arrange
            var entity       = new FakeEntity("Name");
            var databaseName = $"{DatabaseNamePrefix}.{nameof(SaveChangesAsync)}";
            var options      = new DbContextOptionsBuilder <FakeContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;

            using (var context = new FakeContext(options))
            {
                context.Add(entity);
                await context.SaveChangesAsync(true);
            }

            // Act
            using (var context = new FakeContext(options))
            {
                context.Entry(entity).State = EntityState.Modified;
                await context.SaveChangesAsync(true);
            }

            // Assert
            using (var context = new FakeContext(options))
            {
                entity = await context.FindAsync <FakeEntity>(entity.Id);
            }

            Assert.NotNull(entity?.Updated);
        }