public void It_should_return_unknown() { var identifier = new RemoraOperationKindIdentifier {Logger = GetConsoleLogger()}; var operation = new RemoraOperation(); Assert.That(identifier.Identify(operation), Is.EqualTo(RemoraOperationKind.Unknown)); }
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_return_null_when_not_found() { var container = new WindsorContainer(); var factory = new PipelineFactory(container.Kernel, new RemoraConfig()) {Logger = GetConsoleLogger()}; var operation = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/bar/foobar?welcome")}; Assert.That(factory.Get(operation), Is.Null); }
public void It_should_identify_soap_requests_by_SOAPAction_header() { var identifier = new RemoraOperationKindIdentifier {Logger = GetConsoleLogger()}; var operation = new RemoraOperation(); operation.Request.HttpHeaders.Add("SOAPAction", "http://tempuri.org/"); Assert.That(identifier.Identify(operation), Is.EqualTo(RemoraOperationKind.Soap)); }
public void It_should_create_an_appropriate_pipeline() { var container = new WindsorContainer(); container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentOne>().Named("cmpOne")); container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentTwo>().Named("cmpTwo")); var pipelineDef1 = PDef("pipe1", "/foo/(.*)", ""); var pipelineDef2 = PDef("pipe2", "/(.*)", "", "cmpOne", "cmpTwo"); var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2}}; var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()}; var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo/something")}; var result1 = factory.Get(operation1); Assert.That(result1.Id, Is.EqualTo(pipelineDef1.Id)); Assert.That(result1.Components.Count(), Is.EqualTo(0)); Assert.That(result1.Definition, Is.SameAs(pipelineDef1)); Assert.That(operation1.ExecutingPipeline, Is.SameAs(result1)); }
public void It_should_position_http_headers() { var operation = new RemoraOperation {IncomingUri = new Uri(@"http://tempuri.org")}; var componentDefinition = new ComponentDefinition { Properties = { {"name", "foo"}, {"value", "bar"} } }; _setHttpHeader.BeginAsyncProcess(operation, componentDefinition, b => { Assert.That(b); Assert.That(!operation.OnError); Assert.That( operation.Request.HttpHeaders[ "foo"], Is.EqualTo("bar")); }); }
public void It_should_throw_an_exception_if_name_or_value_not_in_component_definition() { var operation = new RemoraOperation {IncomingUri = new Uri(@"http://tempuri.org")}; var componentDefinition = new ComponentDefinition(); Assert.That(() => _setHttpHeader.BeginAsyncProcess(operation, componentDefinition, b => { }), Throws.Exception.TypeOf<SetHttpHeaderException>() .With.Message.Contains("name")); componentDefinition.Properties["name"] = "foo"; Assert.That(() => _setHttpHeader.BeginAsyncProcess(operation, componentDefinition, b => { }), Throws.Exception.TypeOf<SetHttpHeaderException>() .With.Message.Contains("value")); componentDefinition.Properties["name"] = "foo"; componentDefinition.Properties["value"] = "bar"; Assert.That(() => _setHttpHeader.BeginAsyncProcess(operation, componentDefinition, b => { }), Throws.Nothing); }
public void It_should_rewrite_url_if_present() { var container = new WindsorContainer(); var pipelineDef1 = PDef("pipe1", "http(s)?://.*/bar/(.*)", "http://tempuri2.org/$2"); var pipelineDef2 = PDef("pipe2", "/(.*)", ""); var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2}}; var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()}; var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/bar/foobar?welcome")}; var result1 = factory.Get(operation1); Assert.That(operation1.Request.Uri, Is.EqualTo(new Uri("http://tempuri2.org/foobar?welcome"))); var operation2 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo")}; var result2 = factory.Get(operation2); Assert.That(operation2.Request.Uri, Is.Null); }
public void It_should_throw_UrlRewriteException_when_urlrewriting_fails() { var container = new WindsorContainer(); var pipelineDef1 = PDef("pipe", ".*", "foo"); var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1}}; var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()}; var operation = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/")}; Assert.That(() => factory.Get(operation), Throws.Exception.TypeOf<UrlRewriteException>() .With.Message.Contains(".*") .And.Message.Contains("foo") ); }
public void It_should_throw_InvalidConfigurationException_when_filter_regex_is_invalid() { var container = new WindsorContainer(); var pipelineDef1 = PDef("pipe", "(((", ""); var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1}}; var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()}; var operation = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/")}; Assert.That(() => factory.Get(operation), Throws.Exception.TypeOf<InvalidConfigurationException>() .With.Message.Contains("(((") ); }
public void It_should_select_the_first_available_when_ambiguous() { var container = new WindsorContainer(); container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentOne>().Named("cmpOne")); container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentTwo>().Named("cmpTwo")); var pipelineDef1 = PDef("pipe1", "/bar/(.*)", ""); var pipelineDef2 = PDef("pipe2", "/(.*)", "", "cmpOne", "cmpTwo"); var pipelineDef3 = PDef("pipe3", "/foo/(.*)", "", "cmpOne", "cmpTwo"); var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2, pipelineDef3}}; var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()}; var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo/something")}; var result1 = factory.Get(operation1); Assert.That(result1.Id, Is.EqualTo(pipelineDef2.Id)); Assert.That(result1.Components.Count(), Is.EqualTo(2)); Assert.That(result1.Components.First(), Is.TypeOf<TestComponentOne>()); Assert.That(result1.Components.Skip(1).First(), Is.TypeOf<TestComponentTwo>()); }
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")); } }