public async Task should_trigger_scope_closing_on_failing_handler() { var registry = new EventHandlerRegistry(); var container = Substitute.For <IContainer>(); var scope = Substitute.For <IContainerScope>(); var handler = new FailingHandler(); ScopeClosingEventArgs actual = null; registry.Map <TestEvent>(handler.GetType()); scope.Resolve(handler.GetType()).Returns(handler); container.CreateScope().Returns(scope); var sut = new SeparateScopesIocEventBus(container, registry); sut.ScopeClosing += (sender, args) => actual = args; try { await sut.PublishAsync(new TestEvent()); } catch (AggregateException) { //ignore for test purposes } actual.Should().NotBeNull(); actual.HandlersWasSuccessful.Should().BeFalse(); }
private void OnBackgroundJobScopeClosing(object sender, ScopeClosingEventArgs e) { if (e.Successful) { e.Scope.Resolve <IAdoNetUnitOfWork>().SaveChanges(); } }
public void the_constructor_should_assign_failure_to_the_property() { var scope = Substitute.For <IContainerScope>(); var sut = new ScopeClosingEventArgs(scope, false); sut.Successful.Should().BeFalse(); }
public void the_constructor_should_assign_scope_to_the_property() { var scope = Substitute.For <IContainerScope>(); var sut = new ScopeClosingEventArgs(scope, true); sut.Scope.Should().BeSameAs(scope); }
private void OnScopeClosing(object sender, ScopeClosingEventArgs e) { try { e.Scope.Resolve <IAdoNetUnitOfWork>().SaveChanges(); } catch (Exception exception) { _log.Error("Failed to close scope. Err: " + exception, e.Exception); } }
public void trigger_ScopeClosed_before_closing_it_after_job_Execution() { var sl = Substitute.For <IContainer>(); var job = Substitute.For <IBackgroundJob>(); var scope = Substitute.For <IContainerScope>(); sl.CreateScope().Returns(scope); scope.Resolve(job.GetType()).Returns(job); scope.ResolveAll <IBackgroundJob>().Returns(new[] { job }); ScopeClosingEventArgs actual = null; var sut = new BackgroundJobManager(sl); sut.StartInterval = TimeSpan.FromSeconds(0); sut.ScopeClosing += (o, e) => actual = e; sut.Start(); Thread.Sleep(100); actual.Should().NotBeNull(); }
public async Task should_trigger_scope_closing_on_successful_invocation() { var registry = new EventHandlerRegistry(); var container = Substitute.For <IContainer>(); var scope = Substitute.For <IContainerScope>(); var handler = new SuccessfulHandler(); ScopeClosingEventArgs actual = null; registry.Map <TestEvent>(handler.GetType()); scope.Resolve(handler.GetType()).Returns(handler); container.CreateScope().Returns(scope); var sut = new SeparateScopesIocEventBus(container, registry); sut.ScopeClosing += (sender, args) => actual = args; await sut.PublishAsync(new TestEvent()); actual.Should().NotBeNull(); actual.HandlersWasSuccessful.Should().BeTrue(); }