Beispiel #1
0
 public static BoltOnOptions BoltOnEFModule(this BoltOnOptions boltOnOptions)
 {
     boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly());
     boltOnOptions.ServiceCollection.AddScoped <ChangeTrackerContext>();
     boltOnOptions.AddInterceptor <ChangeTrackerInterceptor>();
     return(boltOnOptions);
 }
Beispiel #2
0
        public static BoltOnOptions BoltOnCqrsModule(this BoltOnOptions boltOnOptions,
                                                     Action <CqrsOptions> action = null)
        {
            boltOnOptions.IsCqrsEnabled = true;
            var options = new CqrsOptions();

            action?.Invoke(options);
            boltOnOptions.AddInterceptor <CqrsInterceptor>().Before <UnitOfWorkInterceptor>();
            boltOnOptions.ServiceCollection.AddSingleton(options);
            boltOnOptions.ServiceCollection.AddTransient <IEventDispatcher, EventDispatcher>();
            return(boltOnOptions);
        }
Beispiel #3
0
        public void AddInterceptor_AfterAnInterceptorThatDoesntExist_ReturnsInterceptorsInExpectedOrder()
        {
            // arrange
            var serviceCollection = new Moq.Mock <IServiceCollection>();
            var boltOnOptions     = new BoltOnOptions(serviceCollection.Object);

            // act
            boltOnOptions.AddInterceptor <StopwatchInterceptor>();
            boltOnOptions.AddInterceptor <CqrsInterceptor>().After <TestBootstrappingInterceptor>();

            // assert
            var interceptorTypes                  = boltOnOptions.InterceptorTypes.ToList();
            var stopWatchInterceptorIndex         = interceptorTypes.IndexOf(typeof(StopwatchInterceptor));
            var testBootstrappingInterceptorIndex = interceptorTypes.IndexOf(typeof(TestBootstrappingInterceptor));
            var cqrsInterceptorIndex              = interceptorTypes.IndexOf(typeof(CqrsInterceptor));

            Assert.True(stopWatchInterceptorIndex != -1);
            Assert.True(testBootstrappingInterceptorIndex == -1);
            Assert.True(cqrsInterceptorIndex != -1);
            Assert.True(cqrsInterceptorIndex > stopWatchInterceptorIndex);
        }
Beispiel #4
0
        public void AddInterceptor_BeforeAnExistingInterceptor_ReturnsInterceptorsInExpectedOrder()
        {
            // arrange
            var serviceCollection = new Moq.Mock <IServiceCollection>();
            var boltOnOptions     = new BoltOnOptions(serviceCollection.Object);

            // act
            boltOnOptions.AddInterceptor <StopwatchInterceptor>();
            boltOnOptions.AddInterceptor <UnitOfWorkInterceptor>();
            boltOnOptions.AddInterceptor <CqrsInterceptor>().Before <UnitOfWorkInterceptor>();

            // assert
            var interceptorTypes          = boltOnOptions.InterceptorTypes.ToList();
            var stopWatchInterceptorIndex = interceptorTypes.IndexOf(typeof(StopwatchInterceptor));
            var uowInterceptorIndex       = interceptorTypes.IndexOf(typeof(UnitOfWorkInterceptor));
            var cqrsInterceptorIndex      = interceptorTypes.IndexOf(typeof(CqrsInterceptor));

            Assert.True(stopWatchInterceptorIndex != -1);
            Assert.True(uowInterceptorIndex != -1);
            Assert.True(cqrsInterceptorIndex != -1);
            Assert.True(cqrsInterceptorIndex < uowInterceptorIndex);
            Assert.True(cqrsInterceptorIndex > stopWatchInterceptorIndex);
        }
        public static void RegisterMediatorFakes(this BoltOnOptions boltOnOptions)
        {
            var changeTrackerInterceptor = new Mock <IBoltOnLogger <ChangeTrackerInterceptor> >();

            changeTrackerInterceptor.Setup(s => s.Debug(It.IsAny <string>()))
            .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
            boltOnOptions.ServiceCollection.AddTransient(s => changeTrackerInterceptor.Object);


            var boltOnClock     = new Mock <IBoltOnClock>();
            var currentDateTime = DateTime.Parse("10/27/2018 12:51:59 PM");

            boltOnClock.Setup(s => s.Now).Returns(currentDateTime);
            boltOnOptions.ServiceCollection.AddTransient((s) => boltOnClock.Object);

            var testInterceptorLogger = new Mock <IBoltOnLogger <TestInterceptor> >();

            testInterceptorLogger.Setup(s => s.Debug(It.IsAny <string>()))
            .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
            boltOnOptions.ServiceCollection.AddTransient((s) => testInterceptorLogger.Object);

            var stopWatchInterceptorLogger = new Mock <IBoltOnLogger <StopwatchInterceptor> >();

            stopWatchInterceptorLogger.Setup(s => s.Debug(It.IsAny <string>()))
            .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
            boltOnOptions.ServiceCollection.AddTransient((s) => stopWatchInterceptorLogger.Object);

            var customUoWOptionsBuilder = new Mock <IBoltOnLogger <TestCustomUnitOfWorkOptionsBuilder> >();

            customUoWOptionsBuilder.Setup(s => s.Debug(It.IsAny <string>()))
            .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
            boltOnOptions.ServiceCollection.AddTransient(s => customUoWOptionsBuilder.Object);

            var uowOptionsBuilderLogger = new Mock <IBoltOnLogger <UnitOfWorkOptionsBuilder> >();

            uowOptionsBuilderLogger.Setup(s => s.Debug(It.IsAny <string>()))
            .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
            boltOnOptions.ServiceCollection.AddTransient((s) => uowOptionsBuilderLogger.Object);

            if (MediatorTestHelper.IsClearInterceptors)
            {
                boltOnOptions.RemoveAllInterceptors();
            }

            if (MediatorTestHelper.IsCustomizeIsolationLevel)
            {
                boltOnOptions.RemoveInterceptor <ChangeTrackerInterceptor>();
                boltOnOptions.AddInterceptor <CustomChangeTrackerInterceptor>();
                boltOnOptions.ServiceCollection.AddSingleton <IUnitOfWorkOptionsBuilder, TestCustomUnitOfWorkOptionsBuilder>();
                var customChangeTrackerInterceptorLogger = new Mock <IBoltOnLogger <CustomChangeTrackerInterceptor> >();
                customChangeTrackerInterceptorLogger.Setup(s => s.Debug(It.IsAny <string>()))
                .Callback <string>(st => MediatorTestHelper.LoggerStatements.Add(st));
                boltOnOptions.ServiceCollection.AddTransient(s => customChangeTrackerInterceptorLogger.Object);
            }

            if (MediatorTestHelper.IsRemoveStopwatchInterceptor)
            {
                boltOnOptions.RemoveInterceptor <StopwatchInterceptor>();
            }

            boltOnOptions.AddInterceptor <TestInterceptor>();
        }