public void Ctor_SubscribersInAssembly() { var args = EventSubscriberHostArgs.Create(GetType().Assembly); var ts = args.GetSubscriberTypes(); Assert.AreEqual(2, ts.Length); }
public override void Configure(IFunctionsHostBuilder builder) { var config = builder.GetBeefConfiguration <Startup>("Beef_"); // Add the core beef services. builder.Services.AddBeefExecutionContext() .AddBeefRequestCache() .AddBeefCachePolicyManager(config.GetSection("BeefCaching").Get <CachePolicyConfig>()) .AddBeefBusinessServices(); // Add event subscriber host and auto-discovered subscribers. builder.Services.AddBeefEventHubSubscriberHost(EventSubscriberHostArgs.Create <Startup>()); // Add the data sources as singletons for dependency injection requirements. var ccs = config.GetSection("CosmosDb"); builder.Services.AddScoped <Data.Database.IDatabase>(_ => new Database(config.GetConnectionString("BeefDemo"))) .AddDbContext <EfDbContext>() .AddScoped <Data.EntityFrameworkCore.IEfDb, EfDb>() .AddSingleton <Data.Cosmos.ICosmosDb>(_ => new CosmosDb(new Cosmos.CosmosClient(ccs.GetValue <string>("EndPoint"), ccs.GetValue <string>("AuthKey")), ccs.GetValue <string>("Database"))); // Add the generated reference data services for dependency injection requirements. builder.Services.AddGeneratedReferenceDataManagerServices() .AddGeneratedReferenceDataDataSvcServices() .AddGeneratedReferenceDataDataServices(); // Add the generated entity services for dependency injection requirements. builder.Services.AddGeneratedManagerServices() .AddGeneratedDataSvcServices() .AddGeneratedDataServices(); // Add event publishing. builder.Services.AddBeefEventHubEventPublisher(config.GetValue <string>("EventHubConnectionString")); }
public void C120_DoNotAllowMultipleMessages() { var sp = TestSetUp.CreateServiceProvider(); ExpectException.Throws<EventSubscriberException>( "The 'EventDataSubscriberHost' does not AllowMultipleMessages; there were 2 event messages.", async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(new EventData(), new EventData())); }
public void Ctor_NoIEventSubscriber() { var sp = TestSetUp.CreateServiceProvider(); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp)); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, (Type[])null)); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, new Type[] { })); }
public override void Configure(IFunctionsHostBuilder builder) { // Services configuration as follows: // - .AddBeefExecutionContext - enables the `ExecutionContext` required internally by _Beef_. // - .AddBeefServiceBusReceiverHost - adds the capability to encapsulate the receive orchestration Azure Service Bus messages. builder.Services.AddBeefExecutionContext(); builder.Services.AddBeefServiceBusReceiverHost(EventSubscriberHostArgs.Create <Startup>()); }
public void C110_TooManySubjectSubscribers() { var ed = new EventData<string> { Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST" }; var sp = TestSetUp.CreateServiceProvider(); ExpectException.Throws<EventSubscriberException>( "There are 2 IEventSubscriber instances subscribing to Subject 'Test.Blah.123' and Action 'CREATE'; there must be only a single subscriber.", async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub), typeof(TestSubS)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(ed)); }
public async Task C130_AllowMultipleMessages() { var sp = TestSetUp.CreateServiceProvider(); await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(sp, typeof(TestSub)).UseLoggerForAuditing()).AllowMultipleMessages().ReceiveAsync(new EventData { Subject = "X" }, new EventData { Subject = "X" }); }
public override void Configure(IFunctionsHostBuilder builder) { var config = builder.GetBeefConfiguration <Startup>("Beef_"); // Add the core beef services. builder.Services.AddBeefExecutionContext() .AddBeefSystemTime() .AddBeefRequestCache() .AddBeefCachePolicyManager(config.GetSection("BeefCaching").Get <CachePolicyConfig>(), new System.TimeSpan(0, 0, 30), new System.TimeSpan(0, 0, 30), useCachePolicyManagerTimer: true) .AddBeefBusinessServices(); // Add event subscriber host with auto-discovered subscribers and set the audit writer to use azure storage; plus use the poison event orchestrator/invoker. var ehasr = new EventHubAzureStorageRepository(config.GetConnectionString("AzureStorage")); builder.Services.AddBeefEventHubConsumerHost( EventSubscriberHostArgs.Create <Startup>().UseAuditWriter(ehasr).UseMaxAttempts(10), additional: (_, ehsh) => ehsh.UseInvoker(new EventHubConsumerHostPoisonInvoker(ehasr))); var sbasr = new ServiceBusAzureStorageRepository(config.GetConnectionString("AzureStorage")); builder.Services.AddBeefServiceBusReceiverHost( EventSubscriberHostArgs.Create <Startup>().UseAuditWriter(sbasr).UseMaxAttempts(10), additional: (_, ehsh) => ehsh.UseInvoker(new ServiceBusReceiverHostPoisonInvoker(sbasr))); // Add the data sources as singletons for dependency injection requirements. var ccs = config.GetSection("CosmosDb"); builder.Services.AddScoped <Data.Database.IDatabase>(_ => new Database(config.GetConnectionString("BeefDemo"))) .AddDbContext <EfDbContext>() .AddScoped <Data.EntityFrameworkCore.IEfDb, EfDb>() .AddSingleton <Data.Cosmos.ICosmosDb>(_ => new CosmosDb(new Cosmos.CosmosClient(ccs.GetValue <string>("EndPoint"), ccs.GetValue <string>("AuthKey")), ccs.GetValue <string>("Database"))); // Add the generated reference data services for dependency injection requirements. builder.Services.AddGeneratedReferenceDataManagerServices() .AddGeneratedReferenceDataDataSvcServices() .AddGeneratedReferenceDataDataServices(); // Add the generated entity services for dependency injection requirements. builder.Services.AddGeneratedManagerServices() .AddGeneratedValidationServices() .AddGeneratedDataSvcServices() .AddGeneratedDataServices(); // Add identifier generator services. builder.Services.AddSingleton <IGuidIdentifierGenerator, GuidIdentifierGenerator>() .AddSingleton <IStringIdentifierGenerator, StringIdentifierGenerator>(); // Add event publishing. builder.Services.AddBeefEventHubEventProducer(new EventHubProducerClient(config.GetValue <string>("EventHubConnectionString"))); // Add the AutoMapper profiles. builder.Services.AddAutoMapper(Mapper.AutoMapperProfile.Assembly, typeof(ContactData).Assembly); // Add logging. builder.Services.AddLogging(); }
public void Ctor_NoSubscribersInAssembly() { ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(typeof(TestAttribute).Assembly)); }
public void Ctor_NoIEventSubscriber() { ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create()); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create((Type[])null)); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(new Type[] { })); }
private EventDataSubscriberHost CreateTestHost<T>(Func<T> create) where T : class { var sp = TestSetUp.CreateServiceProvider(sc => sc.AddTransient(_ => create())); return new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(T)).UseServiceProvider(sp).UseLoggerForAuditing()); }
public void Ctor_NoSubscribersInAssembly() { var sp = TestSetUp.CreateServiceProvider(); ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, typeof(TestAttribute).Assembly)); }