private static SerializationFormatData ForData(string name, params string[] mimeTypes) { SerializationFormatData result = new SerializationFormatData(); result.name = name; result.mimeTypes = mimeTypes; return result; }
/// <summary> /// Sends the current request to the server, and tries to throw an /// exception if the response indicates an error occurred. /// </summary> public virtual void SendRequestAndCheckResponse() { this.SendRequest(); string mediaType = new ContentType(this.ResponseContentType).MediaType; SerializationFormatData data = SerializationFormatData.Values .Single(format => format.MimeTypes.Any(m => String.Equals(m, mediaType, StringComparison.OrdinalIgnoreCase))); if (data.IsStructured) { Stream stream = TestUtil.EnsureStreamWithSeek(this.GetResponseStream()); XmlReader reader = XmlReader.Create(stream); while (reader.Read()) { if (reader.LocalName == "error") { throw this.CreateExceptionFromError(XElement.Load(reader, LoadOptions.PreserveWhitespace)); } } stream.Position = 0; } else if (data.Name == "Text") { string text = this.GetResponseStreamAsText(); if (text.Contains("<?xml")) { throw new Exception(text); } } else { // TODO: implement. } }
private static SerializationFormatData ForData(string name, params string[] mimeTypes) { SerializationFormatData result = new SerializationFormatData(); result.name = name; result.mimeTypes = mimeTypes; return(result); }
private static void CreateValues() { if (values == null) { json = ForData("JSON", TestUtil.JsonFormat); atom = ForData("Atom", TestUtil.AtomFormat, "text/xml", "application/xml"); binary = ForData("Binary", "application/octet-stream"); values = new SerializationFormatData[] { json, atom, binary, ForData("Text", "text/plain"), }; } }