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(); }
/// <summary> /// Plays the event. /// </summary> /// <param name="merchantCreatedEvent">The merchant created event.</param> private void PlayEvent(MerchantCreatedEvent merchantCreatedEvent) { this.IsCreated = true; this.EstateId = merchantCreatedEvent.EstateId; this.Name = merchantCreatedEvent.MerchantName; this.AggregateId = merchantCreatedEvent.AggregateId; this.DateCreated = merchantCreatedEvent.DateCreated; this.MaximumDevices = 1; }
/// <summary> /// Creates the specified estate identifier. /// </summary> /// <param name="estateId">The estate identifier.</param> /// <param name="merchantName">Name of the merchant.</param> /// <param name="dateCreated">The date created.</param> public void Create(Guid estateId, String merchantName, DateTime dateCreated) { // Ensure this merchant has not already been created this.EnsureMerchantNotAlreadyCreated(); MerchantCreatedEvent merchantCreatedEvent = new MerchantCreatedEvent(this.AggregateId, estateId, merchantName, dateCreated); this.ApplyAndAppend(merchantCreatedEvent); }
public void MerchantDomainEventHandler_MerchantCreatedEvent_EventIsHandled() { MerchantCreatedEvent merchantCreatedEvent = TestData.MerchantCreatedEvent; Mock <IEstateReportingRepository> estateReportingRepository = new Mock <IEstateReportingRepository>(); MerchantDomainEventHandler eventHandler = new MerchantDomainEventHandler(estateReportingRepository.Object); Logger.Initialise(NullLogger.Instance); Should.NotThrow(async() => { await eventHandler.Handle(merchantCreatedEvent, CancellationToken.None); }); }
public void MerchantCreatedEvent_CanBeCreated_IsCreated() { MerchantCreatedEvent merchantCreatedEvent = new MerchantCreatedEvent(TestData.MerchantId, TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); merchantCreatedEvent.ShouldNotBeNull(); merchantCreatedEvent.AggregateId.ShouldBe(TestData.MerchantId); merchantCreatedEvent.EventId.ShouldNotBe(Guid.Empty); merchantCreatedEvent.EstateId.ShouldBe(TestData.EstateId); merchantCreatedEvent.DateCreated.ShouldBe(TestData.DateMerchantCreated); merchantCreatedEvent.MerchantName.ShouldBe(TestData.MerchantName); merchantCreatedEvent.MerchantId.ShouldBe(TestData.MerchantId); }
/// <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(MerchantCreatedEvent domainEvent, CancellationToken cancellationToken) { await this.EstateReportingRepository.AddMerchant(domainEvent, cancellationToken); }
// 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); }