Beispiel #1
0
        protected override void Because()
        {
            _repository1.Save(aggregate, Guid.NewGuid());
            aggregate.ChangeName("one");

            _thrown = Catch.Exception(() => _repository2.Save(aggregate, Guid.NewGuid()));
        }
        public async Task Can_Modify_Aggregate()
        {
            // PREPARE
            var @event = new TestAggregateCreated
            {
                TestAggregateId = 332,
                Name            = "ddsd"
            };

            var aggregate = new TestAggregate();
            await aggregate.Initialize(GetEvents(@event), Task.FromResult(3333));

            // RUN
            aggregate.ChangeName("changed name");

            // ASSERT
            Assert.True(aggregate.HasChanges());
            Assert.Equal("332", aggregate.AggregateId);
            Assert.Equal(3333, aggregate.AggregateVersion);
            var changes = aggregate.GetChanges();

            Assert.Single(changes);
            var nameChanged = (TestAggregateNameChanged)changes.Single();

            Assert.Equal(332, nameChanged.TestAggregateId);
            Assert.Equal("ddsd", nameChanged.PreviousName);
            Assert.Equal("changed name", nameChanged.CurrentName);
        }
        public void RepositoryShouldReturnPreviouslySavedAggregateWithChangesAppliedInTheRightOrder()
        {
            EventBus   eventBus;
            EventStore eventStore;
            var        repository = EnvironmentMock.CreateEnvironment <TestAggregate>(out eventBus, out eventStore);

            var          guid      = Guid.NewGuid();
            const string name      = "Initial Aggregate Name ";
            var          aggregate = new TestAggregate(guid, String.Empty);

            aggregate.ChangeName(name + 1);
            aggregate.ChangeName(name + 2);
            aggregate.ChangeName(name + 1);
            aggregate.ChangeName(name + 3);

            repository.Save(aggregate, -1);

            repository.GetById(guid).ReturnNameForTest().Should().Be(name + 3);
        }
Beispiel #4
0
        protected override void Because()
        {
            var commitId = Guid.NewGuid();

            _repository.Save(_testAggregate, commitId, null);

            _testAggregate.ChangeName("one");

            _repository.Save(_testAggregate, commitId);
        }
        public void RepositorySaveShouldInitiateEventHandlersToUpdateReadModel()
        {
            EventBus   eventBus;
            EventStore eventStore;
            var        repository = EnvironmentMock.CreateEnvironment <TestAggregate>(out eventBus, out eventStore);

            var          guid      = Guid.NewGuid();
            const string name      = "Initial Aggregate Name";
            var          aggregate = new TestAggregate(guid, String.Empty);

            aggregate.ChangeName(name);

            repository.Save(aggregate, -1);

            TestDatabase.Items[guid].Name.Should().Be(name);
        }
        public void RepositorySaveShouldMarkAllAggregateChangesAsCommitted()
        {
            EventBus   eventBus;
            EventStore eventStore;
            var        repository = EnvironmentMock.CreateEnvironment <TestAggregate>(out eventBus, out eventStore);

            var          guid      = Guid.NewGuid();
            const string name      = "Initial Aggregate Name";
            var          aggregate = new TestAggregate(guid, String.Empty);

            aggregate.ChangeName(name);

            repository.Save(aggregate, -1);

            repository.GetById(guid).HasPendingChanges().Should().Be(false);
        }