Example #1
0
        public void ShouldPopulateProjections()
        {
            //Given
            var          events           = new List <object>();
            Guid         id               = Guid.NewGuid();
            const string name             = "test";
            const string newName          = "second";
            var          bus              = new E05.Test.Infrastructure.Bus();
            var          eventsSerializer = EventsSerializer.GetEventSerializer();
            var          eventStore       = new EventStore(bus, eventsSerializer);
            var          commandHandler   = new InventoryCommandHandler(bus, eventStore);
            var          projection       = new ItemsProjection(bus);

            //When
            bus.Send(new CreateInventoryItem(id, name));
            bus.Send(new ModifyItemName(id, newName, 0));

            var items = projection.GetAll().ToList();

            Assert.AreEqual(1, items.Count);
            var kvp = items[0];

            Assert.AreEqual(id, kvp.Id);
            Assert.AreEqual(newName, kvp.Name);
            Assert.AreEqual(1, kvp.Version);
        }
Example #2
0
        public void ShouldSendDataViaBus()
        {
            //Given
            var          events  = new List <object>();
            Guid         id      = Guid.NewGuid();
            const string name    = "test";
            const string newName = "second";
            var          bus     = new E05.Test.Infrastructure.Bus();

            bus.AddListener(ob =>
            {
                events.Add(ob);
            });
            var eventStore = new EventStore(bus);
            var target     = new InventoryCommandHandler(bus, eventStore);

            //When
            bus.Send(new CreateInventoryItem(id, name));
            bus.Send(new ModifyItemName(id, newName, 0));


            //Then
            Assert.AreEqual(4, events.Count);
            var inventoryItemCreated = events[1] as InventoryItemCreated;

            Assert.AreEqual(id, inventoryItemCreated.Id);
            Assert.AreEqual(name, inventoryItemCreated.Name);

            var itemNameModified = events[3] as ItemNameModified;

            Assert.AreEqual(id, itemNameModified.Id);
            Assert.AreEqual(newName, itemNameModified.NewName);
        }
Example #3
0
 public void Setup()
 {
     _target    = new E05.Test.Infrastructure.Bus();
     _topics    = new List <object>();
     _queues    = new List <object>();
     _listeners = new List <object>();
 }
Example #4
0
        public void ShouldGenerateSnapshot()
        {
            //Given
            var          events           = new List <object>();
            Guid         id               = Guid.NewGuid();
            const string name             = "test";
            var          bus              = new E05.Test.Infrastructure.Bus();
            var          snapshotStore    = new SnapshotStore();
            var          eventsSerializer = EventsSerializer.GetEventSerializer();
            var          eventStore       = new EventStore(bus, eventsSerializer, snapshotStore);
            var          commandHandler   = new InventoryCommandHandler(bus, eventStore);
            var          projection       = new ItemsProjection(bus);

            bus.Send(new CreateInventoryItem(id, name));

            //When
            var i = 0;

            for (; i < 11; i++)
            {
                var lastProjection = projection.GetById(id);
                bus.Send(new ModifyItemName(id, "new" + i, lastProjection.Version));
            }

            //Then
            var items = projection.GetAll().ToList();

            Assert.AreEqual(1, items.Count);
            var kvp = items[0];

            Assert.AreEqual(id, kvp.Id);
            Assert.AreEqual("new10", kvp.Name);
            Assert.AreEqual(11, kvp.Version);

            var snapshotData = snapshotStore.GetSnapshot(id);

            Assert.AreEqual(10, snapshotData.Version);
            var snapshot = JsonConvert.DeserializeObject <InventorySnapshot>(snapshotData.Data);

            Assert.AreEqual("new9", snapshot.Name);
        }
Example #5
0
 public ItemsProjection(E05.Test.Infrastructure.Bus bus)
 {
     bus.RegisterTopic <InventoryItemCreated>(Handle);
     bus.RegisterTopic <ItemNameModified>(Handle);
 }