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 Setup() { _snapstore = new Moq.Mock <IStoreSnapshots>(); _eventstore = new Moq.Mock <IStoreEvents>(); _channel = new Moq.Mock <IDelayedChannel>(); _delayedEvent = new Moq.Mock <IDelayedMessage>(); _state = new FakeState { Id = "test" }; _event = new Moq.Mock <IFullEvent>(); _event.Setup(x => x.Event).Returns(new FakeEvent()); _event.Setup(x => x.Descriptor.StreamType).Returns(StreamTypes.Domain); var conflictingEvent = new ConflictingEvents { Events = new[] { _event.Object } }; _delayedEvent.Setup(x => x.Message).Returns(conflictingEvent); _channel.Setup(x => x.Age(Moq.It.IsAny <string>(), Moq.It.IsAny <string>())) .Returns(Task.FromResult((TimeSpan?)TimeSpan.FromSeconds(60))); _channel.Setup(x => x.Pull(Moq.It.IsAny <string>(), Moq.It.IsAny <string>(), Moq.It.IsAny <int?>())) .Returns(Task.FromResult(new[] { _delayedEvent.Object }.AsEnumerable())); _eventstore.Setup(x => x.WriteEvents <FakeEntity>(Moq.It.IsAny <string>(), Moq.It.IsAny <Id>(), Moq.It.IsAny <Id[]>(), Moq.It.IsAny <IFullEvent[]>(), Moq.It.IsAny <IDictionary <string, string> >(), Moq.It.IsAny <long?>())) .Returns(Task.FromResult(0L)); }
public void Setup() { _uow = new Moq.Mock <IUnitOfWork>(); _stream = new Moq.Mock <IEventStream>(); _resolver = new Moq.Mock <IRouteResolver>(); _eventstore = new Moq.Mock <IStoreEvents>(); _store = new Moq.Mock <IStoreStreams>(); _channel = new Moq.Mock <IDelayedChannel>(); _resolver.Setup(x => x.Conflict(Moq.It.IsAny <Entity>(), typeof(Event))) .Returns((entity, e) => (entity as Entity).Conflict((IEvent)e)); _resolver.Setup(x => x.Resolve(Moq.It.IsAny <Entity>(), typeof(Event))) .Returns((entity, e) => (entity as Entity).Handle((IEvent)e)); _resolver.Setup(x => x.Conflict(Moq.It.IsAny <Child>(), typeof(Event))) .Returns((entity, e) => (entity as Child).Conflict((IEvent)e)); _resolver.Setup(x => x.Resolve(Moq.It.IsAny <Child>(), typeof(Event))) .Returns((entity, e) => (entity as Child).Handle((IEvent)e)); _stream.Setup(x => x.Add(Moq.It.IsAny <IEvent>(), Moq.It.IsAny <IDictionary <string, string> >())); _event = new Moq.Mock <IFullEvent>(); _event.Setup(x => x.Event).Returns(new Event()); _channel.Setup(x => x.Age(Moq.It.IsAny <string>(), Moq.It.IsAny <string>())) .Returns(Task.FromResult((TimeSpan?)TimeSpan.FromSeconds(60))); var repo = new Moq.Mock <IRepository <Entity> >(); _entity = new Entity(_stream.Object, _resolver.Object); repo.Setup(x => x.Get(Moq.It.IsAny <string>(), Moq.It.IsAny <Id>())).Returns(Task.FromResult(_entity)); _uow.Setup(x => x.For <Entity>()).Returns(repo.Object); _eventstore.Setup( x => x.WriteEvents("test", new[] { _event.Object }, Moq.It.IsAny <IDictionary <string, string> >(), null)) .Returns(Task.FromResult(0L)); _store.Setup(x => x.WriteStream <Entity>(Moq.It.IsAny <Guid>(), Moq.It.IsAny <IEventStream>(), Moq.It.IsAny <IDictionary <string, string> >())).Returns(Task.CompletedTask); _store.Setup(x => x.Freeze <Entity>(Moq.It.IsAny <IEventStream>())).Returns(Task.CompletedTask).Callback(() => _wasFrozen = true); _store.Setup(x => x.Unfreeze <Entity>(Moq.It.IsAny <IEventStream>())).Returns(Task.CompletedTask); _conflicting = new ConflictingEvents { EntityType = typeof(Entity).AssemblyQualifiedName, Parents = new Tuple <string, Id>[] { }, Events = new[] { _event.Object } }; }
public void Setup() { _stream = new Moq.Mock <IEventStream>(); _resolver = new Moq.Mock <IRouteResolver>(); _eventstore = new Moq.Mock <IStoreEvents>(); _store = new Moq.Mock <IStoreStreams>(); _channel = new Moq.Mock <IDelayedChannel>(); _delayedEvent = new Moq.Mock <IDelayedMessage>(); _resolver.Setup(x => x.Conflict(Moq.It.IsAny <Entity>(), typeof(Event))) .Returns((entity, e) => (entity as Entity).Conflict((IEvent)e)); _resolver.Setup(x => x.Resolve(Moq.It.IsAny <Entity>(), typeof(Event))) .Returns((entity, e) => (entity as Entity).Handle((IEvent)e)); _stream.Setup(x => x.Add(Moq.It.IsAny <IEvent>(), Moq.It.IsAny <IDictionary <string, string> >())); _event = new Moq.Mock <IFullEvent>(); _event.Setup(x => x.Event).Returns(new Event()); var conflictingEvent = new ConflictingEvents { Events = new[] { _event.Object } }; _delayedEvent.Setup(x => x.Message).Returns(conflictingEvent); _channel.Setup(x => x.Age(Moq.It.IsAny <string>(), Moq.It.IsAny <string>())) .Returns(Task.FromResult((TimeSpan?)TimeSpan.FromSeconds(60))); _channel.Setup(x => x.Pull(Moq.It.IsAny <string>(), Moq.It.IsAny <string>(), Moq.It.IsAny <int?>())) .Returns(Task.FromResult(new[] { _delayedEvent.Object }.AsEnumerable())); _eventstore.Setup( x => x.WriteEvents("test", new[] { _event.Object }, Moq.It.IsAny <IDictionary <string, string> >(), null)) .Returns(Task.FromResult(0L)); _store.Setup(x => x.WriteStream <Entity>(Moq.It.IsAny <Guid>(), Moq.It.IsAny <IEventStream>(), Moq.It.IsAny <IDictionary <string, string> >())).Returns(Task.CompletedTask); _store.Setup(x => x.Freeze <Entity>(Moq.It.IsAny <IEventStream>())).Returns(Task.CompletedTask).Callback(() => _wasFrozen = true); _store.Setup(x => x.Unfreeze <Entity>(Moq.It.IsAny <IEventStream>())).Returns(Task.CompletedTask); }