public async Task command_handler_should_pass_if_modified_since_check_is_ok()
        {
            SampleAggregate aggregate = await CreateAndSaveAggregate().ConfigureAwait(false);

            var cmd          = new TouchSampleAggregate(new SampleAggregateId(1));
            var startVersion = aggregate.Version;

            cmd.SetContextData(MessagesConstants.IfVersionEqualsTo, startVersion.ToString());

            await _sut.HandleAsync(cmd).ConfigureAwait(false);

            Assert.That(_sut.Aggregate.Version, Is.EqualTo(startVersion + 1));
        }
        public async Task command_handler_should_throw_if_modified_since_check_fails()
        {
            SampleAggregate aggregate = await CreateAndSaveAggregate().ConfigureAwait(false);

            var cmd = new TouchSampleAggregate(new SampleAggregateId(1));

            cmd.SetContextData(MessagesConstants.IfVersionEqualsTo, aggregate.Version.ToString());

            //now simulate another change of the entity
            aggregate.Touch();
            await _repositoryEx.SaveAsync(aggregate, Guid.NewGuid().ToString(), null).ConfigureAwait(false);

            Assert.ThrowsAsync <AggregateModifiedException>(async() => await _sut.HandleAsync(cmd).ConfigureAwait(false));
        }
예제 #3
0
        public void repository_command_handler_should_set_context()
        {
            var cmd = new TouchSampleAggregate(new SampleAggregateId(1));

            cmd.SetContextData("key", "value");
            IRepositoryExFactory factory = NSubstitute.Substitute.For <IRepositoryExFactory>();

            factory.Create().Returns(_sut);
            var handler = new TouchSampleAggregateHandler
            {
                Repository       = _sut,
                AggregateFactory = _aggregateFactory,
                AggregateCachedRepositoryFactory = new AggregateCachedRepositoryFactory(factory)
            };

            handler.Handle(cmd);

            var context = handler.Aggregate.ExposeContext;

            Assert.NotNull(context);
            Assert.AreEqual("TouchSampleAggregate", context["command.name"]);
            Assert.AreEqual("value", context["key"]);
        }