コード例 #1
0
        public void ShouldBeAbleToDetermineWhenTheLastItemHasBeenConsumed()
        {
            var items = new List <object> {
                1
            };
            var tokenizableStreamBase = new TokenizableStreamBase <object>(() => items);

            Assert.IsFalse(tokenizableStreamBase.IsAtEnd());
            tokenizableStreamBase.Consume();
            Assert.IsTrue(tokenizableStreamBase.IsAtEnd());
            tokenizableStreamBase.Consume();
            Assert.IsTrue(tokenizableStreamBase.IsAtEnd());
        }
コード例 #2
0
        public void ShouldConsumeTokensFromTheExtractor()
        {
            var items = new List <object> {
                1, 2, 3
            };
            var tokenizableStreamBase = new TokenizableStreamBase <object>(() => items);

            Assert.AreEqual(1, tokenizableStreamBase.Current);
            tokenizableStreamBase.Consume();
            Assert.AreEqual(2, tokenizableStreamBase.Current);
            tokenizableStreamBase.Consume();
            Assert.AreEqual(3, tokenizableStreamBase.Current);
        }
コード例 #3
0
        public void ShouldBeAbleToRollbackASnapshotAfterTheLastItemHasBeenConsumed()
        {
            var items = new List <object> {
                1, 2
            };
            var tokenizableStreamBase = new TokenizableStreamBase <object>(() => items);

            Assert.AreEqual(1, tokenizableStreamBase.Current);
            tokenizableStreamBase.TakeSnapshot();
            tokenizableStreamBase.Consume();
            tokenizableStreamBase.Consume();
            tokenizableStreamBase.Consume();
            Assert.IsTrue(tokenizableStreamBase.IsAtEnd());
            tokenizableStreamBase.RollbackSnapshot();
            Assert.AreEqual(1, tokenizableStreamBase.Current);
        }
コード例 #4
0
        public void ShouldReturnNullFromCurrentAfterLastItemHaseBeenConsumed()
        {
            var items = new List <object> {
                1
            };
            var tokenizableStreamBase = new TokenizableStreamBase <object>(() => items);

            Assert.IsNotNull(tokenizableStreamBase.Current);
            tokenizableStreamBase.Consume();
            Assert.IsNull(tokenizableStreamBase.Current);
        }
コード例 #5
0
        /// <summary>
        /// Gets all the tokens in the stream.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <returns>A list of tokens.</returns>
        public static List <TItem> GetAll <TItem>(this TokenizableStreamBase <TItem> tokens)
            where TItem : class
        {
            var list = new List <TItem>();

            while (!tokens.IsAtEnd())
            {
                list.Add(tokens.Current);
                tokens.Consume();
            }

            return(list);
        }
コード例 #6
0
        public void ShouldBeAbleToTakeASnapshot()
        {
            var items = new List <object> {
                1, 2
            };
            var tokenizableStreamBase = new TokenizableStreamBase <object>(() => items);

            Assert.AreEqual(1, tokenizableStreamBase.Current);
            tokenizableStreamBase.TakeSnapshot();
            Assert.AreEqual(1, tokenizableStreamBase.Current);
            tokenizableStreamBase.Consume();
            Assert.AreEqual(2, tokenizableStreamBase.Current);
        }