public void It_should_validate_arguments() { var formatter = new ExceptionFormatter(); Assert.That(() => formatter.WriteException(null, null), Throws.Exception.TypeOf<ArgumentNullException>() .With.Message.Contains("operation") ); Assert.That(() => formatter.WriteException(new RemoraOperation(), null), Throws.Exception.TypeOf<ArgumentNullException>() .With.Message.Contains("response") ); }
public void It_should_write_faults_when_operation_is_kind_of_soap() { var operation = new RemoraOperation { Kind = RemoraOperationKind.Soap, Exception = new InvalidConfigurationException("themessage") }; using (var stream = new MemoryStream()) { var response = _mocks.Stub<IUniversalResponse>(); SetupResult.For(response.OutputStream).Return(stream); _mocks.Replay(response); var formatter = new ExceptionFormatter(); formatter.WriteException(operation, response); Assert.That(response.ContentType, Is.EqualTo("text/xml")); Assert.That(response.StatusCode, Is.EqualTo((int) HttpStatusCode.OK)); Assert.That(response.ContentEncoding, Is.EqualTo(Encoding.UTF8)); stream.Position = 0; var body = Encoding.UTF8.GetString(stream.ReadFully(0)); Assert.That(body, Contains.Substring("InvalidConfiguration")); Assert.That(body, Contains.Substring("themessage")); using (var reader = new StringReader(body)) { Assert.That(() => XDocument.Load(reader), Throws.Nothing); } } }
public void It_should_write_html_errors_when_unknown() { var operation = new RemoraOperation { Kind = RemoraOperationKind.Unknown, Exception = new InvalidConfigurationException("themessage") }; using (var stream = new MemoryStream()) { var response = _mocks.Stub<IUniversalResponse>(); SetupResult.For(response.OutputStream).Return(stream); _mocks.Replay(response); var formatter = new ExceptionFormatter(); formatter.WriteException(operation, response); Assert.That(response.ContentType, Is.EqualTo("text/html")); Assert.That(response.StatusCode, Is.EqualTo((int) HttpStatusCode.InternalServerError)); Assert.That(response.ContentEncoding, Is.EqualTo(Encoding.UTF8)); stream.Position = 0; var body = Encoding.UTF8.GetString(stream.ReadFully(0)); Assert.That(body, Contains.Substring("InvalidConfiguration")); Assert.That(body, Contains.Substring("themessage")); } }