예제 #1
0
        public async Task GetAggregateAsync_should_applychanges_from_events_history()
        {
            await _eventStore.SaveDomainEventsAsync(new List <DomainEvent>()
            {
                new DomainEvent()
                {
                    Id          = ObjectId.GenerateNewId(),
                    AggregateId = _aggregateId,
                    Commit      = 1,
                    Index       = 1,
                    Type        = "AnotherTestEvent",
                    Version     = 1,
                    Json        = @"{""firstname"":""Jones"",""surname"":""Smith"", ""isvalid"": true}"
                },
                new DomainEvent()
                {
                    Id          = ObjectId.GenerateNewId(),
                    AggregateId = _aggregateId,
                    Commit      = 2,
                    Index       = 2,
                    Type        = "TestEvent",
                    Version     = 1,
                    Json        = @"{""city"":""Hemel Hempstead"",""isCaptured"":false}"
                },
                new DomainEvent()
                {
                    Id          = ObjectId.GenerateNewId(),
                    AggregateId = "some-fake-id",
                    Commit      = 3,
                    Index       = 3,
                    Type        = "TestEvent",
                    Version     = 1,
                    Json        = @"{""city"":""London"",""isCaptured"":true}"
                }
            });

            var aggregate = await _aggregateRepository.GetAggregateAsync(_aggregateId);

            Assert.That(aggregate, Is.Not.Null);
            Assert.That(aggregate.Index, Is.EqualTo(2));
            Assert.That(aggregate.Commit, Is.EqualTo(2));
            Assert.That(aggregate.ReappliedEvents.Count, Is.EqualTo(2));
            Assert.That(aggregate.ReappliedEvents[0], Is.TypeOf <AnotherTestEventV1>());
            Assert.That(aggregate.ReappliedEvents[1], Is.TypeOf <TestEventV1>());
        }