Ejemplo n.º 1
0
        public void ShouldGenerateNewEventsAfterLoadFromHistory()
        {
            //Given
            Guid         id           = Guid.NewGuid();
            const string name         = "test";
            const string newName      = "second";
            const string newNameThree = "third";
            var          target       = new InventoryAggregateRoot();

            var history = new List <object>
            {
                new InventoryItemCreated(id, name),
                new ModifyItemName(id, newName)
            };

            target.LoadFromHistory(history);

            //When
            target.ChangeName(newNameThree);


            //Then
            var changes = target.GetUncommittedChanges();

            Assert.AreEqual(1, changes.Count);

            var itemNameModified = changes[0] as ItemNameModified;

            Assert.AreEqual(id, itemNameModified.Id);
            Assert.AreEqual(newNameThree, itemNameModified.NewName);
        }
Ejemplo n.º 2
0
        public void ShouldGenerateEventsOnMethodInvocation()
        {
            //Given
            Guid         id      = Guid.NewGuid();
            const string name    = "test";
            const string newName = "second";
            var          target  = new InventoryAggregateRoot(id, name);

            //When
            target.ChangeName(newName);

            //Then
            var changes = target.GetUncommittedChanges();

            Assert.AreEqual(2, changes.Count);

            var inventoryItemCreated = changes[0] as InventoryItemCreated;

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

            var itemNameModified = changes[1] as ItemNameModified;

            Assert.AreEqual(id, itemNameModified.Id);
            Assert.AreEqual(newName, itemNameModified.NewName);
        }
Ejemplo n.º 3
0
        public void ShouldGenerateEventsOnCreation()
        {
            //Given
            Guid         id   = Guid.NewGuid();
            const string name = "test";

            //When
            var target = new InventoryAggregateRoot(id, name);

            //Then
            Assert.AreEqual(id, target.Id);
            var changes = target.GetUncommittedChanges();

            Assert.AreEqual(1, changes.Count);
            var inventoryItemCreated = changes[0] as InventoryItemCreated;

            Assert.AreEqual(id, inventoryItemCreated.Id);
            Assert.AreEqual(name, inventoryItemCreated.Name);
        }
Ejemplo n.º 4
0
        public void ShouldApplyModifications()
        {
            //Given
            Guid         id      = Guid.NewGuid();
            const string name    = "test";
            const string newName = "second";
            var          target  = new InventoryAggregateRoot();

            var history = new List <object>
            {
                new InventoryItemCreated(id, name),
                new ModifyItemName(id, newName)
            };

            //When
            target.LoadFromHistory(history);

            //Then
            Assert.AreEqual(id, target.Id);
        }