public Task When_starting_correlationContext_with_legacy_ctor_when_another_context_is_active_should_not_throw() { const string parentContextId = nameof(parentContextId); #pragma warning disable 618 // justification, covering legacy implementation (pre v3.0) var sut = new CorrelationManager( new CorrelationContextFactory(_correlationContextAccessor), _correlationIdFactoryMock.Object, new NullLogger <CorrelationManager>() ); #pragma warning restore 618 return(sut.CorrelateAsync(parentContextId, async() => { CorrelationContext parentContext = _correlationContextAccessor.CorrelationContext; parentContext.Should().NotBeNull(); parentContext.CorrelationId.Should().Be(parentContextId); await sut.CorrelateAsync(() => { CorrelationContext innerContext = _correlationContextAccessor.CorrelationContext; innerContext.Should().NotBeNull().And.NotBe(parentContext); innerContext.CorrelationId.Should().NotBe(parentContextId); return Task.CompletedTask; }); })); }
public CorrelationManagerTests() { _correlationContextAccessor = new CorrelationContextAccessor(); _correlationIdFactoryMock = new Mock <ICorrelationIdFactory>(); _correlationIdFactoryMock .Setup(m => m.Create()) .Returns(() => GeneratedCorrelationId) .Verifiable(); _sut = new CorrelationManager( new CorrelationContextFactory(_correlationContextAccessor), _correlationIdFactoryMock.Object, new TestLogger <CorrelationManager>() ); }
protected HangfireIntegrationTests(ITestOutputHelper testOutputHelper) { // Output type + timestamp _testOutputHelper = testOutputHelper ?? throw new ArgumentNullException(nameof(testOutputHelper)); _testOutputHelper.WriteLine(GetType().Name + "," + DateTime.Now.Ticks); MockHttp.Fallback.Respond(HttpStatusCode.OK); var correlationContextAccessor = new CorrelationContextAccessor(); _correlationManager = new CorrelationManager( new CorrelationContextFactory(correlationContextAccessor), new GuidCorrelationIdFactory(), correlationContextAccessor, new TestLogger <CorrelationManager>() ); }
public static IEnumerable <object[]> NullArgumentTestCases() { var instance = new CorrelationManager( Mock.Of <ICorrelationContextFactory>(), Mock.Of <ICorrelationIdFactory>(), Mock.Of <ICorrelationContextAccessor>(), Mock.Of <ILogger <CorrelationManager> >() ); // ReSharper disable ConvertToLocalFunction Func <Task> correlatedTask = () => Task.CompletedTask; Func <Task <int> > returningCorrelatedTask = () => Task.FromResult(1); Action correlatedAction = () => { }; Func <int> returningCorrelatedAction = () => 1; // ReSharper restore ConvertToLocalFunction return(new[] { // Instance members DelegateTestCase.Create(instance.CorrelateAsync, (string)null, correlatedTask, (OnException)null), DelegateTestCase.Create(instance.CorrelateAsync, (string)null, returningCorrelatedTask, (OnException <int>)null), DelegateTestCase.Create(instance.Correlate, (string)null, correlatedAction, (OnException)null), DelegateTestCase.Create(instance.Correlate, (string)null, returningCorrelatedAction, (OnException <int>)null), // Extensions DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, correlatedTask), DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, returningCorrelatedTask), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, correlatedAction), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, returningCorrelatedAction), DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, correlatedTask, (OnException)null), DelegateTestCase.Create(AsyncCorrelationManagerExtensions.CorrelateAsync, instance, returningCorrelatedTask, (OnException <int>)null), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, correlatedAction, (OnException)null), DelegateTestCase.Create(CorrelationManagerExtensions.Correlate, instance, returningCorrelatedAction, (OnException <int>)null), } .SelectMany(tc => tc.GetNullArgumentTestCases())); }
public CorrelationManagerTests() { _correlationContextAccessor = new CorrelationContextAccessor(); _correlationIdFactoryMock = new Mock <ICorrelationIdFactory>(); _correlationIdFactoryMock .Setup(m => m.Create()) .Returns(() => GeneratedCorrelationId) .Verifiable(); Logger serilogLogger = new LoggerConfiguration() .WriteTo.TestCorrelator() .CreateLogger(); _logProvider = new SerilogLoggerProvider(serilogLogger); _logger = new TestLogger <CorrelationManager>(_logProvider.CreateLogger(nameof(CorrelationManager))); _sut = new CorrelationManager( new CorrelationContextFactory(_correlationContextAccessor), _correlationIdFactoryMock.Object, _correlationContextAccessor, _logger ); }