Exemplo n.º 1
0
 public void TestCtor2()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Verify(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()), Times.Once);
     }
 }
Exemplo n.º 2
0
 public void TestCount()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Setup(x => x.Count).Returns(42);
         proxy.Count.Should().Be(42);
         _logFile.Setup(x => x.Count).Returns(9001);
         proxy.Count.Should().Be(9001);
     }
 }
Exemplo n.º 3
0
        public void TestListen1()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
            {
                proxy.AddListener(_listener.Object, TimeSpan.FromSeconds(1), 1000);
                proxy.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1));

                _modifications.Property(x => x.Count).ShouldEventually().Be(2);
                _modifications.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 1)
                });
            }
        }
Exemplo n.º 4
0
        public void TestCtor1()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero))
            {
                proxy.InnerLogFile.Should().BeNull();
                proxy.MaxCharactersPerLine.Should().Be(0);
                proxy.Exists.Should().BeFalse();
                proxy.FileSize.Should().Be(Size.Zero);
                proxy.StartTimestamp.Should().NotHaveValue();
                proxy.Count.Should().Be(0);

                new Action(() => proxy.GetLine(0)).ShouldThrow<IndexOutOfRangeException>();
                new Action(() => proxy.GetSection(new LogFileSection(0, 1))).ShouldThrow<IndexOutOfRangeException>();
            }
        }
Exemplo n.º 5
0
        protected AbstractDataSource(ITaskScheduler taskScheduler, DataSource settings, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");
            if (settings == null) throw new ArgumentNullException("settings");
            if (settings.Id == Guid.Empty) throw new ArgumentException("settings.Id shall be set to an actually generated id");

            _taskScheduler = taskScheduler;
            _settings = settings;
            _maximumWaitTime = maximumWaitTime;
            _counter = new LogFileCounter();

            _logFile = new LogFileProxy(taskScheduler, maximumWaitTime);
            _search = new LogFileSearchProxy(taskScheduler, _logFile, maximumWaitTime);
            CreateSearch();
        }
Exemplo n.º 6
0
        public void TestDispose1()
        {
            var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero);
            _scheduler.PeriodicTaskCount.Should().Be(1);

            proxy.IsDisposed.Should().BeFalse();
            new Action(proxy.Dispose).ShouldNotThrow();
            proxy.IsDisposed.Should().BeTrue();
            _scheduler.PeriodicTaskCount.Should().Be(0);
        }
Exemplo n.º 7
0
 public void TestStartTimestamp()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Setup(x => x.StartTimestamp).Returns(new DateTime(2016, 10, 7, 14, 46, 00));
         proxy.StartTimestamp.Should().Be(new DateTime(2016, 10, 7, 14, 46, 00));
         _logFile.Setup(x => x.StartTimestamp).Returns((DateTime?)null);
         proxy.StartTimestamp.Should().NotHaveValue();
     }
 }
Exemplo n.º 8
0
        public void TestListen4()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
            {
                proxy.AddListener(_listener.Object, TimeSpan.Zero, 1000);

                new Action(() => proxy.OnLogFileModified(new Mock<ILogFile>().Object, new LogFileSection(0, 1))).ShouldNotThrow();
                _modifications.Should().Equal(new[] { LogFileSection.Reset }, "because the OnLogFileModified shouldn't have been forwarded since it's from the wrong source");

                new Action(() => proxy.OnLogFileModified(null, new LogFileSection(0, 1))).ShouldNotThrow();
                _modifications.Should().Equal(new[] { LogFileSection.Reset }, "because the OnLogFileModified shouldn't have been forwarded since it's from the wrong source");
            }
        }
Exemplo n.º 9
0
 public void TestMaxCharactersPerLine()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Setup(x => x.MaxCharactersPerLine).Returns(101);
         proxy.MaxCharactersPerLine.Should().Be(101);
         _logFile.Setup(x => x.MaxCharactersPerLine).Returns(42);
         proxy.MaxCharactersPerLine.Should().Be(42);
     }
 }
Exemplo n.º 10
0
 public void TestInnerLogFile1()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         proxy.InnerLogFile = null;
         _logFile.Verify(x => x.RemoveListener(It.IsAny<ILogFileListener>()), Times.Once);
     }
 }
Exemplo n.º 11
0
        public void TestListen3()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
            {
                proxy.AddListener(_listener.Object, TimeSpan.Zero, 1000);

                _listeners.OnRead(500);
                _listeners.Invalidate(400, 100);
                _listeners.OnRead(550);

                _scheduler.RunOnce();

                _modifications.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 500),
                    new LogFileSection(400, 100, true),
                    new LogFileSection(400, 150)
                });
            }
        }
Exemplo n.º 12
0
        public void TestGetSection()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
            {
                proxy.GetSection(new LogFileSection(42, 101), new LogLine[101]);

                var expected = new LogFileSection(42, 101);
                _logFile.Verify(l => l.GetSection(It.Is<LogFileSection>(x => Equals(x, expected)),
                                                 It.IsAny<LogLine[]>()), Times.Once);
            }
        }
Exemplo n.º 13
0
 public void TestGetLine()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         proxy.GetLine(42);
         _logFile.Verify(l => l.GetLine(It.Is<int>(x => x == 42)), Times.Once);
     }
 }
Exemplo n.º 14
0
 public void TestFileSize()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Setup(x => x.FileSize).Returns(Size.FromBytes(12));
         proxy.FileSize.Should().Be(Size.FromBytes(12));
         _logFile.Setup(x => x.FileSize).Returns(Size.OneMegabyte);
         proxy.FileSize.Should().Be(Size.OneMegabyte);
     }
 }
Exemplo n.º 15
0
 public void TestExists()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         _logFile.Setup(x => x.Exists).Returns(true);
         proxy.Exists.Should().BeTrue();
         _logFile.Setup(x => x.Exists).Returns(false);
         proxy.Exists.Should().BeFalse();
     }
 }
Exemplo n.º 16
0
 public void TestDispose2()
 {
     using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
     {
         proxy.Dispose();
         _logFile.Verify(l => l.Dispose(), Times.Once);
     }
 }