Exemplo n.º 1
0
        public void Deserialize()
        {
            var formatter = new JsonEventFormatter(_typeResolver);
            var obj = new StoredEvent<JObject>(
                eventName: "bob",
                eventVersion: new Version(3, 0) /* different on purpose */,
                eventIdentifier: new Guid("402639D5-4106-4AE7-B210-45780C7A08F3"),
                eventSourceId: new Guid("697BAB3C-E122-4C70-85B0-76750BC2D878"),
                eventSequence: 1,
                eventTimeStamp: new DateTime(2001, 4, 12, 12, 52, 21, 425, DateTimeKind.Utc),
                data: new JObject(
                    new JProperty("Name", "Alice"),
                    new JProperty("Value", 10),
                    new JProperty("Day", new DateTime(2000, 01, 01))
                )
            );

            var rawResult = formatter.Deserialize(obj);
            rawResult.Should().BeOfType<AnEvent>();

            var result = (AnEvent) rawResult;
            result.EventIdentifier.Should().Be(obj.EventIdentifier);
            result.EventSourceId.Should().Be(obj.EventSourceId);
            result.EventSequence.Should().Be(obj.EventSequence);
            result.EventTimeStamp.Should().Be(obj.EventTimeStamp);
            result.EventVersion.Should().Be(new Version(2, 0));

            result.Name.Should().Be("Alice");
            result.Value.Should().Be(10);
            result.Day.Should().Be(new DateTime(2000, 01, 01));
        }
Exemplo n.º 2
0
 public virtual void InitializeFrom(StoredEvent stored)
 {
     EventIdentifier = stored.EventIdentifier;
     EventSourceId = stored.EventSourceId;
     EventSequence = stored.EventSequence;
     EventTimeStamp = stored.EventTimeStamp;
 }
Exemplo n.º 3
0
 public virtual void InitializeFrom(StoredEvent stored)
 {
     // TODO: this does not update the event version information. That information isn't even exposed here.
     EventIdentifier = stored.EventIdentifier;
     EventSourceId = stored.EventSourceId;
     EventSequence = stored.EventSequence;
     EventTimeStamp = stored.EventTimeStamp;
 }
        public void Upgrade(StoredEvent<JObject> theEvent)
        {
            if (theEvent.EventVersion < V2) {
                var obj = theEvent.Data;

                var name = string.Format("{0} {1}",
                    obj.Property("Forename").Value,
                    obj.Property("Surname").Value);

                obj.Remove("Forename");
                obj.Remove("Surname");
                obj.Add("Name", name);

                theEvent.EventVersion = V2;
            }
        }