コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        //[Fact]
        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);
                }
            }
        }
コード例 #4
0
        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);
                }
        }
コード例 #5
0
        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);
                    }
                }
            }
        }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
0
        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);
                    }
                }
            }
        }
コード例 #8
0
        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);
                    }
                }
            }
        }
コード例 #9
0
        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);
                    }
                }
            }
        }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
 public void OpenFile()
 {
     using (var file = new TestFile())
     {
         file.Append("testLine");
         new FileOpenViewModel(null).FileAndDirectoryValidator(file.Info.FullName).Select(f => f.FullName).First().Should().Be(file.Info.FullName);
     }
 }
コード例 #13
0
 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 });
     }
 }
コード例 #14
0
        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 });
            }


        }
コード例 #15
0
        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));
                }
            }
        }
コード例 #16
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);
            }
        }
コード例 #17
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);
                }
        }
コード例 #18
0
        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);
                }
            }
        }
コード例 #19
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);
                }
            }
        }
コード例 #20
0
        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);
                }
            }
        }
コード例 #21
0
        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);
                }
            }
        }
コード例 #22
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);
                }
            }
        }
コード例 #23
0
        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);
                }
            }
        }
コード例 #24
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);
                }
            }
        }
コード例 #25
0
        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);
                    }
                }
            }

        }
コード例 #26
0
        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);
                    }
                }
            }
        }