Beispiel #1
0
        public void multi_apply_double()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            reified.Apply(1U, 10);
            reified.Apply(1U, 10);
        }
Beispiel #2
0
        public void multi_initial()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            Assert.AreEqual((uint)0U, (uint)reified.Sequence);
            Assert.AreEqual((int)0, (int)reified.Current.I.Value);
            Assert.AreEqual("I", reified.Current.S);
        }
Beispiel #3
0
        public void multi_apply()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            reified.Apply(1U, 10);

            Assert.AreEqual((uint)1U, (uint)reified.Sequence);
            Assert.AreEqual((int)10, (int)reified.Current.I.Value);
            Assert.AreEqual("I(10:1)", reified.Current.S);
        }
Beispiel #4
0
        public void multi_apply_reset()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            reified.Apply(1U, 10);

            Assert.NotNull(reified.Current);

            reified.Reset();

            Assert.Equal(0U, reified.Sequence);
            Assert.Equal(0, reified.Current.I.Value);
            Assert.Equal("I", reified.Current.S);
        }
Beispiel #5
0
        public void multi_apply_double()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            try
            {
                reified.Apply(1U, 10);
                reified.Apply(1U, 10);
                Assert.True(false);
            }
            catch (ArgumentException)
            {
                ;
            }
        }
Beispiel #6
0
        public void multi_apply_twice()
        {
            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                MockString().Object
            });

            var oldcount = State.Creations;

            reified.Apply(1U, 10);
            reified.Apply(4U, 14);

            Assert.AreEqual((uint)4U, (uint)reified.Sequence);
            Assert.AreEqual(oldcount, State.Creations);
            Assert.AreEqual((int)24, (int)reified.Current.I.Value);
            Assert.AreEqual(oldcount + 1, State.Creations);
            Assert.AreEqual("I(10:1)(14:4)", reified.Current.S);
            Assert.AreEqual(oldcount + 1, State.Creations);
        }
Beispiel #7
0
        public async Task multi_apply_separate()
        {
            var cache = new Mock <IProjectionCacheProvider>();

            ReturnsExtensions.ReturnsAsync(cache.Setup(c => c.OpenReadAsync("string")), new MemoryStream(new byte[]
            {
                0x02, 0x00, 0x00, 0x00,     // Current position (beginning)
                0x30, 0x30, 0x30, 0x30,     // Event data "0000"
                0x02, 0x00, 0x00, 0x00      // Current position (end)
            }));

            var str = MockString();

            str.Setup(p => p.TryLoadAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Returns <Stream, CancellationToken>((s, c) =>
            {
                var bytes = new byte[4];
                s.Read(bytes, 0, 4);
                return(Task.FromResult(Encoding.UTF8.GetString(bytes)));
            });

            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                str.Object
            }, cache.Object);

            await reified.TryLoadAsync(CancellationToken.None);

            reified.Apply(1U, 10);
            reified.Apply(4U, 14);

            Assert.AreEqual((uint)4U, (uint)reified.Sequence);
            Assert.AreEqual((int)24, (int)reified.Current.I.Value);
            Assert.AreEqual("0000(14:4)", reified.Current.S);
        }
Beispiel #8
0
        public async Task multi_apply_separate()
        {
            var cache = new Testing.InMemoryCache {
                { "string", new byte[]
                  {
                      0x02, 0x00, 0x00, 0x00, // Current position (beginning)
                      0x30, 0x30, 0x30, 0x30, // Event data "0000"
                      0x02, 0x00, 0x00, 0x00  // Current position (end)
                  } }
            };

            var str = MockString();

            str.Setup(p => p.TryLoadAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Returns <Stream, CancellationToken>((s, c) =>
            {
                var bytes = new byte[4];
                s.Read(bytes, 0, 4);
                return(Task.FromResult(Encoding.UTF8.GetString(bytes)));
            });

            var reified = new ReifiedProjectionGroup <int, State>(new IProjection <int>[]
            {
                MockInteger().Object,
                str.Object
            }, cache);

            await reified.TryLoadAsync(CancellationToken.None);

            reified.Apply(1U, 10);
            reified.Apply(4U, 14);

            Assert.Equal(4U, reified.Sequence);
            Assert.Equal(24, reified.Current.I.Value);
            Assert.Equal("0000(14:4)", reified.Current.S);
        }
Beispiel #9
0
 internal EventStreamWrapper(IStorageDriver storage, IEnumerable <IProjection <TEvent> > projections, IProjectionCacheProvider projectionCache, ILogAdapter log = null)
 {
     _log        = log;
     Stream      = new EventStream <TEvent>(storage, log);
     _projection = new ReifiedProjectionGroup <TEvent, TState>(projections, projectionCache, log);
 }