Пример #1
0
		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;
				}
			}
		}