public static async Task Run() { var appender = new MemoryAppendStoreAsync(); IEventStoreAsync es = new EventStoreAsync(appender); IDtoConverter<SayingDto, Saying> converter = new MyDtoConverters(); Stream mem = System.IO.File.Open("test.json", FileMode.OpenOrCreate, FileAccess.ReadWrite); IDtoSerializer<SayingDto> dtoSerializer = new FastJsonSerializer<SayingDto>(mem); ITableReaderWriter<Saying> said = new TableWriterForSerializer<Saying, SayingDto>(new MemoryHashTableWriter<Saying>(), converter, dtoSerializer); IAsyncProjection projection = new ConsoleProjection(new AsyncProjectFromImplementation(new SayingHistoryProjection(said))); IEventStoreAsync es2 = new EventStoreAsyncPublisher(es, projection); //IAsyncCommandDispatcher dispatcher = new ConsoleLoggerDispatcher(new CompositeAsyncCommandDispatcher(new SaySomething(es2))); ICommandHandler handler = new SaySomething(es2); await handler.GetExecutor(new SayCommand() { PersonId = new PersonId(1), Say = "Say hello", Timestamp = DateTime.UtcNow }).Execute(); foreach (var saying in said.GetAll().Result) { Console.Write("Entry in projection:\t\t"); Console.WriteLine("{0} said: {1}", saying.PersonId, saying.Said); } }
public async Task ExecuteCommand() { string container = "testing"; string connection = ""; //var appender = new AzureAsyncAppender(connection, container, new PrefixedDirectory("demo")); //await appender.Initialize(); var appender = new MemoryAppendStoreAsync(); var es = new EventStoreAsync(appender); var dispatcher = new SaySomething(es); await dispatcher.GetExecutor( new SayCommand { PersonId = new PersonId(1), Say = "I am Winter ", Timestamp = DateTime.UtcNow }).Execute(); await dispatcher.GetExecutor( new SayCommand { PersonId = new PersonId(1), Say = "How are you?", Timestamp = DateTime.UtcNow }).Execute(); await dispatcher.GetExecutor( new SayCommand { PersonId = new PersonId(1), Say = "Dunno...", Timestamp = DateTime.UtcNow }).Execute(); await dispatcher.GetExecutor( new SayCommand { PersonId = new PersonId(1), Say = "ok say something more", Timestamp = DateTime.UtcNow }).Execute(); await dispatcher.GetExecutor( new SayCommand { PersonId = new PersonId(1), Say = "NO!", Timestamp = DateTime.UtcNow }).Execute(); var events = (await es.ReplayAll()).Events; Assert.Equal(5, events.Count); }
public async Task AppendToEmptyStream() { var appender = new MemoryAppendStoreAsync(); var es = new EventStoreAsync(appender); var dispatcher = new TastyDomainDriven.Sample.CommandServices.SaySomething(es); await dispatcher.GetExecutor(new SayCommand() { PersonId = new PersonId(1), Say = "I have something to say", Timestamp = DateTime.UtcNow }).Execute(); Assert.Equal(1, (await es.ReplayAll()).Events.Count); }
public async Task AppendToToPublisher() { var appender = new MemoryAppendStoreAsync(); var es = new EventStoreAsync(appender); ITableReaderWriter<Saying> table = new MemoryHashTableWriter<Saying>(); var publisher = new EventStoreAsyncPublisher(es, new AsyncProjectFromImplementation(new SayingHistoryProjection(table))); var dispatcher = new Sample.CommandServices.SaySomething(publisher); await dispatcher.GetExecutor(new SayCommand() { PersonId = new PersonId(1), Say = "I have something to say", Timestamp = DateTime.UtcNow }).Execute(); Assert.Equal(1, (await es.ReplayAll()).Events.Count); Assert.Equal(1, (await table.GetAll()).Count); }