public void CreateTextWriterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); Assert.AreSame(ex, formatter.Exception); }
public void CreateXmlWriterTest() { StringBuilder sb = new StringBuilder(); XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb)); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex); Assert.AreSame(writer, formatter.Writer); Assert.AreSame(ex, formatter.Exception); }
public void CreateXmlWriterTest() { StringBuilder sb = new StringBuilder(); XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb)); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); Assert.AreSame(writer, formatter.Writer); Assert.AreSame(ex, formatter.Exception); }
public void CreateTextWriterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex); // TextWriter won't be the same so we can only test the Exception Assert.AreSame(ex, formatter.Exception); }
public void CreateTextWriterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); // TextWriter won't be the same so we can only test the Exception Assert.AreSame(ex, formatter.Exception); }
public void SimpleTextWriterFormatterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); Assert.IsTrue(sb.Length > 0); }
public void SkipsHandlingInstanceIdIfEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception, Guid.Empty); formatter.Format(); string[] lines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.IsFalse(lines.Any(l => l.StartsWith("HandlingInstanceID", StringComparison.Ordinal))); }
public void SimpleFormatterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); Assert.IsTrue(sb.Length == 0); formatter.Format(); Assert.IsTrue(sb.Length > 0); }
public string DoTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); formatter.Format(); return(sb.ToString()); }
public void VerifyInnerExceptionGetsFormatted() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(message, new MockException()); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); Assert.IsTrue(sb.Length == 0); formatter.Format(); Assert.IsTrue(sb.ToString().Contains(innerException)); }
public void WellFormedTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); }
public void VerifyInnerExceptionGetsFormatted() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("exception message", new MockException()); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("//InnerException"); Assert.IsNotNull(element); }
public void WritesHandlingInstanceIdIfNotEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Guid testGuid = Guid.NewGuid(); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception, testGuid); formatter.Format(); string[] lines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string line = lines.First(l => l.StartsWith("HandlingInstanceID", StringComparison.Ordinal)); Assert.IsNotNull(line); Assert.IsTrue(line.IndexOf(testGuid.ToString("D", CultureInfo.InvariantCulture)) >= 0); }
public void VerifyInnerExceptionGetsFormatted() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("Foo Bar", new MockException()); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("//InnerException"); Assert.IsNotNull(element); }
public void DoesNotFormatHandlingInstanceIdIfEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("Foo Bar", new MockException()); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("/Exception/@handlingInstanceId"); Assert.IsNull(element); }
public void CanGetMachineNameWithoutSecurity() { EnvironmentPermission denyPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, computerName); PermissionSet permissions = new PermissionSet(PermissionState.None); permissions.AddPermission(denyPermission); permissions.Deny(); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); Assert.IsTrue(sb.Length == 0); formatter.Format(); Assert.IsTrue(sb.ToString().Contains(machineName + " : " + permissionDenied)); }
public void FormatsHandlingInstanceIdIfAvailable() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("Foo Bar", new MockException()); Guid testGuid = Guid.NewGuid(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, testGuid); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("/Exception/@handlingInstanceId"); Assert.IsNotNull(element); Assert.AreEqual(testGuid.ToString("D", CultureInfo.InvariantCulture), element.InnerText); }
public void CanGetWindowsIdentityWithoutSecurity() { SecurityPermission denyPermission = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal); PermissionSet permissions = new PermissionSet(PermissionState.None); permissions.AddPermission(denyPermission); permissions.Deny(); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); Assert.IsTrue(sb.Length == 0); formatter.Format(); Console.WriteLine(sb.ToString()); Assert.IsTrue(sb.ToString().Contains(windowsIdentity + " : " + permissionDenied)); }
public void SimpleFormatterTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); // Nothing should be written until Format() is called Assert.IsTrue(sb.Length == 0); // Format the exception formatter.Format(); // Not much of a test, but at least we can tell if _something_ got written // to the underlying StringBuilder Assert.IsTrue(sb.Length > 0); }
public string DoTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception); formatter.Format(); return sb.ToString(); }
public void FormatsHandlingInstanceIdIfAvailable() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("exception message", new MockException()); Guid testGuid = Guid.NewGuid(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, testGuid); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("/Exception/@handlingInstanceId"); Assert.IsNotNull(element); Assert.AreEqual(testGuid.ToString("D", CultureInfo.InvariantCulture), element.InnerText); }
public void DoesNotFormatHandlingInstanceIdIfEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException("exception message", new MockException()); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, exception, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); XmlNode element = doc.DocumentElement.SelectSingleNode("/Exception/@handlingInstanceId"); Assert.IsNull(element); }
public void WritesHandlingInstanceIdIfNotEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Guid testGuid = Guid.NewGuid(); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception, testGuid); // Format the exception formatter.Format(); string[] lines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); string line = lines.First(l => l.StartsWith("HandlingInstanceID", StringComparison.Ordinal)); Assert.IsNotNull(line); Assert.IsTrue(line.IndexOf(testGuid.ToString("D", CultureInfo.InvariantCulture)) >= 0); }
public void SimpleXmlWriterFormatterTest() { StringBuilder sb = new StringBuilder(); XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb)); Exception ex = new MockException(); XmlExceptionFormatter formatter = new XmlExceptionFormatter(writer, ex, Guid.Empty); Assert.IsTrue(sb.Length == 0); formatter.Format(); Assert.IsTrue(sb.Length > 0); }
public void SkipsHandlingInstanceIdIfEmpty() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Exception exception = new MockException(); TextExceptionFormatter formatter = new TextExceptionFormatter(writer, exception, Guid.Empty); // Format the exception formatter.Format(); string[] lines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.IsFalse(lines.Any(l => l.StartsWith("HandlingInstanceID", StringComparison.Ordinal))); }