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); }
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)); }
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)); }
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); }
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); }