コード例 #1
0
        public void Process_BootstrapWithDefaults_InvokesAllTheInterceptorsAndReturnsSuccessfulResultForOneWayCommand()
        {
            // arrange
            MediatorTestHelper.IsClearInterceptors = false;
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            serviceCollection.BoltOn();
            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.TightenBolts();
            var boltOnClock = serviceProvider.GetService <IBoltOnClock>();
            var mediator    = serviceProvider.GetService <IMediator>();
            var request     = new TestOneWayCommand();

            // act
            mediator.Process(request);

            // assert
            Assert.Equal(1, request.Value);
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(d => d ==
                                                                              $"StopwatchInterceptor started at {boltOnClock.Now}"));
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(d => d ==
                                                                              $"StopwatchInterceptor ended at {boltOnClock.Now}. Time elapsed: 0"));
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(d => d == "TestInterceptor Started"));
        }
コード例 #2
0
        public async Task Process_BootstrapWithDefaults_InvokesAllTheInterceptorsAndReturnsSuccessfulResultForOneWayCommand()
        {
            // arrange
            RequestorTestHelper.IsRemoveStopwatchInterceptor = false;
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            serviceCollection.BoltOn(b => b.RegisterRequestorFakes());
            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.TightenBolts();
            var appClock  = serviceProvider.GetService <IAppClock>();
            var requestor = serviceProvider.GetService <IRequestor>();
            var request   = new TestOneWayCommand();

            // act
            await requestor.ProcessAsync(request);

            // assert
            Assert.Equal(1, request.Value);
            Assert.NotNull(RequestorTestHelper.LoggerStatements.FirstOrDefault(d => d ==
                                                                               $"StopwatchInterceptor started at {appClock.Now}"));
            Assert.NotNull(RequestorTestHelper.LoggerStatements.FirstOrDefault(d => d ==
                                                                               $"StopwatchInterceptor ended at {appClock.Now}. Time elapsed: 0"));
            Assert.NotNull(RequestorTestHelper.LoggerStatements.FirstOrDefault(d => d == "TestInterceptor Started"));
            Assert.NotNull(RequestorTestHelper.LoggerStatements.FirstOrDefault(d => d == $"About to start transaction. TransactionScopeOption: {TransactionScopeOption.RequiresNew} " +
                                                                               $"IsolationLevel: {IsolationLevel.ReadCommitted} Timeout: { TransactionManager.DefaultTimeout}"));
            Assert.NotNull(RequestorTestHelper.LoggerStatements.FirstOrDefault(d => d == "Transaction completed"));
        }
コード例 #3
0
        public async Task Process_MediatorWithOneWayCommandRequestAndAsyncHandler_StartsTransactionsWithCustomizedQueryIsolationLevel()
        {
            // arrange
            MediatorTestHelper.IsCustomizeIsolationLevel    = true;
            MediatorTestHelper.IsRemoveStopwatchInterceptor = false;
            var serviceCollection = new ServiceCollection();

            serviceCollection.BoltOn(options =>
            {
                options.BoltOnEFModule();
                options.RegisterMediatorFakes();
            });
            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.TightenBolts();
            var sut     = serviceProvider.GetService <IMediator>();
            var command = new TestOneWayCommand();

            // act
            await sut.ProcessAsync(command);

            // assert
            Assert.Equal(1, command.Value);
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(f => f == $"Entering {nameof(CustomChangeTrackerInterceptor)}..."));
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(f => f == "Getting isolation level for Command or Query"));
        }
コード例 #4
0
        public async Task Process_MediatorWithOneWayCommandRequestAndAsyncHandler_ExecutesUoWInterceptorAndStartsTransactionsWithCustomizedQueryIsolationLevel()
        {
            // arrange
            MediatorTestHelper.IsCustomizeIsolationLevel = true;
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .BoltOn()
            .AddLogging();
            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.TightenBolts();
            var sut     = serviceProvider.GetService <IMediator>();
            var command = new TestOneWayCommand();

            // act
            await sut.ProcessAsync(command);

            // assert
            Assert.Equal(1, command.Value);
            Assert.NotNull(MediatorTestHelper.LoggerStatements.FirstOrDefault(f => f == "Getting isolation level for Command or Query"));
        }