Exemplo n.º 1
0
        public async Task handles_child_entity()
        {
            var child = new Child(_stream.Object, _resolver.Object);

            var repo = new Moq.Mock <IRepository <Entity, Child> >();

            repo.Setup(x => x.Get(Moq.It.IsAny <Id>())).Returns(Task.FromResult(child));
            _uow.Setup(x => x.For <Entity, Child>(Moq.It.IsAny <Entity>())).Returns(repo.Object);

            var handler = new HandleConflictingEvents(_uow.Object);

            var conflict = new ConflictingEvents
            {
                EntityType = typeof(Child).AssemblyQualifiedName,
                Parents    = new Tuple <string, Id>[] { new Tuple <string, Id>(typeof(Entity).AssemblyQualifiedName, "test") },
                Events     = new[] { _event.Object }
            };

            await handler.Handle(conflict, new Moq.Mock <IMessageHandlerContext>().Object).ConfigureAwait(false);

            Assert.AreEqual(1, child.Conflicts);

            _stream.Verify(x => x.Add(Moq.It.IsAny <IEvent>(), Moq.It.IsAny <IDictionary <string, string> >()),
                           Moq.Times.Once);
        }
Exemplo n.º 2
0
        public void no_route_exception()
        {
            var handler = new HandleConflictingEvents(_uow.Object);

            _resolver.Setup(x => x.Conflict(Moq.It.IsAny <Entity>(), typeof(Event))).Throws <NoRouteException>();

            Assert.ThrowsAsync <ConflictResolutionFailedException>(
                () => handler.Handle(_conflicting, new Moq.Mock <IMessageHandlerContext>().Object));
        }
Exemplo n.º 3
0
        public void dont_catch_abandon_resolution()
        {
            var handler = new HandleConflictingEvents(_uow.Object);

            _resolver.Setup(x => x.Conflict(Moq.It.IsAny <Entity>(), typeof(Event))).Throws <AbandonConflictException>();

            Assert.ThrowsAsync <AbandonConflictException>(
                () => handler.Handle(_conflicting, new Moq.Mock <IMessageHandlerContext>().Object));
        }
Exemplo n.º 4
0
        public async Task handle_conflicting_message()
        {
            var handler = new HandleConflictingEvents(_uow.Object);

            await handler.Handle(_conflicting, new Moq.Mock <IMessageHandlerContext>().Object).ConfigureAwait(false);

            Assert.AreEqual(1, _entity.Conflicts);

            _stream.Verify(x => x.Add(Moq.It.IsAny <IEvent>(), Moq.It.IsAny <IDictionary <string, string> >()),
                           Moq.Times.Once);
        }
Exemplo n.º 5
0
        public async Task takes_snapshot()
        {
            var handler = new HandleConflictingEvents(_uow.Object);

            _stream.Setup(x => x.AddSnapshot(Moq.It.IsAny <IMemento>()));
            _stream.Setup(x => x.StreamVersion).Returns(0);
            _stream.Setup(x => x.CommitVersion).Returns(1);

            _entity.TakeASnapshot = true;

            await handler.Handle(_conflicting, new Moq.Mock <IMessageHandlerContext>().Object)
            .ConfigureAwait(false);

            Assert.AreEqual(1, _entity.Conflicts);

            _stream.Verify(x => x.Add(Moq.It.IsAny <IEvent>(), Moq.It.IsAny <IDictionary <string, string> >()),
                           Moq.Times.Once);

            _stream.Verify(x => x.AddSnapshot(Moq.It.IsAny <IMemento>()), Moq.Times.Once);
        }