public void LogFilterPositive() { LogRow row = LogRow.GetInstance(this.readOnlyColumns); LogColumn column = this.readOnlyColumns[0]; MemoryStream memoryStream = new MemoryStream(); LogFilter filter = LogFilter.GetTestInstance( delegate { return(LogWriter.GetInstance(memoryStream, false)); }, column.Parameter, column.Conversion); LogFilter.SetDefaultBehavior(true); filter.LogStart(row); filter.LogEntry(row); filter.LogEntry(row); filter.LogStop(); string actual = Encoding.ASCII.GetString(memoryStream.ToArray()); string expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine; Assert.AreEqual(expected, actual, "Log with two entries"); }
public void LogWriterTimeColumns() { LogRow row = LogRow.GetInstance(this.readOnlyColumns); MemoryStream memoryStream = new MemoryStream(); LogWriter writer = LogWriter.GetInstance(memoryStream, true); writer.LogStart(row); System.Threading.Thread.Sleep(10); writer.LogEntry(row); writer.LogEntry(row); writer.LogStop(); // "yyyy-MM-dd T hh:mm:ss:fff" string actual = Encoding.ASCII.GetString(memoryStream.ToArray()); string expected = "Time, Clock, Parameter1, Parameter2, Parameter3" + Environment.NewLine + @"\d\d, \d\d\d\d-\d\d-\d\d T \d\d:\d\d:\d\d:\d\d\d, 0, 0.0, 0.00" + Environment.NewLine + @"\d\d, \d\d\d\d-\d\d-\d\d T \d\d:\d\d:\d\d:\d\d\d, 0, 0.0, 0.00" + Environment.NewLine; string[] actualRows = actual.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string[] expectedRows = expected.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.AreEqual(expectedRows.Length, actualRows.Length, "line counts"); for (int i = 0; i < actualRows.Length; i++) { Regex regex = new Regex(expectedRows[i]); Match match = regex.Match(actualRows[i]); Assert.IsTrue( match.Success, "Row " + i + Environment.NewLine + "Actual: " + actualRows[i] + Environment.NewLine + "Expected: " + expectedRows[i] + Environment.NewLine); } }
public void LogFilterTwoLogs() { int iteration = 1; MemoryStream memoryStream1 = new MemoryStream(); MemoryStream memoryStream2 = new MemoryStream(); LogRow row = LogRow.GetInstance(this.readOnlyColumns); LogColumn column = this.readOnlyColumns[0]; LogFilter filter = LogFilter.GetTestInstance( delegate { if (iteration == 1) { return(LogWriter.GetInstance(memoryStream1, false)); } else { return(LogWriter.GetInstance(memoryStream2, false)); } }, column.Parameter, column.Conversion); LogFilter.SetDefaultBehavior(true); filter.LogStart(row); filter.LogEntry(row); filter.LogEntry(row); filter.LogStop(); iteration = 2; filter.LogStart(row); filter.LogEntry(row); filter.LogEntry(row); filter.LogStop(); string actual = Encoding.ASCII.GetString(memoryStream1.ToArray()); string expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine; Assert.AreEqual(expected, actual, "first log"); actual = Encoding.ASCII.GetString(memoryStream2.ToArray()); Assert.AreEqual(expected, actual, "second log"); }
public void LogWriterStart() { LogRow row = LogRow.GetInstance(this.readOnlyColumns); MemoryStream memoryStream = new MemoryStream(); using (LogWriter writer = LogWriter.GetInstance(memoryStream, false)) { writer.LogStart(row); } string actual = Encoding.ASCII.GetString(memoryStream.ToArray()); string expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine; Assert.AreEqual(expected, actual, "Log Header"); }
public void LogWriterStop() { LogRow row = LogRow.GetInstance(this.readOnlyColumns); MemoryStream memoryStream = new MemoryStream(); LogWriter writer = LogWriter.GetInstance(memoryStream, false); writer.LogStart(row); writer.LogEntry(row); writer.LogEntry(row); writer.LogStop(); string actual = Encoding.ASCII.GetString(memoryStream.ToArray()); string expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine + "0, 0.0, 0.00" + Environment.NewLine; Assert.AreEqual(expected, actual, "Log with two entries"); }
public void LogFilterDynamic() { int iteration = 1; MemoryStream memoryStream1 = new MemoryStream(); MemoryStream memoryStream2 = new MemoryStream(); MemoryStream memoryStream3 = new MemoryStream(); LogRow row = LogRow.GetInstance(this.readOnlyColumns); LogColumn column = this.readOnlyColumns[0]; LogFilter filter = TestLogFilter.GetInstance( delegate { if (iteration == 1) { return(LogWriter.GetInstance(memoryStream1, false)); } else if (iteration == 2) { return(LogWriter.GetInstance(memoryStream2, false)); } else if (iteration == 3) { return(LogWriter.GetInstance(memoryStream3, false)); } return(null); }, column.Parameter, column.Conversion, "3"); foreach (LogColumn tempColumn in this.readOnlyColumns) { string value; double unused; tempColumn.Conversion.Convert(3, out value, out unused); tempColumn.ValueAsString = value; } filter.LogStart(row); filter.LogEntry(row); filter.LogEntry(row); iteration = 2; foreach (LogColumn tempColumn in this.readOnlyColumns) { string value; double unused; tempColumn.Conversion.Convert(1, out value, out unused); tempColumn.ValueAsString = value; } filter.LogEntry(row); foreach (LogColumn tempColumn in this.readOnlyColumns) { string value; double unused; tempColumn.Conversion.Convert(2, out value, out unused); tempColumn.ValueAsString = value; } filter.LogEntry(row); iteration = 3; foreach (LogColumn tempColumn in this.readOnlyColumns) { string value; double unused; tempColumn.Conversion.Convert(3, out value, out unused); tempColumn.ValueAsString = value; } filter.LogEntry(row); filter.LogEntry(row); filter.LogStop(); // First log string actual = Encoding.ASCII.GetString(memoryStream1.ToArray()); string expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine + "3, 1.5, 6.00" + Environment.NewLine + "3, 1.5, 6.00" + Environment.NewLine; Assert.AreEqual(expected, actual, "first log"); // Second log actual = Encoding.ASCII.GetString(memoryStream2.ToArray()); Assert.AreEqual(string.Empty, actual, "second log"); // Third log expected = "Parameter1, Parameter2, Parameter3" + Environment.NewLine + "1, 0.5, 2.00" + Environment.NewLine + "2, 1.0, 4.00" + Environment.NewLine + "3, 1.5, 6.00" + Environment.NewLine + "3, 1.5, 6.00" + Environment.NewLine; actual = Encoding.ASCII.GetString(memoryStream3.ToArray()); Assert.AreEqual(expected, actual, "third log"); }