本文整理汇总了C#中InvalidOperationException.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# InvalidOperationException.ToString方法的具体用法?C# InvalidOperationException.ToString怎么用?C# InvalidOperationException.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvalidOperationException
的用法示例。
在下文中一共展示了InvalidOperationException.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Trace_Verbose_Writes_Correct_Message_To_TraceListeners_With_All_Fields_Set
public void Trace_Verbose_Writes_Correct_Message_To_TraceListeners_With_All_Fields_Set(TraceLevel level)
{
// Arrange
SystemDiagnosticsTraceWriter writer = CreateTraceWriter();
writer.MinimumLevel = level;
writer.IsVerbose = true;
HttpRequestMessage request = new HttpRequestMessage
{
RequestUri = new Uri("http://localhost"),
Method = HttpMethod.Get
};
InvalidOperationException exception = new InvalidOperationException("TestException");
// Act
writer.Trace(request, "TestCategory", level, (tr) =>
{
tr.Message = "TestMessage";
tr.Operation = "TestOperation";
tr.Operator = "TestOperator";
tr.Status = HttpStatusCode.Accepted;
tr.Exception = exception;
});
// Assert
string expected = String.Format("Level={0}, Kind=Trace, Category='TestCategory', Id={1}, Message='TestMessage', Operation=TestOperator.TestOperation, Status=202 (Accepted), Exception={2}",
level.ToString(),
request.GetCorrelationId().ToString(),
exception.ToString());
string actual = ((TestTraceListener)writer.TraceSource.Listeners[0]).Messages[0].Trim();
string timePrefix = "] ";
actual = actual.Substring(actual.IndexOf(timePrefix) + timePrefix.Length);
Assert.Equal(expected, actual);
}