예제 #1
0
        public async Task EventStore_GetByIdObjectAsyncShouldReturnNullIfEvenContainsAndInvalidAggregateType()
        {
            var event1 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = "SomeRandomAggregateRoot", CreatedOn = DateTime.UtcNow.AddMinutes(-5), Id = Guid.Empty, SerializedEvent = "{}" };
            var event2 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = "SomeRandomAggregateRoot", CreatedOn = DateTime.UtcNow.AddMinutes(-4), Id = Guid.Empty, SerializedEvent = "{}" };
            var event3 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = "SomeRandomAggregateRoot", CreatedOn = DateTime.UtcNow.AddMinutes(-3), Id = Guid.Empty, SerializedEvent = "{}" };

            var repo = new Mock<IRepository<AggregateEvent>>();
            repo.Setup(x => x.GetAsync())
                .Returns(Task.FromResult<IQueryable<AggregateEvent>>(
                new List<AggregateEvent>()
                {
                    event1, event2, event3
                }.AsQueryable()))
                .Verifiable();

            var serializationStrategy = new Mock<ISerializationStrategy>();
            serializationStrategy.Setup(x => x.Deserialize("{}", typeof(TestEvent)))
                .Returns(new TestEvent()).Verifiable();
            var aggregateBus = new Mock<IAggregateBus>();

            EventStore.Instance.Configure(repo.Object, serializationStrategy.Object, aggregateBus.Object);

            var result = await EventStore.Instance.GetByIdAsync(Guid.Empty);

            result.Should().BeNull();

            repo.Verify(x => x.GetAsync(), Times.Exactly(1));
            serializationStrategy.Verify(x => x.Deserialize("{}", typeof(TestEvent)), Times.Never);

        }
예제 #2
0
        public void EventStore_GetByIdObjectAsyncShouldThrowExceptionIfNoAcceptableApplyEventMethodIsFound()
        {
            var event1 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregateRoot).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-5), Id = Guid.Empty, SerializedEvent = "{}" };
            var event2 = new AggregateEvent() { EventType = typeof(TestEvent2).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregateRoot).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-4), Id = Guid.Empty, SerializedEvent = "{}" };

            var repo = new Mock<IRepository<AggregateEvent>>();
            repo.Setup(x => x.GetAsync())
                .Returns(Task.FromResult<IQueryable<AggregateEvent>>(
                new List<AggregateEvent>()
                {
                    event1, event2
                }.AsQueryable()))
                .Verifiable();

            var serializationStrategy = new Mock<ISerializationStrategy>();
            serializationStrategy.Setup(x => x.Deserialize("{}", typeof(TestEvent)))
                .Returns(new TestEvent()).Verifiable();
            serializationStrategy.Setup(x => x.Deserialize("{}", typeof(TestEvent2)))
                .Returns(new TestEvent2()).Verifiable();
            var aggregateBus = new Mock<IAggregateBus>();

            EventStore.Instance.Configure(repo.Object, serializationStrategy.Object, aggregateBus.Object);

            EventStore.Instance.Awaiting(x => x.GetByIdAsync(Guid.Empty))
                .ShouldThrow<NotImplementedException>();


            repo.Verify(x => x.GetAsync(), Times.Exactly(2));
            serializationStrategy.Verify(x => x.Deserialize("{}", typeof(TestEvent)), Times.Once);
            serializationStrategy.Verify(x => x.Deserialize("{}", typeof(TestEvent2)), Times.Once);

        }
예제 #3
0
        public async Task EventStore_LatestEventTimestampAsyncShouldUseTheRepoAndReturnDateTimeMinIfNoEventsAreFound()
        {
            var event1 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregate).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-5), Id = Guid.Empty, SerializedEvent = "{}" };
            var event2 = new AggregateEvent() { EventType = typeof(TestEvent2).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregate).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-4), Id = Guid.Empty, SerializedEvent = "{}" };
            var event3 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregate).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-3), Id = Guid.Empty, SerializedEvent = "{}" };

            var repo = new Mock<IRepository<AggregateEvent>>();
            repo.Setup(x => x.GetAsync())
                .Returns(Task.FromResult<IQueryable<AggregateEvent>>(
                new List<AggregateEvent>()
                {
                    event1, event2, event3
                }.AsQueryable()))
                .Verifiable();

            var serializationStrategy = new Mock<ISerializationStrategy>();
            var aggregateBus = new Mock<IAggregateBus>();

            EventStore.Instance.Configure(repo.Object, serializationStrategy.Object, aggregateBus.Object);

            var result = await EventStore.Instance.LatestEventTimestampAsync(Guid.NewGuid());

            result.Should().Be(DateTime.MinValue);

            repo.Verify(x => x.GetAsync(), Times.Once);
        }
예제 #4
0
        public async Task EventStore_GetByIdObjectAsyncShouldReturnDefaultTForNoEvents()
        {
            var event1 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregateRoot).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-5), Id = Guid.Empty, SerializedEvent = "{}" };
            var event2 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregateRoot).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-4), Id = Guid.Empty, SerializedEvent = "{}" };
            var event3 = new AggregateEvent() { EventType = typeof(TestEvent).AssemblyQualifiedName, AggregateId = Guid.Empty, AggregateIdType = typeof(Guid).ToString(), AggregateType = typeof(TestAggregateRoot).AssemblyQualifiedName, CreatedOn = DateTime.UtcNow.AddMinutes(-3), Id = Guid.Empty, SerializedEvent = "{}" };

            var repo = new Mock<IRepository<AggregateEvent>>();
            repo.Setup(x => x.GetAsync())
                .Returns(Task.FromResult<IQueryable<AggregateEvent>>(
                new List<AggregateEvent>()
                {
                    event1, event2, event3
                }.AsQueryable()))
                .Verifiable();

            var serializationStrategy = new Mock<ISerializationStrategy>();
            serializationStrategy.Setup(x => x.Deserialize("{}", typeof(TestEvent)))
                .Returns(new TestEvent()).Verifiable();
            var aggregateBus = new Mock<IAggregateBus>();

            EventStore.Instance.Configure(repo.Object, serializationStrategy.Object, aggregateBus.Object);

            var result = await EventStore.Instance.GetByIdAsync(Guid.Empty);

            result.Should().NotBeNull();
            result.Should().BeOfType(typeof(TestAggregateRoot));
            var aggregateRoot = result as TestAggregateRoot;
            aggregateRoot.Should().NotBeNull();
            aggregateRoot.WasApplyEventCalled.Should().BeTrue();

            repo.Verify(x => x.GetAsync(), Times.Exactly(2));
            serializationStrategy.Verify(x => x.Deserialize("{}", typeof(TestEvent)), Times.Exactly(3));

        }
예제 #5
0
        public async Task EventStore_SaveAsyncShouldUseTheRepo()
        {
            var @event = new AggregateEvent();
            var repo = new Mock<IRepository<AggregateEvent>>();
            repo.Setup(x => x.SaveAsync(@event)).Returns(Task.FromResult<object>(null)).Verifiable();
            var serializationStrategy = new Mock<ISerializationStrategy>();
            var aggregateBus = new Mock<IAggregateBus>();

            EventStore.Instance.Configure(repo.Object, serializationStrategy.Object, aggregateBus.Object);

            await EventStore.Instance.SaveAsync(@event);

            repo.Verify(x => x.SaveAsync(@event), Times.Once);
        }