private void BuildCountryProjector() { var countryMapBuilder = new EventMapBuilder <CountryLookup, string, NHibernateProjectionContext>(); countryMapBuilder .Map <CountryRegisteredEvent>() .AsCreateOf(anEvent => anEvent.Code) .Using((country, anEvent) => country.Name = anEvent.Name); countryProjector = new NHibernateChildProjector <CountryLookup, string>(countryMapBuilder, (lookup, identity) => lookup.Id = identity) { // We use a local LRU cache for the countries to avoid unnecessary database lookups. Cache = new LruProjectionCache <CountryLookup, string>( 20000, TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(2), p => p.Id, () => DateTime.UtcNow) }; }
public When_there_is_a_child_projector() { Given(() => { Events.Map <ProductAddedToCatalogEvent>() .AsCreateOf(anEvent => anEvent.ProductKey) .Using((entry, anEvent) => entry.Category = anEvent.Category); Events.Map <ProductAddedToCatalogEvent>().As((anEvent, context) => { ProductCatalogChildEntry childEntry1 = context.Session.Get <ProductCatalogChildEntry>("c350E"); ProductCatalogChildEntry childEntry2 = context.Session.Get <ProductCatalogChildEntry>("c350F"); childProjectionStates.Add(new ChildProjectionState { Entry1Exists = childEntry1 != null, Entry2Exists = childEntry2 != null }); }); var childMapBuilder = new EventMapBuilder <ProductCatalogChildEntry, string, NHibernateProjectionContext>(); childMapBuilder.Map <ProductAddedToCatalogEvent>() .AsCreateOf(anEvent => anEvent.ProductKey) .Using((entry, anEvent) => entry.Category = anEvent.Category); var childProjector = new NHibernateChildProjector <ProductCatalogChildEntry, string>(childMapBuilder); StartProjecting(children: new INHibernateChildProjector[] { childProjector }); }); When(async() => { var transaction1 = new Transaction { Events = new[] { new EventEnvelope { Body = new ProductAddedToCatalogEvent { ProductKey = "c350E", Category = "Hybrid" } } } }; transaction2 = new Transaction { Events = new[] { new EventEnvelope { Body = new ProductAddedToCatalogEvent { ProductKey = "c350F", Category = "Gas" } } } }; await The <MemoryEventSource>().Write(transaction1, transaction2); }); }