/// <summary> /// Handles the specific domain event. /// </summary> /// <param name="domainEvent">The domain event.</param> /// <param name="cancellationToken">The cancellation token.</param> private async Task HandleSpecificDomainEvent(EstateCreatedEvent domainEvent, CancellationToken cancellationToken) { await this.EstateReportingRepository.CreateReadModel(domainEvent, cancellationToken); await this.EstateReportingRepository.AddEstate(domainEvent, cancellationToken); }
public static void LoadTypes() { VoucherIssuedEvent v = new VoucherIssuedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, "", ""); TransactionHasStartedEvent t = new TransactionHasStartedEvent(Guid.Parse("2AA2D43B-5E24-4327-8029-1135B20F35CE"), Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, "", "", "", "", null); ReconciliationHasStartedEvent r = new ReconciliationHasStartedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); EstateCreatedEvent e = new EstateCreatedEvent(Guid.NewGuid(), ""); MerchantCreatedEvent m = new MerchantCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), "", DateTime.Now); ContractCreatedEvent c = new ContractCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), ""); MerchantBalanceChangedEvent mb = new MerchantBalanceChangedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, Guid.NewGuid(), Guid.NewGuid(), 0, 0, 0, ""); ImportLogCreatedEvent i = new ImportLogCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.MinValue); FileCreatedEvent f = new FileCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), String.Empty, DateTime.MinValue); SettlementCreatedForDateEvent s = new SettlementCreatedForDateEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); StatementCreatedEvent ms = new StatementCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); TypeProvider.LoadDomainEventsTypeDynamically(); }
public void EstateCreatedEvent_CanBeCreated_IsCreated() { EstateCreatedEvent estateCreatedEvent = new EstateCreatedEvent(TestData.EstateId, TestData.EstateName); estateCreatedEvent.ShouldNotBeNull(); estateCreatedEvent.AggregateId.ShouldBe(TestData.EstateId); estateCreatedEvent.EventId.ShouldNotBe(Guid.Empty); estateCreatedEvent.EstateId.ShouldBe(TestData.EstateId); estateCreatedEvent.EstateName.ShouldBe(TestData.EstateName); }
/// <summary> /// Creates the specified estate name. /// </summary> /// <param name="estateName">Name of the estate.</param> public void Create(String estateName) { Guard.ThrowIfNullOrEmpty(estateName, typeof(ArgumentNullException), "Estate name must be provided when registering a new estate"); this.CheckEstateHasNotAlreadyBeenCreated(); EstateCreatedEvent estateCreatedEvent = new EstateCreatedEvent(this.AggregateId, estateName); this.ApplyAndAppend(estateCreatedEvent); }
public void EstateDomainEventHandler_EstateCreatedEvent_EventIsHandled() { EstateCreatedEvent estateCreatedEvent = TestData.EstateCreatedEvent; Mock <IEstateReportingRepository> estateReportingRepository = new Mock <IEstateReportingRepository>(); EstateDomainEventHandler eventHandler = new EstateDomainEventHandler(estateReportingRepository.Object); Logger.Initialise(NullLogger.Instance); Should.NotThrow(async() => { await eventHandler.Handle(estateCreatedEvent, CancellationToken.None); }); }
public void DomainEventHandlerResolver_GetDomainEventHandlers_EstateCreatedEvent_NoHandlersConfigured_EventHandlersReturned() { Dictionary <String, String[]> eventHandlerConfiguration = new Dictionary <String, String[]>(); EstateCreatedEvent estateCreatedEvent = TestData.EstateCreatedEvent; Mock <IDomainEventHandler> domainEventHandler = new Mock <IDomainEventHandler>(); Func <Type, IDomainEventHandler> createDomainEventHandlerFunc = (type) => { return(domainEventHandler.Object); }; DomainEventHandlerResolver resolver = new DomainEventHandlerResolver(eventHandlerConfiguration, createDomainEventHandlerFunc); List <IDomainEventHandler> handlers = resolver.GetDomainEventHandlers(estateCreatedEvent); handlers.ShouldBeNull(); }
public void DomainEventHandlerResolver_GetDomainEventHandlers_EstateCreatedEvent_EventNotConfigured_EventHandlersReturned() { String handlerTypeName = "EstateReporting.BusinessLogic.EventHandling.EstateDomainEventHandler, EstateReporting.BusinessLogic"; Dictionary <String, String[]> eventHandlerConfiguration = new Dictionary <String, String[]>(); EstateCreatedEvent estateCreatedEvent = TestData.EstateCreatedEvent; eventHandlerConfiguration.Add("RandomEvent", new String[] { handlerTypeName }); Mock <IDomainEventHandler> domainEventHandler = new Mock <IDomainEventHandler>(); Func <Type, IDomainEventHandler> createDomainEventHandlerFunc = (type) => { return(domainEventHandler.Object); }; DomainEventHandlerResolver resolver = new DomainEventHandlerResolver(eventHandlerConfiguration, createDomainEventHandlerFunc); List <IDomainEventHandler> handlers = resolver.GetDomainEventHandlers(estateCreatedEvent); handlers.ShouldBeNull(); }
// This method gets called by the runtime. Use this method to add services to the container. /// <summary> /// Configures the services. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { ConfigurationReader.Initialise(Startup.Configuration); Startup.ConfigureEventStoreSettings(); this.ConfigureMiddlewareServices(services); services.AddTransient <IMediator, Mediator>(); services.AddSingleton <IEstateManagementManager, EstateManagementManager>(); Boolean useConnectionStringConfig = Boolean.Parse(ConfigurationReader.GetValue("AppSettings", "UseConnectionStringConfig")); if (useConnectionStringConfig) { String connectionStringConfigurationConnString = ConfigurationReader.GetConnectionString("ConnectionStringConfiguration"); services.AddSingleton <IConnectionStringConfigurationRepository, ConnectionStringConfigurationRepository>(); services.AddTransient <ConnectionStringConfigurationContext>(c => { return(new ConnectionStringConfigurationContext(connectionStringConfigurationConnString)); }); // TODO: Read this from a the database and set } else { services.AddEventStoreClient(Startup.ConfigureEventStoreSettings); services.AddEventStoreProjectionManagerClient(Startup.ConfigureEventStoreSettings); services.AddEventStorePersistentSubscriptionsClient(Startup.ConfigureEventStoreSettings); services.AddSingleton <IConnectionStringConfigurationRepository, ConfigurationReaderConnectionStringRepository>(); } services.AddTransient <IEventStoreContext, EventStoreContext>(); services.AddSingleton <IEstateManagementRepository, EstateManagementRepository>(); services.AddSingleton <IDbContextFactory <EstateReportingContext>, DbContextFactory <EstateReportingContext> >(); Dictionary <String, String[]> handlerEventTypesToSilentlyHandle = new Dictionary <String, String[]>(); if (Startup.Configuration != null) { IConfigurationSection section = Startup.Configuration.GetSection("AppSettings:HandlerEventTypesToSilentlyHandle"); if (section != null) { Startup.Configuration.GetSection("AppSettings:HandlerEventTypesToSilentlyHandle").Bind(handlerEventTypesToSilentlyHandle); } } services.AddSingleton <Func <String, EstateReportingContext> >(cont => (connectionString) => { return(new EstateReportingContext(connectionString)); }); DomainEventTypesToSilentlyHandle eventTypesToSilentlyHandle = new DomainEventTypesToSilentlyHandle(handlerEventTypesToSilentlyHandle); services.AddTransient <IEventStoreContext, EventStoreContext>(); services.AddSingleton <IAggregateRepository <EstateAggregate.EstateAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <EstateAggregate.EstateAggregate, DomainEventRecord.DomainEvent> >(); services.AddSingleton <IAggregateRepository <MerchantAggregate.MerchantAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <MerchantAggregate.MerchantAggregate, DomainEventRecord.DomainEvent> >(); services.AddSingleton <IAggregateRepository <ContractAggregate.ContractAggregate, DomainEventRecord.DomainEvent>, AggregateRepository <ContractAggregate.ContractAggregate, DomainEventRecord.DomainEvent> >(); services.AddSingleton <IEstateDomainService, EstateDomainService>(); services.AddSingleton <IMerchantDomainService, MerchantDomainService>(); services.AddSingleton <IContractDomainService, ContractDomainService>(); services.AddSingleton <IModelFactory, ModelFactory>(); services.AddSingleton <Factories.IModelFactory, Factories.ModelFactory>(); services.AddSingleton <ISecurityServiceClient, SecurityServiceClient>(); ContractCreatedEvent c = new ContractCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), ""); MerchantCreatedEvent m = new MerchantCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), "", DateTime.Now); EstateCreatedEvent e = new EstateCreatedEvent(Guid.NewGuid(), ""); TypeProvider.LoadDomainEventsTypeDynamically(); // request & notification handlers services.AddTransient <ServiceFactory>(context => { return(t => context.GetService(t)); }); services.AddSingleton <IRequestHandler <CreateEstateRequest, String>, EstateRequestHandler>(); services.AddSingleton <IRequestHandler <CreateEstateUserRequest, Guid>, EstateRequestHandler>(); services.AddSingleton <IRequestHandler <AddOperatorToEstateRequest, String>, EstateRequestHandler>(); services.AddSingleton <IRequestHandler <CreateMerchantRequest, String>, MerchantRequestHandler>(); services.AddSingleton <IRequestHandler <AssignOperatorToMerchantRequest, String>, MerchantRequestHandler>(); services.AddSingleton <IRequestHandler <CreateMerchantUserRequest, Guid>, MerchantRequestHandler>(); services.AddSingleton <IRequestHandler <AddMerchantDeviceRequest, String>, MerchantRequestHandler>(); services.AddSingleton <IRequestHandler <MakeMerchantDepositRequest, Guid>, MerchantRequestHandler>(); services.AddSingleton <IRequestHandler <CreateContractRequest, String>, ContractRequestHandler>(); services.AddSingleton <IRequestHandler <AddProductToContractRequest, String>, ContractRequestHandler>(); services.AddSingleton <IRequestHandler <AddTransactionFeeForProductToContractRequest, String>, ContractRequestHandler>(); services.AddSingleton <Func <String, String> >(container => (serviceName) => { return(ConfigurationReader.GetBaseServerUri(serviceName).OriginalString); }); HttpClientHandler httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => { return(true); } }; HttpClient httpClient = new HttpClient(httpClientHandler); services.AddSingleton <HttpClient>(httpClient); }
/// <summary> /// Plays the event. /// </summary> /// <param name="domainEvent">The domain event.</param> private void PlayEvent(EstateCreatedEvent domainEvent) { this.EstateName = domainEvent.EstateName; this.IsCreated = true; }