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 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 CanStreamFile() { var file = Path.GetTempFileName(); var info = new FileInfo(file); int[] result=new int[0]; var scheduler = new TestScheduler(); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i => $"{i}").ToArray()); using (info.WatchFile(TimeSpan.FromMilliseconds(1), scheduler).Index().Subscribe(x => result = x.Lines.Select((_,idx)=>idx+1).ToArray())) { scheduler.AdvanceByMilliSeconds(1); result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 100)); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => $"{i}")); scheduler.AdvanceByMilliSeconds(1); File.Delete(file); result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 110)); } }
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)); } } }
public void AutoTailWithFilter() { var file = Path.GetTempFileName(); var info = new FileInfo(file); var scheduler = new TestScheduler(); var textMatch = Observable.Return((string)"1"); var autoTailer = Observable.Return(new ScrollRequest(10)); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); using (var tailer = new FileTailer(info, textMatch, autoTailer, scheduler)) { //lines which contain "1" var expectedLines = Enumerable.Range(1, 100) .Select(i => i.ToString()) .Where(s => s.Contains("1")) .Reverse() .Take(10) .Reverse() .Select(int.Parse) .ToArray(); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(expectedLines); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => i.ToString())); //lines which contain "1" expectedLines = Enumerable.Range(1, 110) .Select(i => i.ToString()) .Where(s => s.Contains("1")) .Reverse() .Take(10) .Reverse() .Select(int.Parse) .ToArray(); scheduler.AdvanceByMilliSeconds(250); File.Delete(file); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(expectedLines); } }
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); } }
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 CanStreamFile() { var file = Path.GetTempFileName(); var info = new FileInfo(file); int[] result = new int[0]; var scheduler = new TestScheduler(); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i => $"{i}").ToArray()); using (info.WatchFile(scheduler: scheduler).ScanFile().Subscribe(x => result = x.MatchingLines.Select(l => l.Line).ToArray())) { result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 100)); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => $"{i}")); scheduler.AdvanceByMilliSeconds(250); File.Delete(file); result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 110)); } }
public void CanStreamFileWithPredicate() { var file = Path.GetTempFileName(); var info = new FileInfo(file); int[] result = new int[0]; var scheduler = new TestScheduler(); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i => $"{i}").ToArray()); //filter by odd numbers using (info.WatchFile(scheduler: scheduler).ScanFile(l=>int.Parse(l) % 2 == 1).Subscribe(x => result = x.MatchingLines.Select(l=>l.Line).ToArray())) { result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 100).Where(i=>i % 2 == 1)); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => $"{i}")); scheduler.AdvanceByMilliSeconds(250); File.Delete(file); result.ShouldAllBeEquivalentTo(Enumerable.Range(1, 110).Where(i => i % 2 == 1)); } }
public void AutoTail() { var file = Path.GetTempFileName(); var info = new FileInfo(file); var scheduler = new TestScheduler(); var textMatch = Observable.Return((string)null); var autoTailer = Observable.Return(new ScrollRequest(10)); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray()); using (var tailer = new FileTailer(info, textMatch, autoTailer, scheduler)) { tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(91, 10)); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => i.ToString())); scheduler.AdvanceByMilliSeconds(250); File.Delete(file); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(101, 10)); } }
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 AutoTail() { var file = Path.GetTempFileName(); var info = new FileInfo(file); var scheduler = new TestScheduler(); var textMatch = Observable.Return((string)null); var autoTailer = Observable.Return(new ScrollRequest(10)); File.AppendAllLines(file, Enumerable.Range(1, 100).Select(i =>i.ToString()).ToArray()); using (var tailer = new FileTailer(info, textMatch, autoTailer,scheduler)) { tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(91, 10)); File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => i.ToString())); scheduler.AdvanceByMilliSeconds(250); File.Delete(file); tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(Enumerable.Range(101, 10)); } }
public void EmptyTailedFiles() { var pulse = new Subject <Unit>(); var scheduler = new TestScheduler(); using (var files = new TestFileCollection()) { for (int i = 0; i < 10; i++) { files.Add(new TestFile()); } FileSearchResult fileSearchResult = null; var search = files.Select(t => t.Info.WatchFile(pulse)) .Merge() .Search(str => str.Contains("9"), scheduler); using (search.Subscribe(x => fileSearchResult = x)) { scheduler.AdvanceByMilliSeconds(250); pulse.Once(); var segments = 0; var segmentsCompleted = 0; var isSearchCompleted = true; var count = 0; while (fileSearchResult != null) { segments += fileSearchResult.Segments; segmentsCompleted += fileSearchResult.SegmentsCompleted; isSearchCompleted = isSearchCompleted && fileSearchResult.IsSearching; count += fileSearchResult.Count; fileSearchResult = fileSearchResult.Previous as FileSearchResult; } segments.Should().Be(10); segmentsCompleted.Should().Be(0); isSearchCompleted.Should().Be(false); 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 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 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); } } }