Example #1
0
        public void oob_no_define_throws()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, null);

            Assert.Throws <InvalidOperationException>(
                () => stream.AddOob(new FakeEvent(), "test", new Dictionary <string, string>()));
        }
Example #2
0
        public void version_with_snapshot()
        {
            var memento = new Moq.Mock <IMemento>();

            memento.Setup(x => x.EntityId).Returns("test");

            var snapshot = new Moq.Mock <ISnapshot>();

            snapshot.Setup(x => x.Version).Returns(1);
            snapshot.Setup(x => x.Payload).Returns(memento.Object);

            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, snapshot.Object);

            Assert.AreEqual(1, stream.StreamVersion);
            Assert.AreEqual(1, stream.CommitVersion);

            stream.Add(new FakeEvent(), new Dictionary <string, string>());

            Assert.AreEqual(2, stream.StreamVersion);
            Assert.AreEqual(1, stream.CommitVersion);

            var uncommitted = stream.Uncommitted.First();

            Assert.AreEqual(2, uncommitted.Descriptor.Version);
        }
Example #3
0
        public void oob_uncomitted()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, null);

            stream.DefineOob("test");
            stream.AddOob(new FakeEvent(), "test", new Dictionary <string, string>());

            Assert.AreEqual(1, stream.Uncommitted.Count());
        }
Example #4
0
        public void dirty_check()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, null);

            Assert.False(stream.Dirty);

            stream.Add(new FakeEvent(), new Dictionary <string, string>());

            Assert.True(stream.Dirty);
        }
Example #5
0
        public void multiple_define_oob()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, null);

            Assert.AreEqual(0, stream.Oobs.Count());
            Assert.AreEqual(0, stream.PendingOobs.Count());

            stream.DefineOob("test");
            stream.DefineOob("test");

            Assert.AreEqual(1, stream.PendingOobs.Count());
        }
Example #6
0
        public void new_stream_version()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, null, null);

            Assert.AreEqual(-1, stream.CommitVersion);
            Assert.AreEqual(-1, stream.StreamVersion);

            stream.Add(new FakeEvent(), new Dictionary <string, string>());

            Assert.AreEqual(-1, stream.CommitVersion);
            Assert.AreEqual(0, stream.StreamVersion);

            var uncommitted = stream.Uncommitted.First();

            Assert.AreEqual(0, uncommitted.Descriptor.Version);
        }
Example #7
0
        public void current_memento()
        {
            var memento = new Moq.Mock <IMemento>();

            memento.Setup(x => x.EntityId).Returns("test");

            var snapshot = new Moq.Mock <ISnapshot>();

            snapshot.Setup(x => x.Version).Returns(1);
            snapshot.Setup(x => x.Payload).Returns(memento.Object);

            // _events contains 1 event
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, snapshot.Object);

            Assert.AreEqual(1, stream.StreamVersion);

            Assert.AreEqual(new Id("test"), stream.Snapshot.Payload.EntityId);
        }
Example #8
0
        public void clone_has_important_info()
        {
            var memento = new Moq.Mock <IMemento>();

            memento.Setup(x => x.EntityId).Returns("test");

            var snapshot = new Moq.Mock <ISnapshot>();

            snapshot.Setup(x => x.Version).Returns(1);
            snapshot.Setup(x => x.Payload).Returns(memento.Object);

            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, snapshot.Object);

            var clone = stream.Clone();

            Assert.AreEqual("test", clone.Bucket);
            Assert.AreEqual(new Id("test"), clone.StreamId);

            Assert.AreEqual(stream.CommitVersion, clone.CommitVersion);
            Assert.AreEqual(stream.Snapshot.Payload, clone.Snapshot.Payload);
        }
Example #9
0
        public void total_uncomitted()
        {
            var stream = new Aggregates.Internal.EventStream <Entity>("test", "test", null, null, _events, null);

            Assert.AreEqual(0, stream.TotalUncommitted);

            stream.Add(new FakeEvent(), new Dictionary <string, string>());

            Assert.AreEqual(1, stream.TotalUncommitted);

            stream.DefineOob("test");
            stream.AddOob(new FakeEvent(), "test", new Dictionary <string, string>());

            Assert.AreEqual(2, stream.TotalUncommitted);

            var memento = new Moq.Mock <IMemento>();

            stream.AddSnapshot(memento.Object);

            Assert.AreEqual(3, stream.TotalUncommitted);
        }