private static Guid SaveTestAggregateWithoutCustomHeaders(IRepository repository, int numberOfEvents)
 {
     var aggregateToSave = new TestAggregate(Guid.NewGuid());
     aggregateToSave.ProduceEvents(numberOfEvents);
     repository.Save(aggregateToSave, Guid.NewGuid(), d => { });
     return aggregateToSave.Id;
 }
Esempio n. 2
0
        public void SavesCommitHeadersOnEachEvent()
        {
            var commitId        = Guid.NewGuid();
            var aggregateToSave = new TestAggregate(Guid.NewGuid());

            aggregateToSave.ProduceEvents(20);
            _repo.Save(aggregateToSave, commitId, d => {
                d.Add("CustomHeader1", "CustomValue1");
                d.Add("CustomHeader2", "CustomValue2");
            });

            var read = _connection.ReadStreamEventsForward(string.Format("aggregate-{0}", aggregateToSave.Id), 1, 20, false);

            foreach (var serializedEvent in read.Events)
            {
                var parsedMetadata       = JObject.Parse(Encoding.UTF8.GetString(serializedEvent.OriginalEvent.Metadata));
                var deserializedCommitId = parsedMetadata.Property("CommitId").Value.ToObject <Guid>();
                Assert.AreEqual(commitId, deserializedCommitId);

                var deserializedCustomHeader1 = parsedMetadata.Property("CustomHeader1").Value.ToObject <string>();
                Assert.AreEqual("CustomValue1", deserializedCustomHeader1);

                var deserializedCustomHeader2 = parsedMetadata.Property("CustomHeader2").Value.ToObject <string>();
                Assert.AreEqual("CustomValue2", deserializedCustomHeader2);
            }
        }
        public void ClearsEventsFromAggregateOnceCommitted()
        {
            var aggregateToSave = new TestAggregate(Guid.NewGuid());
            aggregateToSave.ProduceEvents(10);
            _repo.Save(aggregateToSave, Guid.NewGuid(), d => { });

            Assert.AreEqual(0, ((IAggregate) aggregateToSave).GetUncommittedEvents().Count);
        }
        public void ClearsEventsFromAggregateOnceCommitted()
        {
            var aggregateToSave = new TestAggregate(Guid.NewGuid());
            aggregateToSave.ProduceEvents(10);
            _repo.Save(aggregateToSave, Guid.NewGuid(), d => { });

            Assert.AreEqual(0, ((IAggregate) aggregateToSave).GetUncommittedEvents().Count);
        }
 private static Guid SaveTestAggregateWithoutCustomHeaders(IRepository repository, int numberOfEvents)
 {
     var aggregateToSave = new TestAggregate(Guid.NewGuid());
     aggregateToSave.ProduceEvents(numberOfEvents);
     repository.Save(aggregateToSave, Guid.NewGuid(), d => { });
     return aggregateToSave.Id;
 }
        public void SavesCommitHeadersOnEachEvent()
        {
            var commitId = Guid.NewGuid();
            var aggregateToSave = new TestAggregate(Guid.NewGuid());
            aggregateToSave.ProduceEvents(20);
            _repo.Save(aggregateToSave, commitId, d => {
                d.Add("CustomHeader1", "CustomValue1");
                d.Add("CustomHeader2", "CustomValue2");
            });

            var read = _connection.ReadStreamEventsForward(string.Format("aggregate-{0}", aggregateToSave.Id), 1, 20, false);
            foreach (var serializedEvent in read.Events)
            {
                var parsedMetadata = JObject.Parse(Encoding.UTF8.GetString(serializedEvent.OriginalEvent.Metadata));
                var deserializedCommitId = parsedMetadata.Property("CommitId").Value.ToObject<Guid>();
                Assert.AreEqual(commitId, deserializedCommitId);

                var deserializedCustomHeader1 = parsedMetadata.Property("CustomHeader1").Value.ToObject<string>();
                Assert.AreEqual("CustomValue1", deserializedCustomHeader1);

                var deserializedCustomHeader2 = parsedMetadata.Property("CustomHeader2").Value.ToObject<string>();
                Assert.AreEqual("CustomValue2", deserializedCustomHeader2);
            }
        }