protected void setup() { Host = new InMemoryHost(startup: new StartupProperties { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } }); Pipeline = null; _actions = new Dictionary <Type, Func <ICommunicationContext, Task <PipelineContinuation> > >(); var manager = Host.HostManager; Resolver.AddDependencyInstance(typeof(IErrorCollector), Errors = new TestErrorCollector()); Resolver.AddDependency <IPathManager, PathManager>(); _ambientContext = new ContextScope(new AmbientContext()); _requestScope = Resolver.CreateRequestScope(); manager.SetupCommunicationContext(Context = new WriteTrackingResponseCommunicationContext(InnerContext = new InMemoryCommunicationContext())); }
public InMemoryReceiveEndpointBuilder(IBusBuilder busBuilder, InMemoryHost host, ISendTransportProvider sendTransportProvider, IInMemoryEndpointConfiguration configuration) : base(busBuilder, configuration) { _host = host; _sendTransportProvider = sendTransportProvider; _configuration = configuration; }
public InMemoryPublishEndpointProvider(ISendEndpointProvider sendEndpointProvider, ISendTransportProvider transportProvider, IPublishPipe publishPipe) { _sendEndpointProvider = sendEndpointProvider; _publishPipe = publishPipe; _host = transportProvider as InMemoryHost; _publishObservable = new PublishObservable(); }
public InMemoryBusBuilder(InMemoryHost inMemoryHost, ISendTransportProvider sendTransportProvider, BusHostCollection <IBusHostControl> hosts, IInMemoryEndpointConfiguration configuration) : base(hosts, configuration) { if (inMemoryHost == null) { throw new ArgumentNullException(nameof(inMemoryHost)); } if (sendTransportProvider == null) { throw new ArgumentNullException(nameof(sendTransportProvider)); } var busQueueName = GenerateBusQueueName(); _inputAddress = new Uri(inMemoryHost.Address, $"{busQueueName}"); InMemoryHost = inMemoryHost; _configuration = configuration; var busEndpointSpecification = _configuration.CreateNewConfiguration(ConsumePipe); _busEndpointSpecification = new InMemoryReceiveEndpointSpecification(inMemoryHost.Address, busQueueName, sendTransportProvider, busEndpointSpecification); inMemoryHost.ReceiveEndpointFactory = new InMemoryReceiveEndpointFactory(this, sendTransportProvider, configuration); }
public apiDocumentation() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(opt => { opt.Vocabulary = ExampleVocabularies.ExampleApp.Uri.ToString(); opt.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has.ResourcesOfType <CreateAction>().Vocabulary(Vocabularies.SchemaDotOrg); ResourceSpace.Has.ResourcesOfType <Customer>() .Vocabulary(ExampleVocabularies.ExampleApp.Uri.ToString()) .SupportedOperation(new Operation { Method = "POST", Expects = "schema:Event" }) .SupportedOperation(new CreateAction { Method = "POST", Expects = "schema:Person" }); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary(ExampleVocabularies.ExampleApp.Uri.ToString()); ResourceSpace.Has.ResourcesNamed("Ignored"); }, startup: new StartupProperties() { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } }); }
public static_links() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; options.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary("https://schemas.example/schema#") .Link(new SubLink("sub", new Uri("sub", UriKind.Relative))) .Link(new SubLink("subdub", new Uri("sub/dub", UriKind.Relative), "blah")) .AtUri("/events/{id}") .HandledBy <EventHandler>(); ResourceSpace.Has.ResourcesOfType <Customer>(); }, startup: new StartupProperties() { OpenRasta = { Diagnostics = { TracePipelineExecution = false }, Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false} } }); }
public iri_node_named_resource_types() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; }); ResourceSpace.Has.ResourcesOfType <Event>() .Named("MyEvents") .Vocabulary("https://schemas.example/schema#") .AtUri(ev => $"/my-events/{ev.Id}") .HandledBy <EventHandler>(); ResourceSpace.Has.ResourcesOfType <Event>() .Named("YourEvents") .Vocabulary("https://schemas.example/schema#") .AtUri(ev => $"/your-events/{ev.Id}") .HandledBy <EventHandler>(); }, startup: new StartupProperties() { OpenRasta = { Diagnostics = { TracePipelineExecution = false }, Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false} } }); }
public void Create_server_and_issue_a_get_request() { using (var host = new InMemoryHost(new OpenRastaConfiguration())) { var request = new InMemoryRequest() { Uri = new Uri("http://localhost/10000/refData"), HttpMethod = "GET" }; // set up code formats request.Entity.ContentType = MediaType.Json; request.Entity.Headers["Accept"] = "application/json"; // send the request and save the resulting response var response = host.ProcessRequest(request); int statusCode = response.StatusCode; // deserialize the content from the response if (response.Entity.ContentLength > 0) { // rewind the stream, as OpenRasta won't do this response.Entity.Stream.Seek(0, SeekOrigin.Begin); var serializer = new DataContractJsonSerializer(typeof(RefData)); refData = (RefData)serializer.ReadObject(response.Entity.Stream); } } }
public void CanRetrieveSimpleResourceDetails() { using (var host = new InMemoryHost(new SampleApi.Configuration())) { var request = new InMemoryRequest { Uri = new Uri("http://localhost/api-docs/simple"), HttpMethod = "GET", Entity = { ContentType = MediaType.Json } }; request.Entity.Headers["Accept"] = "application/json"; var response = host.ProcessRequest(request); var statusCode = response.StatusCode; Assert.AreEqual(200, statusCode); Assert.IsTrue(response.Entity.ContentLength > 0); response.Entity.Stream.Seek(0, SeekOrigin.Begin); var serializer = new DataContractJsonSerializer(typeof(ResourceDetails)); var resourceDetails = (ResourceDetails)serializer.ReadObject(response.Entity.Stream); Assert.IsNotNull(resourceDetails); } }
public void FixtureSetUp() { _host = FubuApplication .For <JsonSerializationFubuRegistry>() .StructureMap() .RunInMemory(); }
public iri_node_with_blank_node() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; }); ResourceSpace.Has.ResourcesOfType <Person>() .Vocabulary("https://schemas.example/schema#"); ResourceSpace.Has.ResourcesOfType <EventWithPerson>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{id}") .HandledBy <Handler>(); }, startup: new StartupProperties() { OpenRasta = { Diagnostics = { TracePipelineExecution = false }, Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false} } }); }
public custom_collection_type() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; options.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has.ResourcesOfType <EventCollection>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/") .HandledBy <Handler>(); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{id}"); ResourceSpace.Has.ResourcesOfType <Customer>() .Vocabulary("https://schemas.example/schema#") .AtUri(customer => $"/customers/{customer.Name}"); }, startup: new StartupProperties { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } }); }
public search() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; options.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has .ResourcesOfType <List <Event> >() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/") .EntryPointCollection(options => { options.Search = new IriTemplate("/events/{?q}") { Mapping = { new IriTemplateMapping("q") } }; }); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{location}/{id}"); }, startup: new StartupProperties() { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } }); }
public iri_node_with_iri_node() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; options.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has.ResourcesOfType <Person>() .Vocabulary("https://schemas.example/schema#") .AtUri("/people/{id}"); ResourceSpace.Has.ResourcesOfType <EventWithPerson>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{id}") .HandledBy <Handler>(); }, startup: new StartupProperties() { OpenRasta = { Diagnostics = { TracePipelineExecution = false }, Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false} } }); }
public async Task request_is_returned() { using (var server = new InMemoryHost(() => { ResourceSpace.Has.ResourcesNamed("resource") .AtUri("/{id}").HandledBy <Handler>(); ResourceSpace.Uses.Diagnostics(new DiagnosticsOptions { TraceMethod = true }); })) { var response = await server.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "TRACE", Uri = new Uri("http://localhost/1"), Headers = { { "Accept", "*/*" }, { "User-Agent", "stuff" } } }); response.StatusCode.ShouldBe(200); response.Entity.ContentType?.MediaType.ShouldBe("message/http"); using (var reader = new StreamReader(response.Entity.Stream, Encoding.UTF8)) reader.ReadToEnd().ShouldBe( "TRACE /1 HTTP/1.1\r\n" + "Host: http://localhost/\r\n" + "Accept: */*\r\n" + "User-Agent: stuff\r\n\r\n"); } }
protected override void SetUp() { base.SetUp(); Host = new InMemoryHost(null); DependencyManager.SetResolver(Host.Resolver); }
public async Task should_provide_enumerable_independently() { var server = new InMemoryHost(() => { ResourceSpace.Has.ResourcesNamed("multipart_parser") .AtUri("/multipart/{id}") .HandledBy <MultiPartHandler>(); }); var response = await server.Post( "/multipart/1", contentType : "multipart/form-data;boundary=bound", content : @" --bound Content-Disposition: form-data; name=""id"" 1 --bound Content-Disposition: form-data; name=""another"" another --bound-- "); response.StatusCode.ShouldBe(200); response.ReadString().ShouldBe("id=1;count=1"); }
private IResponse ProcessRequest(InMemoryHost x) { IResponse response = x.ProcessRequest(BuildRequest()); response.Entity.Stream.Seek(0, SeekOrigin.Begin); return(response); }
protected void given_context() { Host = new InMemoryHost(null); HostManager = Host.HostManager; HostManager.SetupCommunicationContext(Context = new InMemoryCommunicationContext()); DependencyManager.SetResolver(Host.Resolver); }
public search() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => options.Vocabulary = "https://schemas.example/schema#"); ResourceSpace.Has .ResourcesOfType <List <Event> >() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/") .EntryPointCollection(options => { options.Search = new IriTemplate("/events/{?q}") { Mapping = { new IriTemplateMapping("q") } }; }); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{location}/{id}"); }); }
public registering_factory() { host = new InMemoryHost(() => { ResourceSpace.Uses.Dependency(context => context.Singleton(() => new ClassWithDefaultConstructor())); }); }
public context() { server = new InMemoryHost(() => { ResourceSpace.Uses.Hydra(options => { options.Vocabulary = "https://schemas.example/schema#"; options.Serializer = ctx => ctx.Transient(() => new PreCompiledUtf8JsonSerializer()).As <IMetaModelHandler>(); }); ResourceSpace.Has .ResourcesOfType <List <Event> >() .Vocabulary("https://schemas.example/schema#") .AtUri("/events") .EntryPointCollection(); ResourceSpace.Has.ResourcesOfType <Event>() .Vocabulary("https://schemas.example/schema#") .AtUri("/events/{id}"); }, startup: new StartupProperties { OpenRasta = { Diagnostics = { TracePipelineExecution = false }, Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false} } }); }
protected override void SetUp() { base.SetUp(); Host = new InMemoryHost(); DependencyManager.SetResolver(Host.Resolver); configCookie = OpenRastaConfiguration.Manual; }
public static Task <IResponse> Get(this InMemoryHost host, string uri) { return(host.ProcessRequestAsync(new InMemoryRequest { HttpMethod = "GET", Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute) })); }
public IInMemoryHostConfiguration CreateHostConfiguration(InMemoryHost host) { var hostConfiguration = new InMemoryHostConfiguration(this, host); _hosts.Add(hostConfiguration); return(hostConfiguration); }
protected void given_context() { Host = new InMemoryHost(); HostManager = Host.HostManager; DependencyManager.SetResolver(Host.Resolver); RequestScope = Host.Resolver.CreateRequestScope(); HostManager.SetupCommunicationContext(Context = new InMemoryCommunicationContext()); }
static Task <IResponse> ExecuteMethod(InMemoryHost host, string method, string uri, string content, string contentType) { return(host.ProcessRequestAsync(new InMemoryRequest { HttpMethod = method, Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute) }.WriteString(content, contentType))); }
public post_with_and_without_uri_var_as_int() { server = new InMemoryHost(() => ResourceSpace.Has .ResourcesNamed("example") .AtUri("/domain/new") .And.AtUri("/account/{account_id}/domain/new") .HandledBy <CollectionHandler <int, string> >()); }
public no_accept_header_with_wildcard_and_specific_mt_codec() { server = new InMemoryHost(() => ResourceSpace.Has .ResourcesOfType <TaskItem>() .AtUri("/{id}") .HandledBy <TaskHandler>() .TranscodedBy <NullCodec>().ForMediaType("*/*").ForMediaType("application/json")); }
async Task <IResponse> Get(Func <OperationResult> getter) { var server = new InMemoryHost(new ErrorApi(getter)); return(await server.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "GET" })); }
public InMemoryHostConfiguration(IInMemoryBusConfiguration busConfiguration, Uri baseAddress, int transportConcurrencyLimit, IHostTopology hostTopology) { _busConfiguration = busConfiguration; Topology = hostTopology; HostAddress = baseAddress ?? new Uri("loopback://localhost/"); _host = new InMemoryHost(this, transportConcurrencyLimit); }
public void FixtureSetUp() { fileSystem.DeleteDirectory(Folder); fileSystem.CreateDirectory(Folder); fileSystem.CreateDirectory(Folder.AppendPath(Application)); _streams.Each(x => x.DumpContents()); FubuMvcPackageFacility.PhysicalRootPath = _applicationDirectory; var runtime = FubuApplication.For(determineRegistry()).StructureMap() .Packages(x => x.Loader(this)).Bootstrap(); _host = new InMemoryHost(runtime); }
public InMemoryBusBuilder(InMemoryHost inMemoryHost, ISendTransportProvider sendTransportProvider, BusHostCollection<IBusHostControl> hosts, IConsumePipeFactory consumePipeFactory, ISendPipeFactory sendPipeFactory, IPublishPipeFactory publishPipeFactory) : base(consumePipeFactory, sendPipeFactory, publishPipeFactory, hosts) { if (inMemoryHost == null) throw new ArgumentNullException(nameof(inMemoryHost)); if (sendTransportProvider == null) throw new ArgumentNullException(nameof(sendTransportProvider)); var busQueueName = GenerateBusQueueName(); _inputAddress = new Uri($"loopback://localhost/{busQueueName}"); InMemoryHost = inMemoryHost; _sendTransportProvider = sendTransportProvider; _busEndpointSpecification = new InMemoryReceiveEndpointSpecification(busQueueName, ConsumePipe); inMemoryHost.ReceiveEndpointFactory = new InMemoryReceiveEndpointFactory(this); }
public async Task Should_be_able_to_consume_messages_polymorphically_if_the_receiving_bus_support_the_binary_serializer() { var inMemoryTransportCache = new InMemoryHost(Environment.ProcessorCount); var consumed = new TaskCompletionSource<Base>(); var sourceBus = Bus.Factory.CreateUsingInMemory(x => { x.SetHost(inMemoryTransportCache); x.UseBinarySerializer(); }); var recvBus = Bus.Factory.CreateUsingInMemory(x => { x.SetHost(inMemoryTransportCache); x.SupportBinaryMessageDeserializer(); x.UseJsonSerializer(); x.ReceiveEndpoint("input_queue", configurator => { #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously configurator.Handler<Base>(async ctx => { consumed.TrySetResult(ctx.Message); }); #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously }); }); await sourceBus.StartAsync(); await recvBus.StartAsync(); // Create a recursive list var head = new ListNode { Value = 100 }; var tail = new ListNode { Next = head, Value = 200 }; head.Next = tail; var messageToSend = new Derived() { PropBase = 10, PropDerived = 20, Head = head }; await sourceBus.Publish(messageToSend); var completedTask = await Task.WhenAny(consumed.Task, Task.Delay(250)); Assert.AreEqual(consumed.Task, completedTask, "Timeout while waiting to receive the message sent on the source bus."); var message = await consumed.Task; Assert.NotNull(message); Assert.AreEqual(messageToSend.PropBase, message.PropBase); Assert.AreEqual(head.Value, message.Head.Value); Assert.AreEqual(tail.Value, message.Head.Next.Value); Assert.AreEqual(head.Value, message.Head.Next.Next.Value); await sourceBus.StopAsync(); await recvBus.StopAsync(); }
public void SetUp() { host = newHost(); }