public void TestOpenBeforeCreate() { ILogSource logSource = null; try { string fileName = PathEx.GetTempFileName(); if (File.Exists(fileName)) { File.Delete(fileName); } new Action(() => logSource = Create(fileName)).Should().NotThrow(); logSource.Property(x => x.GetProperty(Properties.PercentageProcessed)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(Percentage.HundredPercent); logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).NotBeNull("Because the specified file doesn't exist"); File.WriteAllText(fileName, "Hello World!"); logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(null, "Because the file has been created now"); logSource.Property(x => x.GetProperty(Properties.LogEntryCount)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1, "Because one line was written to the file"); var entry = logSource.GetEntry(0); entry.Index.Should().Be(0); entry.RawContent.Should().Be("Hello World!"); } finally { logSource?.Dispose(); } }
public void TestExists() { ILogSource logSource = null; try { new Action(() => logSource = Create(File2Lines)).Should().NotThrow(); logSource.Property(x => x.GetProperty(Properties.PercentageProcessed)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(Percentage.HundredPercent); logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(null); logSource.GetProperty(Properties.EmptyReason).Should().Be(null, "Because the specified file does exist"); } finally { if (logSource != null) { logSource.Dispose(); } } }
public void TestDoesNotExist() { ILogSource logSource = null; try { new Action(() => logSource = Create("dadwdawdw")).Should().NotThrow(); logSource.Property(x => x.GetProperty(Properties.PercentageProcessed)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(Percentage.HundredPercent); logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).NotBeNull(); logSource.GetProperty(Properties.EmptyReason).Should().BeOfType <SourceDoesNotExist>("Because the specified file doesn't exist"); } finally { if (logSource != null) { logSource.Dispose(); } } }