public void RoundtripEventWithReadonlyFields() { var serializer = new JsonDomainEventSerializer("<events>") .AddAliasesFor(typeof (ComplexDomainEvent), typeof (ComplexValue)); var rootId = Guid.NewGuid(); var utcNow = DateTime.UtcNow; var e = new ComplexDomainEvent("hello there", new ComplexValue(23)) { Meta = { {DomainEvent.MetadataKeys.AggregateRootId, rootId.ToString()}, {DomainEvent.MetadataKeys.TimeUtc, utcNow.ToString("u")} } }; var text = serializer.Serialize(e); Console.WriteLine(text); var roundtrippedEvent = (ComplexDomainEvent)serializer.Deserialize(text); //Assert.That(roundtrippedEvent.Meta[DomainEvent.MetadataKeys.AggregateRootId], Is.EqualTo(rootId)); //Assert.That(roundtrippedEvent.Meta[DomainEvent.MetadataKeys.TimeLocal], Is.EqualTo(utcNow.ToLocalTime())); //Assert.That(roundtrippedEvent.Meta[DomainEvent.MetadataKeys.TimeUtc], Is.EqualTo(utcNow)); Assert.That(roundtrippedEvent.Text, Is.EqualTo("hello there")); Assert.That(roundtrippedEvent.Value.Value, Is.EqualTo(23)); }
public void TryReplicating() { var serializer = new JsonDomainEventSerializer(); var source = new InMemoryEventStore(); var destination = new InMemoryEventStore(); var seqNo = 0; Func<string, EventData> getRecognizableEvent = text => serializer.Serialize(new RecognizableEvent(text) { Meta = { {DomainEvent.MetadataKeys.AggregateRootId, "268DD0C0-529F-4242-9D53-601A88BB1813"}, {DomainEvent.MetadataKeys.SequenceNumber, (seqNo).ToString(Metadata.NumberCulture)}, {DomainEvent.MetadataKeys.GlobalSequenceNumber, (seqNo++).ToString(Metadata.NumberCulture)}, } }); // arrange using (var eventReplicator = new EventReplicator(source, destination)) { eventReplicator.Start(); Thread.Sleep(TimeSpan.FromSeconds(2)); // act source.Save(Guid.NewGuid(), new[] { getRecognizableEvent("hello") }); source.Save(Guid.NewGuid(), new[] { getRecognizableEvent("there") }); source.Save(Guid.NewGuid(), new[] { getRecognizableEvent("my") }); source.Save(Guid.NewGuid(), new[] { getRecognizableEvent("friend") }); Thread.Sleep(TimeSpan.FromSeconds(1)); } // assert var greeting = string.Join(" ", destination .Select(x => serializer.Deserialize(x)) .OfType<RecognizableEvent>() .Select(e => e.Id)); Assert.That(greeting, Is.EqualTo("hello there my friend")); }