public void SerializeAndDeserializeCommandWithMetadata() { Converts.Repository .AddJsonEnumSearchHandler() .AddJsonObjectSearchHandler() .AddJsonPrimitivesSearchHandler() .AddJsonKey() .AddJsonTimeSpan(); IFormatter formatter = new CompositeCommandFormatter( new ReflectionCompositeTypeProvider( new ReflectionCompositeDelegateFactory(), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public ), new DefaultFactory <JsonCompositeStorage>() ); TimeSpan delay = TimeSpan.FromSeconds(50); string sourceID = "AbcDef"; int value = 15; Envelope <CreateOrder> envelope = new Envelope <CreateOrder>(new CreateOrder()) .AddDelay(delay) .AddSourceID(sourceID); IKey key = envelope.Body.Key; IKey orderKey = envelope.Body.OrderKey; envelope.Metadata.Add("Value", value); string json = formatter.Serialize(envelope); envelope = formatter.Deserialize <Envelope <CreateOrder> >(json); Assert.AreEqual(delay, envelope.GetDelay()); Assert.AreEqual(sourceID, envelope.GetSourceID()); Assert.AreEqual(value, envelope.Metadata.Get <int>("Value")); Assert.AreEqual(key, envelope.Body.Key); Assert.AreEqual(orderKey, envelope.Body.OrderKey); }
private void Domain() { Converts.Repository .AddStringTo <int>(Int32.TryParse) .AddStringTo <bool>(Boolean.TryParse) .AddEnumSearchHandler(false) .AddJsonEnumSearchHandler() .AddJsonPrimitivesSearchHandler() .AddJsonObjectSearchHandler() .AddJsonKey() .AddJsonTimeSpan() .Add(new ColorConverter()) .AddToStringSearchHandler(); EventStore = new EntityEventStore(ServiceProvider.EventSourcingContextFactory); eventDispatcher = new PersistentEventDispatcher(new EmptyEventStore()); eventDispatcher.DispatcherExceptionHandlers.Add(this); eventDispatcher.EventExceptionHandlers.Add(this); IFactory <ICompositeStorage> compositeStorageFactory = Factory.Default <JsonCompositeStorage>(); typeProvider = new ReflectionCompositeTypeProvider( new ReflectionCompositeDelegateFactory(), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public ); CommandFormatter = new CompositeCommandFormatter(typeProvider, compositeStorageFactory); EventFormatter = new CompositeEventFormatter(typeProvider, compositeStorageFactory, new List <ICompositeFormatterExtender>() { new UserKeyEventExtender() }); commandDispatcher = new PersistentCommandDispatcher(new SerialCommandDistributor(), new EmptyCommandStore(), CommandFormatter); OutcomeRepository = new AggregateRootRepository <Outcome>( EventStore, EventFormatter, new ReflectionAggregateRootFactory <Outcome>(), eventDispatcher, new NoSnapshotProvider(), new EmptySnapshotStore() ); CategoryRepository = new AggregateRootRepository <Category>( EventStore, EventFormatter, new ReflectionAggregateRootFactory <Category>(), eventDispatcher, new NoSnapshotProvider(), new EmptySnapshotStore() ); CurrencyListRepository = new AggregateRootRepository <CurrencyList>( EventStore, EventFormatter, new ReflectionAggregateRootFactory <CurrencyList>(), eventDispatcher, new NoSnapshotProvider(), new EmptySnapshotStore() ); Money.BootstrapTask bootstrapTask = new Money.BootstrapTask( commandDispatcher.Handlers, Factory.Instance(OutcomeRepository), Factory.Instance(CategoryRepository), Factory.Instance(CurrencyListRepository) ); bootstrapTask.Initialize(); }