public static void ClassCleanup() { using (var dbContext = new ValidationDbContext()) { if (dbContext.Database.Exists()) { dbContext.Database.Delete(); } } }
public static void ClassInitialize(TestContext context) { using (var dbContext = new ValidationDbContext()) { if (dbContext.Database.Exists()) { dbContext.Database.Delete(); } dbContext.Database.Initialize(true); } }
public void 新增Member時_若MemberLogs不存在_調用DbContext_Save_應預期得到例外() { using (var dbContext = new ValidationDbContext()) { var id = Guid.NewGuid(); var memberToDb = new Member { Id = id }; dbContext.Members .Add(memberToDb); Action action = () => { dbContext.SaveChanges(); }; action.Should().Throw <DbEntityValidationException>(); } }