public void Notify()
        {
            var file = Path.GetTempFileName();

            File.Delete(file);

            var info      = new FileInfo(file);
            var scheduler = new TestScheduler();

            FileNotification result = null;

            using (info.WatchFile(TimeSpan.FromSeconds(1), scheduler).Subscribe(x => result = x))
            {
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);

                File.AppendAllLines(file, Enumerable.Range(1, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Created);
                result.NotificationType.Should().NotBe(0);

                File.AppendAllLines(file, Enumerable.Range(11, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Changed);

                File.Delete(file);
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);
            }
        }
        public void Notify()
        {
            var file = Path.GetTempFileName();
            File.Delete(file);

            var info = new FileInfo(file);
            var scheduler = new TestScheduler();

            FileNotification result = null;

            using (info.WatchFile(TimeSpan.FromSeconds(1), scheduler).Subscribe(x => result = x))
            {
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);

                File.AppendAllLines(file, Enumerable.Range(1, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Created);
                result.NotificationType.Should().NotBe(0);

                File.AppendAllLines(file, Enumerable.Range(11, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Changed);

                File.Delete(file);
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);
            }
        }
Exemple #3
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);
                }
            }
        }
        public void AutoTailWithFilter()
        {
            var file = Path.GetTempFileName();
            var info = new FileInfo(file);
            var scheduler = new TestScheduler();
            var textMatch = Observable.Return("odd");
            var autoTailer = Observable.Return(new ScrollRequest(10));

            File.AppendAllLines(file, Enumerable.Range(1, 100)
                .Select(i => i%2 == 1 ? $"{i} is an odd number" : $"{i} is an even number").ToArray());

            using (var tailer = new FileTailer(info, textMatch, autoTailer, 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.AppendAllLines(file, 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);

                File.Delete(file);
                tailer.Lines.Items.Select(l => l.Text).ShouldAllBeEquivalentTo(expectedLines);
            }
        }
Exemple #5
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);
                }
            }
        }
        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))
            {

                scheduler.AdvanceBySeconds(1);
                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 WillNotApplyFilterWhenTextIsLessThan3Character()
        {
            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"
                int[] expectedLines = Enumerable.Range(91, 10)
                    .Select(i => i.ToString())
                    .Select(int.Parse)
                    .ToArray();

                scheduler.AdvanceBySeconds(1);

                tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(expectedLines);

                File.Delete(file);
                tailer.Lines.Items.Select(l => l.Number).ShouldAllBeEquivalentTo(expectedLines);
            }
        }