public void HeaderRegexMatchesPartOfAMessage_Forward() { var capt = new TextMessageCapture(); ITextAccess ta = Substitute.For <ITextAccess>(); ITextAccessIterator it = Substitute.For <ITextAccessIterator>(); ta.AverageBufferLength.Returns(100); ta.MaximumSequentialAdvancesAllowed.Returns(3); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"ab(c)?", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow); ta.OpenIterator(0, TextAccessDirection.Forward).Returns(it); it.PositionToCharIndex(0).Returns(0); it.CurrentBuffer.Returns("ab"); it.Advance(0).Returns(_ => { it.CurrentBuffer.Returns("abc_"); it.CharIndexToPosition(0).Returns((long)0); return(true); }); target.BeginSplittingSession(new Range(0, 10), 0, MessagesParserDirection.Forward); Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(3).Returns(false); it.CharIndexToPosition(4).Returns((long)3); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.MessageHeader); Assert.AreEqual("_", capt.MessageBody); Assert.IsTrue(target.CurrentMessageIsEmpty); }
public void FirstTextBufferIsEmpty_Backward() { var capt = new TextMessageCapture(); int aveBufSize = 100; ITextAccess ta = Substitute.For <ITextAccess>(); ITextAccessIterator it = Substitute.For <ITextAccessIterator>(); ta.MaximumSequentialAdvancesAllowed.Returns(3); ta.AverageBufferLength.Returns(aveBufSize); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow); // _abc // || | // pos: 11| 15 // 12 ta.OpenIterator(15, TextAccessDirection.Forward).Returns(it); it.CurrentBuffer.Returns(""); it.PositionToCharIndex(15).Returns(0); // querying past-the end position is allowed it.Advance(0).Returns(_ => { it.CurrentBuffer.Returns("_abc"); it.CharIndexToPosition(1).Returns((long)12); return(true); }); target.BeginSplittingSession(new Range(10, 20), 15, MessagesParserDirection.Forward); Assert.IsFalse(target.CurrentMessageIsEmpty); }
public void HeaderRegexMatchesPartOfAMessage_Forward() { MockRepository repo = new MockRepository(); var capt = new TextMessageCapture(); ITextAccess ta = repo.CreateMock <ITextAccess>(); ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>(); Expect.Call(ta.AverageBufferLength).Return(100); Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3); repo.ReplayAll(); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"ab(c)?", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow); repo.VerifyAll(); repo.BackToRecordAll(); Expect.Call(ta.OpenIterator(0, TextAccessDirection.Forward)).Return(it); Expect.Call(it.PositionToCharIndex(0)).Return(0); Expect.Call(it.CurrentBuffer).Return("ab"); Expect.Call(it.Advance(0)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return("abc_"); Expect.Call(it.CharIndexToPosition(0)).Return((long)0); repo.Replay(it); return(true); }); repo.ReplayAll(); target.BeginSplittingSession(new Range(0, 10), 0, MessagesParserDirection.Forward); repo.VerifyAll(); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(3)).Return(false); Expect.Call(it.CharIndexToPosition(4)).Return((long)3); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.MessageHeader); Assert.AreEqual("_", capt.MessageBody); Assert.IsTrue(target.CurrentMessageIsEmpty); }
static IEnumerable <Checkpoint> EnumCheckpoints( ITextAccessIterator tai, PlainTextMatcher matcher, ProgressAndCancellation progressAndCancellation, LJTraceSource trace) { var advanceTime = new Stopwatch(); long advancesCount = 0; var matchingTime = new Stopwatch(); long matchCount = 0; for (;;) { StringSlice buf = new StringSlice(tai.CurrentBuffer); for (int startIdx = 0; ;) { matchingTime.Start(); var match = matcher.Match(buf, startIdx); matchingTime.Stop(); ++matchCount; if (!match.HasValue) { break; } yield return(new Checkpoint() { Position = tai.CharIndexToPosition(match.Value.MatchBegin), EndPosition = tai.CharIndexToPosition(match.Value.MatchEnd), IsMatch = true }); startIdx = match.Value.MatchEnd; progressAndCancellation.CheckTextIterationCancellation(); } advanceTime.Start(); bool stop = !tai.Advance(Math.Max(0, tai.CurrentBuffer.Length - matcher.MaxMatchLength)); advanceTime.Stop(); ++advancesCount; if (stop) { break; } yield return(new Checkpoint() { EndPosition = tai.CharIndexToPosition(0), IsMatch = false }); progressAndCancellation.CheckTextIterationCancellation(); } trace.Info("Stats: text buffer matching time: {0} ({1} times)", matchingTime.Elapsed, matchCount); trace.Info("Stats: text buffer advance time: {0}/{1}={2}", advanceTime.Elapsed, advancesCount, TimeSpan.FromTicks(advanceTime.ElapsedTicks / Math.Max(1, advancesCount))); }
public async Task MessageIsReadBecauseItEndsRightAfterTheBeginningOfTheRange_Backward() { // reading from position 11 with range 5-15 // _msg1_msg2_msg3 // | | | | // 1 5 11 15 // range begins at pos 5. msg1_ ends at pos 6 (its past-the-end position = 6). msg1_ must be read. ITextAccess ta = Substitute.For <ITextAccess>(); ITextAccessIterator it = Substitute.For <ITextAccessIterator>(); ta.MaximumSequentialAdvancesAllowed.Returns(3); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"msg", ReOptions.None)); ta.OpenIterator(11, TextAccessDirection.Backward).Returns(it); it.PositionToCharIndex(11).Returns(11); it.CharIndexToPosition(6).Returns((long)6); it.CurrentBuffer.Returns("_msg1_msg2_msg3"); await target.BeginSplittingSession(new Range(5, 15), 11, MessagesParserDirection.Backward); Assert.IsFalse(target.CurrentMessageIsEmpty); it.CharIndexToPosition(11).Returns((long)11); it.CharIndexToPosition(1).Returns((long)1); var capt = new TextMessageCapture(); Assert.IsTrue(await target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("msg", capt.MessageHeader); Assert.AreEqual("2_", capt.MessageBody); Assert.AreEqual(6L, capt.BeginPosition); Assert.AreEqual(11L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); // in backward mode the first message that was read is "IsLastMessage" Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(9).Returns(_ => { it.CurrentBuffer.Returns("_msg1_"); return(trueTask); }); Assert.IsTrue(await target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("msg", capt.MessageHeader); Assert.AreEqual("1_", capt.MessageBody); Assert.AreEqual(1L, capt.BeginPosition); Assert.AreEqual(6L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); Assert.IsFalse(await target.GetCurrentMessageAndMoveToNextOne(capt)); }
public void FirstTextBufferIsEmpty_Backward() { MockRepository repo = new MockRepository(); var capt = new TextMessageCapture(); int aveBufSize = 100; ITextAccess ta = repo.CreateMock <ITextAccess>(); ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>(); Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3); Expect.Call(ta.AverageBufferLength).Return(aveBufSize); repo.ReplayAll(); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None), MessagesSplitterFlags.PreventBufferUnderflow); repo.VerifyAll(); // _abc // || | // pos: 11| 15 // 12 repo.BackToRecordAll(); Expect.Call(ta.OpenIterator(15, TextAccessDirection.Forward)).Return(it); Expect.Call(it.CurrentBuffer).Return(""); Expect.Call(it.PositionToCharIndex(15)).Return(0); // querying past-the end position is allowed Expect.Call(it.Advance(0)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return("_abc"); Expect.Call(it.CharIndexToPosition(1)).Return((long)12); repo.Replay(it); return(true); }); repo.ReplayAll(); target.BeginSplittingSession(new Range(10, 20), 15, MessagesParserDirection.Forward); repo.VerifyAll(); Assert.IsFalse(target.CurrentMessageIsEmpty); }
public void GetCurrentMessageAndMoveToNextOne_MainScenario_Backward() { ITextAccess ta = Substitute.For <ITextAccess>(); ITextAccessIterator it = Substitute.For <ITextAccessIterator>(); ta.MaximumSequentialAdvancesAllowed.Returns(3); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None)); ta.OpenIterator(100, TextAccessDirection.Backward).Returns(it); it.PositionToCharIndex(100).Returns(29); it.CurrentBuffer.Returns( "123456 abc 283147948 abc 3498"); // | | | | | | // 0 7 10 21 24 29 - char idx // 50 61 67 85 87 100 - position it.CharIndexToPosition(21).Returns((long)85); target.BeginSplittingSession(new Range(0, 100), 100, MessagesParserDirection.Backward); Assert.IsFalse(target.CurrentMessageIsEmpty); it.CharIndexToPosition(7).Returns((long)61); it.CharIndexToPosition(29).Returns((long)100); var capt = new TextMessageCapture(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 3498", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(85L, capt.BeginPosition); Assert.AreEqual(100L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(8).Returns(_ => { it.CurrentBuffer.Returns( "11 abc 123456 abc 283147948 "); // | | | | | | // 0 3 6 14 17 27 - char idx // 20 33 50 61 67 85 - positions it.CharIndexToPosition(3).Returns((long)33); return(true); }); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(61L, capt.BeginPosition); Assert.AreEqual(85L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(14).Returns(_ => { it.CurrentBuffer.Returns( "11 abc 123456 "); // | | | | // 0 3 6 13 - char idx // 20 33 61 - pos return(true); }); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 123456 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(33L, capt.BeginPosition); Assert.AreEqual(61L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.IsTrue(target.CurrentMessageIsEmpty); target.EndSplittingSession(); it.Received(1).Dispose(); }
public void GetCurrentMessageAndMoveToNextOne_MainScenario_Forward() { ITextAccess ta = Substitute.For <ITextAccess>(); ITextAccessIterator it = Substitute.For <ITextAccessIterator>(); ta.MaximumSequentialAdvancesAllowed.Returns(3); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None)); ta.OpenIterator(0, TextAccessDirection.Forward).Returns(it); it.PositionToCharIndex(0).Returns(0); it.CurrentBuffer.Returns( "123456 abc 283147948 abc 3498"); // | | | | | | // 0 7 10 21 24 28 - char idx // 0 8 16 45 56 67 - positions it.CharIndexToPosition(7).Returns((long)8); target.BeginSplittingSession(new Range(0, 100), 0, MessagesParserDirection.Forward); Assert.IsFalse(target.CurrentMessageIsEmpty); it.CharIndexToPosition(21).Returns((long)45); var capt = new TextMessageCapture(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(8L, capt.BeginPosition); Assert.AreEqual(45L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(24).Returns(_ => { it.CurrentBuffer.Returns( " 3498 abc 2626277"); // | | | // 0 6 9 - char idx // 56 72 81 - position it.CharIndexToPosition(6).Returns((long)72); return(true); }); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 3498 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(45L, capt.BeginPosition); Assert.AreEqual(72L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); it.Advance(9).Returns(_ => { it.CurrentBuffer.Returns( " 2626277"); // | | // 0 8 - char idx // 81 90 - position it.CharIndexToPosition(8).Returns((long)90); return(true); }); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 2626277", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(72L, capt.BeginPosition); Assert.AreEqual(90L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt)); Assert.IsTrue(target.CurrentMessageIsEmpty); target.EndSplittingSession(); it.Received(1).Dispose(); }
public void MessageIsReadBecauseItEndsRightAfterTheBeginningOfTheRange_Backward() { MockRepository repo = new MockRepository(); // reading from position 11 with range 5-15 // _msg1_msg2_msg3 // | | | | // 1 5 11 15 // range begins at pos 5. msg1_ ends at pos 6 (its past-the-end position = 6). msg1_ must be read. ITextAccess ta = repo.CreateMock <ITextAccess>(); ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>(); Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3); repo.ReplayAll(); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"msg", ReOptions.None)); repo.VerifyAll(); repo.BackToRecordAll(); Expect.Call(ta.OpenIterator(11, TextAccessDirection.Backward)).Return(it); Expect.Call(it.PositionToCharIndex(11)).Return(11); Expect.Call(it.CharIndexToPosition(6)).Return((long)6); Expect.Call(it.CurrentBuffer).Return("_msg1_msg2_msg3"); repo.ReplayAll(); target.BeginSplittingSession(new Range(5, 15), 11, MessagesParserDirection.Backward); repo.VerifyAll(); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.CharIndexToPosition(11)).Return((long)11); Expect.Call(it.CharIndexToPosition(1)).Return((long)1); repo.ReplayAll(); var capt = new TextMessageCapture(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("msg", capt.MessageHeader); Assert.AreEqual("2_", capt.MessageBody); Assert.AreEqual(6L, capt.BeginPosition); Assert.AreEqual(11L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); // in backward mode the first message that was read is "IsLastMessage" Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(9)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return("_msg1_"); repo.Replay(it); return(true); }); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("msg", capt.MessageHeader); Assert.AreEqual("1_", capt.MessageBody); Assert.AreEqual(1L, capt.BeginPosition); Assert.AreEqual(6L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); repo.ReplayAll(); Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); }
public void GetCurrentMessageAndMoveToNextOne_MainScenario_Forward() { MockRepository repo = new MockRepository(); ITextAccess ta = repo.CreateMock <ITextAccess>(); ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>(); Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3); repo.ReplayAll(); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None)); repo.VerifyAll(); repo.BackToRecordAll(); Expect.Call(ta.OpenIterator(0, TextAccessDirection.Forward)).Return(it); Expect.Call(it.PositionToCharIndex(0)).Return(0); Expect.Call(it.CurrentBuffer).Return( "123456 abc 283147948 abc 3498"); // | | | | | | // 0 7 10 21 24 28 - char idx // 0 8 16 45 56 67 - positions Expect.Call(it.CharIndexToPosition(7)).Return((long)8); repo.ReplayAll(); target.BeginSplittingSession(new Range(0, 100), 0, MessagesParserDirection.Forward); repo.VerifyAll(); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.CharIndexToPosition(21)).Return((long)45); repo.ReplayAll(); var capt = new TextMessageCapture(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(8L, capt.BeginPosition); Assert.AreEqual(45L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(24)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return( " 3498 abc 2626277"); // | | | // 0 6 9 - char idx // 56 72 81 - position Expect.Call(it.CharIndexToPosition(6)).Return((long)72); repo.Replay(it); return(true); }); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 3498 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(45L, capt.BeginPosition); Assert.AreEqual(72L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(9)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return( " 2626277"); // | | // 0 8 - char idx // 81 90 - position Expect.Call(it.CharIndexToPosition(8)).Return((long)90); repo.Replay(it); return(true); }); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 2626277", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(72L, capt.BeginPosition); Assert.AreEqual(90L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); repo.ReplayAll(); Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.IsTrue(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); it.Dispose(); Expect.On(it); repo.ReplayAll(); target.EndSplittingSession(); repo.VerifyAll(); }
public void GetCurrentMessageAndMoveToNextOne_MainScenario_Backward() { MockRepository repo = new MockRepository(); ITextAccess ta = repo.CreateMock <ITextAccess>(); ITextAccessIterator it = repo.CreateMock <ITextAccessIterator>(); repo.BackToRecordAll(); Expect.Call(ta.MaximumSequentialAdvancesAllowed).Return(3); repo.ReplayAll(); MessagesSplitter target = new MessagesSplitter(ta, reFactory.Create(@"abc", ReOptions.None)); repo.VerifyAll(); repo.BackToRecordAll(); Expect.Call(ta.OpenIterator(100, TextAccessDirection.Backward)).Return(it); Expect.Call(it.PositionToCharIndex(100)).Return(29); Expect.Call(it.CurrentBuffer).Return( "123456 abc 283147948 abc 3498"); // | | | | | | // 0 7 10 21 24 29 - char idx // 50 61 67 85 87 100 - position Expect.Call(it.CharIndexToPosition(21)).Return((long)85); repo.ReplayAll(); target.BeginSplittingSession(new Range(0, 100), 100, MessagesParserDirection.Backward); repo.VerifyAll(); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.CharIndexToPosition(7)).Return((long)61); Expect.Call(it.CharIndexToPosition(29)).Return((long)100); repo.ReplayAll(); var capt = new TextMessageCapture(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 3498", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(85L, capt.BeginPosition); Assert.AreEqual(100L, capt.EndPosition); Assert.IsTrue(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(8)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return( "11 abc 123456 abc 283147948 "); // | | | | | | // 0 3 6 14 17 27 - char idx // 20 33 50 61 67 85 - positions Expect.Call(it.CharIndexToPosition(3)).Return((long)33); repo.Replay(it); return(true); }); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 283147948 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(61L, capt.BeginPosition); Assert.AreEqual(85L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsFalse(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); Expect.Call(it.Advance(14)).Repeat.Once().Do((Predicate <int>) delegate(int i) { repo.Verify(it); repo.BackToRecord(it); Expect.Call(it.CurrentBuffer).Return( "11 abc 123456 "); // | | | | // 0 3 6 13 - char idx // 20 33 61 - pos repo.Replay(it); return(true); }); repo.ReplayAll(); Assert.IsTrue(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.AreEqual("abc", capt.HeaderBuffer.Substring(capt.HeaderMatch.Index, capt.HeaderMatch.Length)); Assert.AreEqual(" 123456 ", capt.BodyBuffer.Substring(capt.BodyIndex, capt.BodyLength)); Assert.AreEqual(33L, capt.BeginPosition); Assert.AreEqual(61L, capt.EndPosition); Assert.IsFalse(capt.IsLastMessage); Assert.IsTrue(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); repo.ReplayAll(); Assert.IsFalse(target.GetCurrentMessageAndMoveToNextOne(capt)); repo.VerifyAll(); Assert.IsTrue(target.CurrentMessageIsEmpty); repo.BackToRecordAll(); it.Dispose(); Expect.On(it); repo.ReplayAll(); target.EndSplittingSession(); repo.VerifyAll(); }