예제 #1
0
        public async Task MockAuditableContextAddAsyncTest()
        {
            var modelA = new MyIntModel();
            var modelB = new MyIntModel();

            using var ctx = DbContextFactory.CreateInMemoryAuditableDbContext <TestAuditableContext>(TestContext);
            var dbContextObjA = await ctx.AddAsync(modelA);

            var dbContextObjB = await ctx.AddAsync <MyIntModel>(modelB);

            Assert.AreEqual(1, dbContextObjA.Entity.Id);
            Assert.AreEqual(2, dbContextObjB.Entity.Id);
            Assert.IsNotNull(dbContextObjA.Entity.CalculatedValue);
            Assert.IsNotNull(dbContextObjB.Entity.CalculatedValue);
        }
예제 #2
0
        public async Task MockDbContextFactoryTest()
        {
            var modelA = new MyIntModel();
            var modelB = new MyIntModel();

            using var ctx = DbContextFactory.CreateInMemoryDbContext <TestDbContext>(TestContext);
            _             = ctx.MyModel.Add(modelA);
            _             = ctx.MyModel.Add(modelB);
            _             = await ctx.SaveChangesAsync();

            Assert.AreEqual(2, await ctx.MyModel.CountAsync());
            modelA.UpdatedBy = "Not Me";
            _ = await ctx.SaveChangesAsync();

            Assert.AreEqual("Not Me", modelA.UpdatedBy);
            Assert.IsNull(modelB.UpdatedOnUtc);
        }