Example #1
0
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FakeBuilder();

            var unitOfWork  = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register <IManageUnitsOfWork>(unitOfWork, throwingUoW);

            //since it is a single exception then it will not be an AggregateException
            Assert.That(async() => await InvokeBehavior(builder), Throws.InstanceOf <InvalidOperationException>().And.SameAs(throwingUoW.ExceptionThrownFromEnd));
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
        }
Example #2
0
        public void Should_pass_exception_to_cleanup()
        {
            var services = new ServiceCollection();

            var unitOfWork  = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            services.AddTransient <IManageUnitsOfWork>(sp => unitOfWork);
            services.AddTransient <IManageUnitsOfWork>(sp => throwingUoW);

            //since it is a single exception then it will not be an AggregateException
            Assert.That(async() => await InvokeBehavior(services), Throws.InstanceOf <InvalidOperationException>().And.SameAs(throwingUoW.ExceptionThrownFromEnd));
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
        }
Example #3
0
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork  = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register <IManageUnitsOfWork>(() => unitOfWork);
            builder.Register <IManageUnitsOfWork>(() => throwingUoW);

            var aggregateException = Assert.Throws <AggregateException>(() => InvokeBehavior(builder));

            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, aggregateException.InnerExceptions.Single());
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register<IManageUnitsOfWork>(() => unitOfWork);
            builder.Register<IManageUnitsOfWork>(() => throwingUoW);

            var aggregateException = Assert.Throws<AggregateException>(() => InvokeBehavior(builder));

            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, aggregateException.InnerExceptions.Single());
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork  = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register <IManageUnitsOfWork>(() => unitOfWork);
            builder.Register <IManageUnitsOfWork>(() => throwingUoW);

            //since it is a single exception then it will not be an AggregateException
            var exception = Assert.Throws <InvalidOperationException>(() => InvokeBehavior(builder));

            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, exception);
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork = new CaptureExceptionPassedToEndUnitOfWork();

            builder.Register<IManageUnitsOfWork>(() => unitOfWork);
            var runner = new UnitOfWorkRunner
                         {
                             Builder = builder
                         };
            var exception = new Exception();
            runner.Begin();
            var aggregateException = Assert.Throws<AggregateException>(() => runner.AppendEndExceptionsAndRethrow(exception));
            Assert.AreSame(exception, unitOfWork.Exception);
            Assert.AreSame(exception, aggregateException.InnerExceptions.Single());
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork = new CaptureExceptionPassedToEndUnitOfWork();

            builder.Register <IManageUnitsOfWork>(() => unitOfWork);
            var runner = new UnitOfWorkRunner
            {
                Builder = builder
            };
            var exception = new Exception();

            runner.Begin();
            var aggregateException = Assert.Throws <AggregateException>(() => runner.AppendEndExceptionsAndRethrow(exception));

            Assert.AreSame(exception, unitOfWork.Exception);
            Assert.AreSame(exception, aggregateException.InnerExceptions.Single());
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FuncBuilder();

            var unitOfWork = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register<IManageUnitsOfWork>(() => unitOfWork);
            builder.Register<IManageUnitsOfWork>(() => throwingUoW);

            //since it is a single exception then it will not be an AggregateException 
            var exception = Assert.Throws<InvalidOperationException>(() => InvokeBehavior(builder));

            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, exception);
        }
        public void Should_pass_exception_to_cleanup()
        {
            var builder = new FakeBuilder();

            var unitOfWork = new CaptureExceptionPassedToEndUnitOfWork();
            var throwingUoW = new UnitOfWorkThatThrowsFromEnd();

            builder.Register<IManageUnitsOfWork>(unitOfWork, throwingUoW);

            //since it is a single exception then it will not be an AggregateException
            Assert.That(async () => await InvokeBehavior(builder), Throws.InstanceOf<InvalidOperationException>().And.SameAs(throwingUoW.ExceptionThrownFromEnd));
            Assert.AreSame(throwingUoW.ExceptionThrownFromEnd, unitOfWork.Exception);
        }