Ejemplo n.º 1
0
        public async Task CustomExceptionHandlerIsCalledWhenExceptionOccurs()
        {
            var composer = new ServiceBusComposer();

            var fakeExceptionHandler = new FakeExceptionHandler();

            composer.WithAdditionalServices(
                services =>
            {
                services.AddSingleton <FakeMessageHandler>();
                services.AddSingleton(fakeExceptionHandler);

                services.ConfigureServiceBus(
                    options =>
                {
                    options
                    .RegisterQueue("testQueue")
                    .WithConnectionString("connectionStringTest")
                    .WithCustomMessageHandler <FakeMessageHandler>()
                    .WithCustomExceptionHandler <FakeExceptionHandler>();
                });
            });

            var provider = await composer.ComposeAndSimulateStartup();

            var clientMock = provider.GetQueueClientMock("testQueue");

            var sentArgs = new ExceptionReceivedEventArgs(new Exception(), "", "", "", "");
            await clientMock.TriggerExceptionOccured(sentArgs);

            fakeExceptionHandler.Mock.Verify(
                o => o.HandleExceptionAsync(sentArgs),
                Times.Once);
        }
Ejemplo n.º 2
0
        private UnitOfWork GetTargetWith(Mock <DbContext> context, FakeExceptionHandler handler)
        {
            ContextUtilitiesDouble       utilitiesStub = new ContextUtilitiesDouble(new[] { new User() });
            Mock <IInterceptorsResolver> resolverStub  = new Mock <IInterceptorsResolver>();

            return(this.GetTargetWith(utilitiesStub, resolverStub.Object, context, handler));
        }
Ejemplo n.º 3
0
        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     = this.GetTargetWith(dbContextStub, handler);

            uof.SaveChanges();

            Assert.AreSame(e, handler.Handled);
        }
Ejemplo n.º 4
0
        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     = this.GetTargetWith(interceptorStub.Object, handler);

            uof.SaveChanges();

            Assert.AreSame(e, handler.Handled);
        }