public void WillCheckPreviousPage() { var scheduler = new TestScheduler(); using (var file = new TestFile()) { file.Append(Enumerable.Range(1, 20).Select(i => i.ToString()).ToArray()); ILineProvider lineProvider = null; using (file.Info.Index(scheduler).Exclude(str => str.Contains("9")).Subscribe(x => lineProvider = x)) { scheduler.AdvanceByMilliSeconds(250); lineProvider.Count.Should().Be(20); var lines = lineProvider.ReadLines(new ScrollRequest(10)).AsArray(); lines.Count().Should().Be(9); var expected = Enumerable.Range(1, 20) .Select(i => i.ToString()) .Where(str => !str.Contains("9")) .Reverse() .Take(10); //slines.Select(line => line.Text).Should().BeEquivalentTo(expected); } } }
public void CanReadIndiciesBack_SmallFile() { var pulse = new Subject<Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { file.Append(Enumerable.Range(1, 100).Select(i => $"This is line number {i.ToString("00000000")}").ToArray()); using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), scheduler: scheduler)) { IndexCollection result = null; using (indexer.Result.Subscribe(indicies => result = indicies)) { pulse.Once(); var head = result.ReadLines(new ScrollRequest(10, 0)); var headText = head.Select(l => l.Text).ToArray(); var headExpected = Enumerable.Range(1, 10).Select(i => $"This is line number {i.ToString("00000000")}"); headText.ShouldAllBeEquivalentTo(headExpected); var tail = result.ReadLines(new ScrollRequest(10)); var tailText = tail.Select(l => l.Text).ToArray(); var tailExpected = Enumerable.Range(91, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray(); tailText.ShouldAllBeEquivalentTo(tailExpected); var mid = result.ReadLines(new ScrollRequest(10, 20)); var midText = mid.Select(l => l.Text).ToArray(); var midExpected = Enumerable.Range(21, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray(); midText.ShouldAllBeEquivalentTo(midExpected); } } } }
public void SkipFirstLine() { var firstLine = "This is the first line"; var secondLine = "This is the second line"; var startPosition = (firstLine + Environment.NewLine).Length; FileNotification result = null; var scheduler = new TestScheduler(); using (var file = new TestFile()) using (file.Info .WatchFile(scheduler: scheduler) .ScanFrom(startPosition, scheduler: scheduler) .Subscribe(x => result = x)) { file.Append(firstLine); file.Append(secondLine); scheduler.AdvanceByMilliSeconds(1000); var lines = File.ReadAllLines(result.FullName).ToArray(); lines.Should().HaveCount(1); lines.Single().Should().Be(secondLine); } }
public void ReadSpecificFileLines() { using (var file=new TestFile()) { file.Append(Enumerable.Range(1, 100).Select(i => i.ToString())); var lines = file.Info.ReadLines(new[] { 1, 2, 3, 10, 100, 105 }); lines.Select(l => l.Number).ShouldAllBeEquivalentTo(new[] { 1, 2, 3, 10, 100 }); } }
public void AutoTailWithFilter() { var scheduler = new TestScheduler(); var autoTailer = Observable.Return(new ScrollRequest(10)); Func<string, bool> predicate = s => s.Contains("odd"); using (var file = new TestFile()) { file.Append(Enumerable.Range(1, 100).Select(i => i%2 == 1 ? $"{i} is an odd number" : $"{i} is an even number").ToArray()); var search = file.Info.Search(predicate, scheduler); using (var tailer = new LineScroller(file.Info, search, autoTailer, new NullLogger(), scheduler)) { //lines which contain "1" var expectedLines = Enumerable.Range(1, 100) .Select(i => i%2 == 1 ? $"{i} is an odd number" : $"{i} is an even number") .Where(s => s.Contains("odd")) .Reverse() .Take(10) .Reverse() .ToArray(); scheduler.AdvanceBySeconds(1); tailer.Lines.Items.Select(l => l.Text).ShouldAllBeEquivalentTo(expectedLines); file.Append( Enumerable.Range(101, 10).Select(i => i%2 == 1 ? $"{i} is an odd number" : $"{i} is an even number").ToArray()); scheduler.AdvanceBySeconds(1); expectedLines = Enumerable.Range(1, 110) .Select(i => i%2 == 1 ? $"{i} is an odd number" : $"{i} is an even number") .Where(s => s.Contains("odd")) .Reverse() .Take(10) .Reverse() .ToArray(); scheduler.AdvanceBySeconds(1); tailer.Lines.Items.Select(l => l.Text).ShouldAllBeEquivalentTo(expectedLines); } } }
public void NotExistingFile() { var pulse = new Subject<Unit>(); using (var file = new TestFile()) { file.Delete(); FileSearchResult fileSearchResult = null; using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9")) .Subscribe(x => fileSearchResult = x)) { fileSearchResult.Should().BeNull(); } } }
public void EmptyForEmptyFile() { FileNotification result = null; var scheduler = new TestScheduler(); using (var file = new TestFile()) using (file.Info .WatchFile(scheduler: scheduler) .ScanFrom(0, scheduler: scheduler) .Subscribe(x => result = x)) { scheduler.AdvanceByMilliSeconds(1000); var lines = File.ReadAllLines(result.FullName).ToArray(); lines.Should().HaveCount(0); } }
//[Fact] //Cannot recreate the file as something is hanging on to it. public void CreateFileLater() { var pulse = new Subject <Unit>(); using (var file = new TestFile()) { file.Delete(); FileSearchResult fileSearchResult = null; using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9")) .Subscribe(x => fileSearchResult = x)) { fileSearchResult.Should().Be(FileSearchResult.None); file.Create(); pulse.Once(); fileSearchResult.Should().NotBe(FileSearchResult.None); } } }
public void AutoTail() { var scheduler = new TestScheduler(); var textMatch = Observable.Return(FileSearchResult.None); var autoTailer = Observable.Return(new ScrollRequest(10)); using (var file = new TestFile()) { file.Append( Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); using (var tailer = new FileTailer(file.Info, textMatch, autoTailer, new NullLogger(), scheduler)) { scheduler.AdvanceByMilliSeconds(250); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(91, 10)); file.Append( Enumerable.Range(101, 10).Select(i => i.ToString())); scheduler.AdvanceByMilliSeconds(250); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(101, 10)); } } }
//[Fact] //Cannot recreate the file as something is hanging on to it. public void CreateFileLater() { var pulse = new Subject<Unit>(); using (var file = new TestFile()) { file.Delete(); FileSearchResult fileSearchResult = null; using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9")) .Subscribe(x => fileSearchResult = x)) { fileSearchResult.Should().Be(FileSearchResult.None); file.Create(); pulse.Once(); fileSearchResult.Should().NotBe(FileSearchResult.None); } } }
public void EmptyFile() { var pulse = new Subject<Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { FileSearchResult fileSearchResult = null; using (file.Info .Search(str => str.Contains("9"), scheduler) .Subscribe(x => fileSearchResult = x)) { scheduler.AdvanceByMilliSeconds(250); pulse.Once(); fileSearchResult.Segments.Should().Be(1); fileSearchResult.SegmentsCompleted.Should().Be(0); fileSearchResult.IsSearching.Should().Be(false); fileSearchResult.Count.Should().Be(0); } } }
public void EmptyFile() { var pulse = new Subject <Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { FileSearchResult fileSearchResult = null; using (file.Info .Search(str => str.Contains("9"), scheduler) .Subscribe(x => fileSearchResult = x)) { scheduler.AdvanceByMilliSeconds(250); pulse.Once(); fileSearchResult.Segments.Should().Be(1); fileSearchResult.SegmentsCompleted.Should().Be(0); fileSearchResult.IsSearching.Should().Be(false); fileSearchResult.Count.Should().Be(0); } } }
public void StartAfterEndOfFileShouldReturnNothing() { FileNotification result = null; var scheduler = new TestScheduler(); using (var file = new TestFile()) using (file.Info .WatchFile(scheduler: scheduler) .ScanFrom(10000, scheduler: scheduler) .Subscribe(x => result = x)) { file.Append("A"); file.Append("B"); file.Append("C"); scheduler.AdvanceByMilliSeconds(1000); var lines = File.ReadAllLines(result.FullName).ToArray(); lines.Should().HaveCount(0); } }
public void StartFromFirstPosition() { var firstLine = "This is the first line"; FileNotification result = null; var scheduler = new TestScheduler(); using (var file = new TestFile()) using (file.Info .WatchFile(scheduler: scheduler) .ScanFrom(0, scheduler: scheduler) .Subscribe(x => result = x)) { file.Append(firstLine); scheduler.AdvanceByMilliSeconds(1000); var lines = File.ReadAllLines(result.FullName).ToArray(); lines.Should().HaveCount(1); lines.Single().Should().Be(firstLine); } }
public void ExludedFilesAre() { var scheduler = new TestScheduler(); using (var file = new TestFile()) { file.Append(Enumerable.Range(1, 20).Select(i => i.ToString()).ToArray()); ILineProvider lineProvider = null; using (file.Info.Index(scheduler).Exclude(str => str.Contains("9")).Subscribe(x => lineProvider = x)) { scheduler.AdvanceByMilliSeconds(250); lineProvider.Count.Should().Be(20); var lines = lineProvider.ReadLines(new ScrollRequest(20, 0)).AsArray(); lines.Count().Should().Be(18); var expected = Enumerable.Range(1, 20).Select(i => i.ToString()).Where(str => !str.Contains("9")); lines.Select(line => line.Text).Should().BeEquivalentTo(expected); } } }
public void CanReadIndiciesBack_LargeFile() { var pulse = new Subject <Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { file.Append(Enumerable.Range(1, 10000).Select(i => $"This is line number {i.ToString("00000000")}").ToArray()); using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), tailSize: 1000, scheduler: scheduler)) { IndexCollection result = null; using (indexer.Result.Subscribe(indicies => result = indicies)) { //start off the head scanner scheduler.AdvanceBy(1); var head = result.ReadLines(new ScrollRequest(10, 0)); var headText = head.Select(l => l.Text).ToArray(); var headExpected = Enumerable.Range(1, 10).Select(i => $"This is line number {i.ToString("00000000")}"); headText.ShouldAllBeEquivalentTo(headExpected); var tail = result.ReadLines(new ScrollRequest(10)); var tailText = tail.Select(l => l.Text).ToArray(); var tailExpected = Enumerable.Range(9991, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray(); tailText.ShouldAllBeEquivalentTo(tailExpected); var mid = result.ReadLines(new ScrollRequest(10, 100)); var midText = mid.Select(l => l.Text).ToArray(); var midExpected = Enumerable.Range(101, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray(); midText.ShouldAllBeEquivalentTo(midExpected); } } } }
public void WillAutoTail() { var pulse = new Subject<Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), tailSize: 1000, scheduler: scheduler)) { file.Append(Enumerable.Range(1, 10000) .Select(i => $"This is line number {i.ToString("00000000")}") .ToArray()); pulse.Once(); IndexCollection result = null; using (indexer.Result.Subscribe(indicies => result = indicies)) { scheduler.AdvanceBy(1); result.Count.Should().Be(10000); file.Append(Enumerable.Range(10001, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray()); pulse.OnNext(Unit.Default); result.Count.Should().Be(10010); } } } }
public void SearchOnDataWhenFileIsPopulated() { var pulse = new Subject<Unit>(); using (var file = new TestFile()) { FileSearchResult fileSearchResult = null; using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9")) .Subscribe(x => fileSearchResult = x)) { file.Append(Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); pulse.Once(); pulse.Once(); fileSearchResult.Matches.Length.Should().NotBe(0); } } }
public void CanReadLinesBackInLargeFile() { var scheduler = new TestScheduler(); var pulse = new Subject<Unit>(); using (var file = new TestFile()) { IEnumerable<Line> lines = null; file.Append(Enumerable.Range(1, 100000).Select(i => i.ToString()).ToArray()); using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9"), scheduler) .Select(result => file.Info.ReadLinesByPosition(result.Matches).ToArray()) .Subscribe(x => lines=x)) { pulse.Once(); // fileSearchResult.Matches.Length.Should().Be(19); file.Append(new[] { "9", "20" }); pulse.Once(); // fileSearchResult.Matches.Length.Should().Be(20); file.Append(new[] { "9999" }); pulse.Once(); // fileSearchResult.Matches.Length.Should().Be(21); } } }
public void WillContinuallyTail() { var scheduler = new TestScheduler(); var pulse = new Subject<Unit>(); using (var file = new TestFile()) { FileSearchResult fileSearchResult = null; file.Append(Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); using (file.Info.WatchFile(pulse) .Search(str => str.Contains("9"), scheduler) .Subscribe(x => fileSearchResult = x)) { pulse.Once(); fileSearchResult.Matches.Length.Should().Be(19); file.Append(new [] {"9","20"}); pulse.Once(); fileSearchResult.Matches.Length.Should().Be(20); file.Append(new[] { "9999" }); pulse.Once(); fileSearchResult.Matches.Length.Should().Be(21); } } }
public void InitiallyEmptyThenLinesAdded() { var scheduler = new TestScheduler(); using (var file = new TestFile()) { FileSearchResult fileSearchResult = null; using (file.Info.WatchFile(scheduler:scheduler) .Search(str => str.Contains("9")) .Subscribe(x => fileSearchResult = x)) { scheduler.AdvanceBy(1); file.Append(Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); scheduler.AdvanceByMilliSeconds(250); fileSearchResult.Matches.Length.Should().Be(19); } } }
public void CanProduceIndices() { var pulse = new Subject<Unit>(); var scheduler = new TestScheduler(); using (var file = new TestFile()) { using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), tailSize: 1000, scheduler: scheduler)) { var lines = Enumerable.Range(1, 10000) .Select(i => $"This is line number {i.ToString("00000000")}") .ToArray(); file.Append(lines); // scheduler.AdvanceBy(1); pulse.Once(); IndexCollection result = null; using (indexer.Result.Subscribe(indicies => result = indicies)) { //start off the head scanner scheduler.AdvanceBy(1); var totalCount = result.Count; //there could be an overlapping index (the index collection will deal with this) totalCount.Should().Be(10000); } } } }
public void CopyTestFileToDirectory(TestFile testFile) { File.Copy(Path.Combine(testFile.Info.Directory.FullName, testFile.Info.Name), Path.Combine(FullName, testFile.Info.Name)); }