Beispiel #1
0
        public async Task takes_snapshot()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            // Delayes conflicting events to be resolved later
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_store.Object, _eventstore.Object, _channel.Object, streamGen);

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

            var entity = new Entity(_stream.Object, _resolver.Object);

            entity.TakeASnapshot = true;

            await resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary <string, string>())
            .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);

            _store.Verify(x => x.WriteStream <Entity>(Moq.It.IsAny <Guid>(), Moq.It.IsAny <IEventStream>(),
                                                      Moq.It.IsAny <IDictionary <string, string> >()), Moq.Times.Once);
        }
Beispiel #2
0
        public Task takes_snapshot()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            // Delayes conflicting events to be resolved later
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_snapstore.Object, _eventstore.Object, _channel.Object, streamGen);

            var entity = new FakeEntity();

            (entity as IEntity <FakeState>).Instantiate(new FakeState());
            entity.State.TakeASnapshot = true;

            return(Task.CompletedTask);
            //await resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary<string, string>())
            //    .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);

            //_store.Verify(x => x.WriteStream<Entity>(Moq.It.IsAny<Guid>(), Moq.It.IsAny<IEventStream>(),
            //    Moq.It.IsAny<IDictionary<string, string>>()), Moq.Times.Once);
        }
Beispiel #3
0
        public void dont_catch_abandon_resolution()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            // Delayes conflicting events to be resolved later
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_store.Object, _eventstore.Object, _channel.Object, streamGen);

            var entity = new Entity(_stream.Object, _resolver.Object);

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

            Assert.ThrowsAsync <AbandonConflictException>(
                () => resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary <string, string>()));
        }
Beispiel #4
0
        public void no_route_exception()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            // Delayes conflicting events to be resolved later
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_snapstore.Object, _eventstore.Object, _channel.Object, streamGen);

            var entity = new FakeEntity();

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

            //Assert.ThrowsAsync<ConflictResolutionFailedException>(
            //    () => resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary<string, string>()));
        }
Beispiel #5
0
        public Task oob_events_not_conflict_resolved()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            _event.Setup(x => x.Descriptor.Headers[Defaults.OobHeaderKey]).Returns("test");
            _event.Setup(x => x.Descriptor.StreamType).Returns(StreamTypes.OOB);

            // Runs all conflicting events back through a re-hydrated entity
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_snapstore.Object, _eventstore.Object, _channel.Object, streamGen);

            var entity = new FakeEntity();

            return(Task.CompletedTask);
            //await resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary<string, string>())
            //    .ConfigureAwait(false);

            //Assert.AreEqual(0, entity.Conflicts);

            //_stream.Verify(x => x.AddOob(Moq.It.IsAny<IEvent>(), "test", Moq.It.IsAny<IDictionary<string, string>>()),
            //    Moq.Times.Once);
        }
Beispiel #6
0
        public async Task conflict_no_resolve()
        {
            var streamGen = new StreamIdGenerator((type, stream, bucket, id, parents) => "test");

            _channel.Setup(x => x.Age(Moq.It.IsAny <string>(), Moq.It.IsAny <string>()))
            .Returns(Task.FromResult((TimeSpan?)TimeSpan.FromSeconds(1)));

            // Delays conflicting events to be resolved later
            var resolver = new Aggregates.Internal.ResolveWeaklyConflictResolver(_store.Object, _eventstore.Object, _channel.Object, streamGen);

            var entity = new Entity(_stream.Object, _resolver.Object);

            await resolver.Resolve(entity, new[] { _event.Object }, Guid.NewGuid(), new Dictionary <string, string>())
            .ConfigureAwait(false);

            Assert.AreEqual(0, entity.Conflicts);

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

            _store.Verify(x => x.WriteStream <Entity>(Moq.It.IsAny <Guid>(), Moq.It.IsAny <IEventStream>(),
                                                      Moq.It.IsAny <IDictionary <string, string> >()), Moq.Times.Never);
        }