protected override IDbContext SetupDbContext()
        {
            var dbContext = new DbContextStub();

            _dbContextHooker = CreateContextHooker(dbContext);
            return(dbContext);
        }
Exemple #2
0
        public static DbContext GuardBy(this DbContext dbContext, GuardianKernel kernel)
        {
            var contextHooker = new DbContextHooker(dbContext, kernel);

            contextHooker.RegisterHooks();

            return(dbContext);
        }
        /// <summary>
        /// Guards the <see cref="DbContext"/>  by <see cref="GuardianKernel"/> .
        /// </summary>
        /// <param name="dbContext">The database context to Guard.</param>
        /// <param name="kernel">The guardian kernel.</param>
        public static DbContext UseGuardian(this DbContext dbContext, GuardianKernel kernel)
        {
            kernel.TryValidate();

            var contextHooker = new DbContextHooker(dbContext, kernel);

            contextHooker.RegisterHooks();

            return(dbContext);
        }
        public void ShouldNotInvokeHooks_AfterDispose()
        {
            var dbContext       = new DbContextStub();
            var dbContextHooker = new DbContextHooker(dbContext);
            var hook            = Substitute.For <IDbHook>();

            dbContextHooker.RegisterSaveHook(hook);

            dbContext.Foos.Add(new FooEntityStub());
            dbContextHooker.Dispose();
            var savedEntities = dbContext.SaveChanges();

            Assert.That(savedEntities, Is.EqualTo(1));
            hook.DidNotReceive().HookEntry(Arg.Any <IDbEntityEntry>());

            dbContext.Dispose();
        }