public void AppNameTest() { const string AppName = "MyApp"; byte[] formattedMsg = Forwarder.FormatMessage(Forwarder.Priority.LOG_DEBUG, AppName, "foo"); string actual = Encoding.UTF8.GetString(formattedMsg); string[] msgParts = actual.Split(' '); Assert.Equal(AppName, msgParts[3]); }
public void TimestampTest() { byte[] formattedMsg = Forwarder.FormatMessage(Forwarder.Priority.LOG_DEBUG, "app", "foo"); string actual = Encoding.UTF8.GetString(formattedMsg); actual = actual.Substring("<0>1 ".Length); string timestamp = actual.Substring(0, actual.IndexOf(" ")); DateTime now = DateTime.UtcNow; DateTime dt = XmlConvert.ToDateTime(timestamp, XmlDateTimeSerializationMode.Utc); TimeSpan delta = now.Subtract(dt); Assert.True(delta.Seconds < 10); }
public void HostnameTest() { byte[] formattedMsg = Forwarder.FormatMessage(Forwarder.Priority.LOG_DEBUG, "app", "foo"); string actual = Encoding.UTF8.GetString(formattedMsg); string[] msgParts = actual.Split(' '); string ipAddr = ""; var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { ipAddr = ip.ToString(); break; } } Assert.Equal(ipAddr, msgParts[2]); }
public void EndsWithNewlineTest() { byte[] formattedMsg = forwarder.FormatMessage(Forwarder.Priority.LOG_DEBUG, "app", "foo"); string actual = Encoding.UTF8.GetString(formattedMsg); Assert.EndsWith("\n", actual); }
public void EmptyMessageTest() { // The UTF-8 BOM should not be present when there is no message. byte[] b = Forwarder.FormatMessage(Forwarder.Priority.LOG_DEBUG, "", ""); Assert.Equal(0, BOMCount(b)); }