예제 #1
0
        public void AddCorrelation_CustomCorrelationAccessorWithCustomOptions_RegisterCustomAccessorAndOptions()
        {
            // Arrange
            string expectedTestOption          = $"test-option-{Guid.NewGuid()}";
            var    testCorrelationInfoProvider = new TestCorrelationInfoAccessor();
            var    services = new ServiceCollection();

            services.AddCorrelation <TestCorrelationInfoAccessor, TestCorrelationInfo, TestCorrelationInfoOptions>(
                provider => testCorrelationInfoProvider,
                options => options.TestOption = expectedTestOption);

            // Act
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            // Assert
            Assert.NotNull(serviceProvider.GetService <ICorrelationInfoAccessor>());
            var correlationInfoAccessor = serviceProvider.GetService <ICorrelationInfoAccessor <TestCorrelationInfo> >();

            Assert.Same(testCorrelationInfoProvider, correlationInfoAccessor);
            var testOptions = serviceProvider.GetService <IOptions <TestCorrelationInfoOptions> >();

            Assert.NotNull(testOptions);
            Assert.NotNull(testOptions.Value);
            Assert.Equal(expectedTestOption, testOptions.Value.TestOption);
        }
예제 #2
0
        public void AddCorrelation_CustomCorrelationFactory_RegisterCustomCorrelation()
        {
            // Arrange
            var services = new ServiceCollection();
            var testCorrelationInfoAccessor = new TestCorrelationInfoAccessor();

            services.AddCorrelation <TestCorrelationInfoAccessor, TestCorrelationInfo>(provider => testCorrelationInfoAccessor);

            // Act
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            // Assert
            var correlationInfoAccessor = serviceProvider.GetService <ICorrelationInfoAccessor>();

            Assert.NotNull(correlationInfoAccessor);
            var correlationInfoAccessorT = serviceProvider.GetService <ICorrelationInfoAccessor <TestCorrelationInfo> >();

            Assert.NotNull(correlationInfoAccessorT);
            Assert.Same(testCorrelationInfoAccessor, correlationInfoAccessorT);
        }