public void SaveChanges_ContextSaveThrowsException_ExceptionHandlerGetsIt()
        {
            Exception e = new Exception();
            Mock<DbContext> dbContextStub = new Mock<DbContext>();
            dbContextStub.Setup(c => c.SaveChanges()).Throws(e);

            FakeExceptionHandler handler = new FakeExceptionHandler();
            UnitOfWork uof = GetTargetWith(dbContextStub, handler);

            uof.SaveChanges();

            Assert.AreSame(e, handler.Handled);
        }
        public void SaveChanges_InterceptorThrowsException_ExceptionHandlerGetsIt()
        {
            Exception e = new Exception();
            Mock<IEntityInterceptor> interceptorStub = new Mock<IEntityInterceptor>();
            interceptorStub.Setup(i => i.OnSave(It.IsAny<IEntityEntry>(), It.IsAny<IUnitOfWork>()))
                           .Throws(e);

            FakeExceptionHandler handler = new FakeExceptionHandler();
            UnitOfWork uof = GetTargetWith(interceptorStub.Object, handler);

            uof.SaveChanges();

            Assert.AreSame(e, handler.Handled);
        }
        private UnitOfWork GetTargetWith(Mock<DbContext> context, FakeExceptionHandler handler)
        {
            ContextUtilitiesDouble utilitiesStub = new ContextUtilitiesDouble(new[] {new User()});
            Mock<IInterceptorsResolver> resolverStub = new Mock<IInterceptorsResolver>();

            return GetTargetWith(utilitiesStub, resolverStub.Object, context, handler);
        }