Exemplo n.º 1
0
 public static BoltOnOptions BoltOnMediatorEFModule(this BoltOnOptions boltOnOptions)
 {
     //boltOnOptions
     //.BoltOnEFModule()
     //.BoltOnAssemblies(Assembly.GetExecutingAssembly());
     return(boltOnOptions);
 }
Exemplo n.º 2
0
        public static void RegisterCosmosdbFakes(this BoltOnOptions boltOnOptions)
        {
            if (IntegrationTestHelper.IsCosmosDbServer)
            {
                var cosmosDbOptions = new TestSchoolCosmosDbOptions
                {
                    Uri = "",
                    AuthorizationKey = "",
                    DatabaseName     = ""
                };
                boltOnOptions.ServiceCollection.AddCosmosDb <TestSchoolCosmosDbOptions>(options =>
                {
                    options.Uri = cosmosDbOptions.Uri;
                    options.AuthorizationKey = cosmosDbOptions.AuthorizationKey;
                    options.DatabaseName     = cosmosDbOptions.DatabaseName;
                });

                using var client = new DocumentClient(new Uri(cosmosDbOptions.Uri), cosmosDbOptions.AuthorizationKey);
                client.CreateDatabaseIfNotExistsAsync(new Database {
                    Id = cosmosDbOptions.DatabaseName
                }).GetAwaiter().GetResult();

                var documentCollection = new DocumentCollection {
                    Id = nameof(StudentFlattened).Pluralize()
                };
                documentCollection.PartitionKey.Paths.Add("/studentTypeId");
                client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(cosmosDbOptions.DatabaseName),
                                                                documentCollection).GetAwaiter().GetResult();
            }

            boltOnOptions.ServiceCollection.AddTransient <IRepository <StudentFlattened>, Repository <StudentFlattened, TestSchoolCosmosDbOptions> >();
        }
Exemplo n.º 3
0
 public static BoltOnOptions BoltOnEFModule(this BoltOnOptions boltOnOptions)
 {
     boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly());
     boltOnOptions.ServiceCollection.AddScoped <ChangeTrackerContext>();
     boltOnOptions.AddInterceptor <ChangeTrackerInterceptor>();
     return(boltOnOptions);
 }
Exemplo n.º 4
0
 public static BoltOnOptions BoltOnMassTransitBusModule(this BoltOnOptions boltOnOptions)
 {
     boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly());
     boltOnOptions.ServiceCollection.AddSingleton <IBus, BoltOnMassTransitBus>();
     boltOnOptions.ServiceCollection.AddTransient(typeof(BoltOnMassTransitConsumer <>));
     return(boltOnOptions);
 }
Exemplo n.º 5
0
        public static IServiceCollection BoltOn(this IServiceCollection serviceCollection, Action <BoltOnOptions> action = null)
        {
            var options = new BoltOnOptions();

            action?.Invoke(options);
            Bootstrapper.Instance.BoltOn(serviceCollection, options, Assembly.GetCallingAssembly());
            return(serviceCollection);
        }
Exemplo n.º 6
0
        public static IServiceCollection BoltOn(this IServiceCollection serviceCollection, Action <BoltOnOptions> action = null)
        {
            var options = new BoltOnOptions(serviceCollection);

            action?.Invoke(options);
            options.RegisterByConvention(Assembly.GetCallingAssembly());
            options.RegisterInterceptors();
            serviceCollection.AddSingleton(options);
            return(serviceCollection);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public static void RegisterCqrsFakes(this BoltOnOptions boltOnOptions)
        {
            boltOnOptions.ServiceCollection.AddDbContext <CqrsDbContext>(options =>
            {
                options.UseInMemoryDatabase("InMemoryDbCqrsDbContext");
                options.ConfigureWarnings(x => x.Ignore(RelationalEventId.AmbientTransactionWarning));
            });

            boltOnOptions.ServiceCollection.AddTransient <IRepository <Student>,
                                                          Repository <Student, CqrsDbContext> >();
            boltOnOptions.ServiceCollection.AddTransient <IRepository <StudentFlattened>,
                                                          Repository <StudentFlattened, CqrsDbContext> >();
        }
Exemplo n.º 9
0
        public void AddInterceptor_AfterAlreadyAddedInterceptor_ReturnsInterceptorsInExpectedOrder()
        {
            // arrange
            var serviceCollection = new Moq.Mock <IServiceCollection>();
            var boltOnOptions     = new BoltOnOptions(serviceCollection.Object);

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

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

            Assert.True(stopWatchInterceptorIndex != -1);
            Assert.True(uowInterceptorIndex != -1);
            Assert.True(uowInterceptorIndex < stopWatchInterceptorIndex);
        }
Exemplo n.º 10
0
 public static void RegisterDataFakes(this BoltOnOptions boltOnOptions)
 {
     boltOnOptions.ServiceCollection.AddTransient <IRepository <Student>, Repository <Student, SchoolDbContext> >();
     if (IntegrationTestHelper.IsSqlServer)
     {
         boltOnOptions.ServiceCollection.AddDbContext <SchoolDbContext>(options =>
         {
             options.UseSqlServer("Data Source=127.0.0.1;initial catalog=Testing;persist security info=True;User ID=sa;Password=Password1;");
         });
     }
     else
     {
         boltOnOptions.ServiceCollection.AddDbContext <SchoolDbContext>(options =>
         {
             options.UseInMemoryDatabase("InMemoryDbForTesting");
             options.ConfigureWarnings(x => x.Ignore(RelationalEventId.AmbientTransactionWarning));
         });
     }
 }
Exemplo n.º 11
0
        public void AddInterceptor_BeforeTheFirstInterceptor_ReturnsInterceptorsInExpectedOrder()
        {
            // arrange
            var serviceCollection = new Moq.Mock <IServiceCollection>();
            var boltOnOptions     = new BoltOnOptions(serviceCollection.Object);

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

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

            Assert.True(stopWatchInterceptorIndex != -1);
            Assert.True(uowInterceptorIndex != -1);
            Assert.True(testBootstrappingInterceptorIndex != -1);
            Assert.True(testBootstrappingInterceptorIndex < stopWatchInterceptorIndex);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
 public InterceptorOptions(BoltOnOptions boltOnOptions)
 {
     BoltOnOptions = boltOnOptions;
 }
Exemplo n.º 14
0
 public static BoltOnOptions BoltOnEFModule(this BoltOnOptions boltOnOptions)
 {
     boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly());
     return(boltOnOptions);
 }
Exemplo n.º 15
0
        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>();
        }