public async Task should_have_no_events_after_save()
        {
            // GIVEN
            var aggregateRoot = SampleAggregateRoot.Create(Guid.NewGuid(), "some text", -1);

            // WHEN
            await _sut.Save(aggregateRoot);

            // THEN
            aggregateRoot.HasChanges.Should().BeFalse();
        }
        should_give_concurrency_exception_when_trying_to_save_an_aggregate_root_with_non_initial_version_and_no_version_in_db()
        {
            // GIVEN
            var id            = Guid.NewGuid();
            var aggregateRoot = SampleAggregateRoot.Create(id, "some text", 12);

            // WHEN
            Func <Task> action = async() => await _sut.Save(aggregateRoot);

            // THEN
            action.Should().Throw <ConcurrencyException>();
        }
        public async Task should_give_concurrency_exception_when_trying_to_save_events_on_old_aggregate_root()
        {
            // GIVEN
            var id            = Guid.NewGuid();
            var aggregateRoot = SampleAggregateRoot.Create(id, "some text", -1);
            await _sut.Save(aggregateRoot);

            var sameAggregateRoot = SampleAggregateRoot.Create(id, "some text", 1);

            // WHEN
            Func <Task> action = async() => await _sut.Save(sameAggregateRoot);

            // THEN
            action.Should().Throw <ConcurrencyException>();
        }
        public async Task should_save_correctly_with_one_event()
        {
            // GIVEN
            var id = Guid.NewGuid();

            var aggregateRoot = SampleAggregateRoot.Create(id, "some text", -1);

            // WHEN
            await _sut.Save(aggregateRoot);

            // THEN
            var loadedAggregateRoot = await _sut.Get <SampleAggregateRoot>(id);

            loadedAggregateRoot.Id.Should().Be(id);
            loadedAggregateRoot.Text.Should().Be("some text");
        }
        public async Task should_save_correctly_with_multiple_events()
        {
            // GIVEN
            var id = Guid.NewGuid();

            var aggregateRoot = SampleAggregateRoot.Create(id, "some text", -1);

            aggregateRoot.ChangeText("text 1");
            aggregateRoot.ChangeText("text 2");
            aggregateRoot.ChangeText("text 3");
            aggregateRoot.ClearText();
            aggregateRoot.ChangeText("final text");

            // WHEN
            await _sut.Save(aggregateRoot);

            // THEN
            var loadedAggregateRoot = await _sut.Get <SampleAggregateRoot>(id);

            loadedAggregateRoot.Id.Should().Be(id);
            loadedAggregateRoot.Text.Should().Be("final text");
        }
示例#6
0
        public void Execute(ICommandContext context, SampleCommand command)
        {
            var root = context.GetAggregateRoot(command.AggregateId, () => SampleAggregateRoot.Register(command));

            root.Create(command);
        }
示例#7
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public PagerListTest()
 {
     _list = new PagerList <SampleAggregateRoot>(1, 2, 3, "Name");
     _list.Add(SampleAggregateRoot.CreateSample());
     _list.Add(SampleAggregateRoot.CreateSample2());
 }