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()); }
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); }
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); }
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); }
/// <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); }
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); }