本文整理汇总了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;
}
}
}