public void ShouldFlushOnceAWhile() { // Setup var configuration = BuildTestConfigration(); DateTime now = DateTime.Now; // Exercise using (CustomHealthReporter target = new CustomHealthReporter(configuration, 200, customCreateFileStream: null, setNewStreamWriter: null, currentTimeProvider: () => now)) { target.Activate(); target.ReportProblem("Error message, with comma.", "UnitTest"); // Verify Assert.False(target.FlushOperation.WaitOne(StreamOperationTimeoutMsec)); target.StreamWriterMock.Verify( s => s.Flush(), Times.Never()); now += TimeSpan.FromMilliseconds(500); target.ReportProblem("Error message, with comma.", "UnitTest"); Assert.True(target.FlushOperation.WaitOne(StreamOperationTimeoutMsec)); target.StreamWriterMock.Verify( s => s.Flush(), Times.Exactly(1)); } }
public async void ShouldFlushOnceAWhile() { // Setup var configuration = BuildTestConfigration(); int flushPeriodPlusMsec = 500; // Exercise using (CustomHealthReporter target = new CustomHealthReporter(configuration, 200)) { target.Activate(); target.ReportProblem("Error message, with comma.", "UnitTest"); // Verify await Task.Delay(DefaultDelayMsec); target.StreamWriterMock.Verify( s => s.Flush(), Times.Never()); await Task.Delay(flushPeriodPlusMsec); target.ReportProblem("Error message, with comma.", "UnitTest"); await Task.Delay(DefaultDelayMsec); target.StreamWriterMock.Verify( s => s.Flush(), Times.Exactly(1)); } }
public void ReportProblemShouldWriteError() { var configuration = BuildTestConfigration(); // Exercise using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { target.Activate(); target.ReportProblem("Error message.", "UnitTest"); Assert.True(target.WriteOperation.WaitOne(StreamOperationTimeoutMsec)); // Verify target.StreamWriterMock.Verify( s => s.WriteLine( It.Is <string>(msg => msg.Contains("UnitTest,Error,Error message."))), Times.Exactly(1)); } }
public void ShouldEscapeQuotesWhenThereIsCommaInMessage() { // Setup var configuration = BuildTestConfigration(); // Exercise using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { target.Activate(); target.ReportProblem("Error \"message\", with comma and quotes.", "UnitTest"); // Verify Assert.True(target.WriteOperation.WaitOne(StreamOperationTimeoutMsec)); target.StreamWriterMock.Verify( s => s.WriteLine( It.Is <string>(msg => msg.Contains("UnitTest,Error,\"Error \"\"message\"\", with comma and quotes.\""))), Times.Exactly(1)); } }
public async void ReportProblemShouldWriteError() { var configuration = BuildTestConfigration(); // Exercise using (CustomHealthReporter target = new CustomHealthReporter(configuration)) { target.Activate(); target.ReportProblem("Error message.", "UnitTest"); await Task.Delay(DefaultDelayMsec); // Verify target.StreamWriterMock.Verify( s => s.WriteLine( It.Is <string>(msg => msg.Contains("UnitTest,Error,Error message."))), Times.Exactly(1)); } }