本文整理匯總了C#中System.InvalidOperationException.CreateResponse方法的典型用法代碼示例。如果您正苦於以下問題:C# InvalidOperationException.CreateResponse方法的具體用法?C# InvalidOperationException.CreateResponse怎麽用?C# InvalidOperationException.CreateResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.InvalidOperationException
的用法示例。
在下文中一共展示了InvalidOperationException.CreateResponse方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Exceptions_are_returned_in_the_requested_format
public void Exceptions_are_returned_in_the_requested_format()
{
const string expectedJson =
@"{
""name"":""InvalidOperationException"",
""message"":""FakeException"",
""callStack"":null
}";
const string expectedXml =
@"<?xml version=""1.0""?>
<Exception xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<name>InvalidOperationException</name>
<message>FakeException</message>
</Exception>";
var ex = new InvalidOperationException("FakeException", null);
foreach (var format in Enum.GetValues(typeof(ResponseFormat)).Cast<ResponseFormat>())
{
configureResponse(format);
switch (format)
{
case ResponseFormat.Html:
Assert.IsNull(ex.CreateResponse(format, _formatter));
break;
case ResponseFormat.Xml:
var xml = ex.CreateResponse(format, _formatter);
assertAreEqual(xml, expectedXml);
break;
case ResponseFormat.Json:
var json = ex.CreateResponse(format, _formatter);
assertAreEqual(json, expectedJson);
break;
}
}
}