public void DeserializeEventStreamShouldReturnAnEvent()
        {
            //Arrange
            var evt  = new EventStub(12);
            var json = @"{
                            'Id': '12',
                            'MediaFileId': '26443db2-1ca1-4f19-bd34-98654a61741c',
                            'AggregateId': '735f8407-16be-44b5-be96-2bab582b5298',
                            'EventId': 'b6c73140-684b-447c-b8fd-9c78c975dc38',
                            'AggregateVersion': 1,
                            'OcurrendOn': '2019-09-08T10:55:48.5529384Z'
                         }";
            Mock <IJsonProvider> moqJsonProvider = new Mock <IJsonProvider>();

            moqJsonProvider.Setup(m => m.DeserializeObject <EventStub>(It.IsAny <string>(),
                                                                       It.IsAny <string>())).Returns(evt);

            //Act
            IEventSerializer sut = new JsonEventSerializer(moqJsonProvider.Object);

            var result = sut.Deserialize <EventStub>(It.IsAny <string>(), json);

            //Assert
            Assert.Equal(evt, result);
        }
        public void passthru_string()
        {
            var json = _serializer.Serialize(new StringEvent {
                String = "Hello"
            });
            var str = (StringEvent)_serializer.Deserialize(json);

            Assert.AreEqual("Hello", str.String);
        }
        public void passthru_jobject()
        {
            var serializer = new JsonEventSerializer <JObject>();
            var obj        = new JObject {
                { "String", new JValue("Hello") }, { "Type", new JValue("StringEvent") }
            };
            var json = serializer.Serialize(obj);
            var obj2 = serializer.Deserialize(json);

            Assert.AreEqual("Hello", obj2.Property("String").ToObject <string>());
            Assert.AreEqual("StringEvent", obj2.Property("Type").ToObject <string>());
        }
Ejemplo n.º 4
0
        public void ShouldBeAbleToSerializerAndDeserialize()
        {
            var obj = ValidSimpleObject();

            var serializer = new JsonEventSerializer();
            var serial     = serializer.Serialize(obj);
            var actual     = (TestSimpleObject)serializer.Deserialize(obj.Type, serial);

            Assert.Equal(obj.StringType, actual.StringType);
            Assert.Equal(obj.TrueBoolean, actual.TrueBoolean);
            Assert.Equal(obj.FalseBoolean, actual.FalseBoolean);
            Assert.Equal(obj.Double, actual.Double);
            Assert.Equal(obj.Integer, actual.Integer);
        }
Ejemplo n.º 5
0
        public void Read_RecoversConcreteTypeProperties()
        {
            //Arrange
            string json = serializer.Serialize(@event);

            //Act
            Event     deserializedEvent     = serializer.Deserialize(json);
            FakeEvent deserializedFakeEvent = (FakeEvent)deserializedEvent;

            //Assert
            deserializedFakeEvent.AggregateId.Should().Be(@event.AggregateId);
            deserializedFakeEvent.Id.Should().Be(@event.Id);
            deserializedFakeEvent.Date.Should().Be(@event.Date);
            deserializedFakeEvent.Message.Should().Be(@event.Message);
        }
Ejemplo n.º 6
0
        public void ShouldSerializeLists()
        {
            var obj = new TestEventWithList(Guid.NewGuid().ToString())
            {
                ListOfObjects = new []
                {
                    ValidSimpleObject(), ValidSimpleObject()
                }
            };

            var serializer = new JsonEventSerializer();
            var serial     = serializer.Serialize(obj);
            var actual     = (TestEventWithList)serializer.Deserialize(obj.Type, serial);

            Assert.Equal(obj.ListOfObjects.Count(), actual.ListOfObjects.Count());
        }
Ejemplo n.º 7
0
        private void Replay()
        {
            var events = new EventList();

            using (var conn = _configuration.CreateConnection())
            {
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = "delete from Customer";
                cmd.ExecuteNonQuery();

                cmd             = conn.CreateCommand();
                cmd.CommandText = "select * from CustomerEvent order by eventDateTime asc";

                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    events.Add(_eventSerializer.Deserialize((string)reader["eventType"], (byte[])reader["Data"]));
                }
            }
            events.ForEach(x => _bus.Post(x));
        }