public void InvokingBehaviour_GivenSimpleAggregateRoot_ShouldRecordEvents()
        {
            // Arrange
            var user = new User();

            user.Register();

            // Act
            user.ChangePassword("newpassword");
            IEnumerable <IEvent> actual = user.GetUncommittedEvents();

            var expected = new EventChain
            {
                new UserRegistered(user.Id),
                new UserChangedPassword("newpassword")
            };

            ObjectComparisonResult result = _comparer.AreEqual(expected, actual);

            if (!result.AreEqual)
            {
                throw new AssertionException(string.Format("Actual events did not match expected events. {0}", result.InequalityReason));
            }
        }
Esempio n. 2
0
        public void GivenAggregateWithUncommittedEvents_WhenSaved_ThenEventStoreShouldContainThoseEvents()
        {
            // Arrange
            var eventStore = new InMemoryEventStore(new ConsoleLogger());
            IRepository <User> repository = new EventSourcingRepository <User>(eventStore, new Mock <IConcurrencyMonitor>().Object, _logger);
            var user = new User();

            user.Register();

            var expectedEvents = new object[] { new UserRegistered(user.Id) };

            // Act
            repository.Save(user);

            // Assert
            var comparisonResult = _comparer.AreEqual(expectedEvents, eventStore.GetAllEvents());

            Assert.That(comparisonResult.AreEqual, comparisonResult.InequalityReason);
        }
Esempio n. 3
0
        public void CompareEmptyObjects()
        {
            var object1 = new NonBuiltInEmptyClass();
            var object2 = new NonBuiltInEmptyClass();

            var result = comparer.AreEqual(object1, object2);

            Assert.IsTrue(result.AreEqual, "The objects are not equal, despite being empty.");
        }