public static BoltOnOptions BoltOnMediatorEFModule(this BoltOnOptions boltOnOptions) { //boltOnOptions //.BoltOnEFModule() //.BoltOnAssemblies(Assembly.GetExecutingAssembly()); return(boltOnOptions); }
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> >(); }
public static BoltOnOptions BoltOnEFModule(this BoltOnOptions boltOnOptions) { boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly()); boltOnOptions.ServiceCollection.AddScoped <ChangeTrackerContext>(); boltOnOptions.AddInterceptor <ChangeTrackerInterceptor>(); return(boltOnOptions); }
public static BoltOnOptions BoltOnMassTransitBusModule(this BoltOnOptions boltOnOptions) { boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly()); boltOnOptions.ServiceCollection.AddSingleton <IBus, BoltOnMassTransitBus>(); boltOnOptions.ServiceCollection.AddTransient(typeof(BoltOnMassTransitConsumer <>)); return(boltOnOptions); }
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); }
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); }
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); }
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> >(); }
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); }
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)); }); } }
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); }
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); }
public InterceptorOptions(BoltOnOptions boltOnOptions) { BoltOnOptions = boltOnOptions; }
public static BoltOnOptions BoltOnEFModule(this BoltOnOptions boltOnOptions) { boltOnOptions.BoltOnAssemblies(Assembly.GetExecutingAssembly()); return(boltOnOptions); }
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>(); }