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); }
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)); }
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); }
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); }