示例#1
0
        public void Shoud_be_able_to_save_the_same_instance_multiple_times()
        {
            var source = new TestEventSourced(42, "forty-two");

            repository.Save(source, Guid.NewGuid().ToString());

            source.UpdateNumber(44);

            repository.Save(source, Guid.NewGuid().ToString());
        }
示例#2
0
        public void Shoud_throw_concurrency_exception_when_there_was_an_attempt_to_save_changes_of_outdated_entity()
        {
            var source = new TestEventSourced(42, "forty-two");

            repository.Save(source, Guid.NewGuid().ToString());

            var source1 = repository.Get(source.Id);

            source1.UpdateNumber(43);

            repository.Save(source1, Guid.NewGuid().ToString());

            source.UpdateNumber(44);

            Action action = () => repository.Save(source, Guid.NewGuid().ToString());

            action.ShouldThrow <ConcurrencyException>()
            .Where(ex => ex.EntityId == source.Id && ex.EntityType == source.GetType().Name);
        }
示例#3
0
        public void Should_store_first_commit_with_events()
        {
            const string correlationId = "testcorrelation";

            var source = new TestEventSourced(42, "forty-two");

            source.UpdateNumber(43);
            source.UpdateText("forty-three");
            repository.Save(source, correlationId);

            var head = headsContainer.GetBlockBlobReference(source.Id.ToString());

            head.Exists().Should().BeTrue();

            Guid commitId;

            using (var stream = new MemoryStream())
            {
                head.DownloadToStream(stream);
                commitId = new Guid(stream.ToArray());
            }

            var commit = commitsContainer.GetBlockBlobReference(commitId.ToString());

            commit.Exists().Should().BeTrue();

            byte[] content;
            using (var stream = new MemoryStream())
            {
                commit.DownloadToStream(stream);
                content = stream.ToArray();
            }

            var events = (IEvent[])serializer.Deserialize(content);

            events.ShouldAllBeEquivalentTo(new IEvent[]
            {
                new TestEventCreated
                {
                    SourceId      = source.Id,
                    SourceVersion = 1,
                    Number        = 42,
                    Text          = "forty-two"
                },
                new TestEventNumber
                {
                    SourceId      = source.Id,
                    SourceVersion = 2,
                    Number        = 43
                },
                new TestEventText
                {
                    SourceId      = source.Id,
                    SourceVersion = 3,
                    Text          = "forty-three"
                },
            });
            commit.Metadata["SourceId"].Should().Be(source.Id.ToString());
            commit.Metadata["SourceType"].Should().Be(source.GetType().Name);
            commit.Metadata["CorrelationId"].Should().Be(correlationId);
            commit.Metadata["CommitId"].Should().NotBeEmpty();
            commit.Metadata.ContainsKey("ParentId").Should().BeFalse();
        }