public async Task Should_use_it_for_component_resolution() { var container = new AcceptanceTestingContainer(); container.RegisterSingleton(typeof(MyComponent), myComponent); var result = await Scenario.Define <Context>() .WithEndpoint <ExternallyManagedContainerEndpoint>(b => { IStartableEndpointWithExternallyManagedContainer configuredEndpoint = null; b.ToCreateInstance( config => { configuredEndpoint = EndpointWithExternallyManagedContainer.Create(config, new RegistrationPhaseAdapter(container)); return(Task.FromResult(configuredEndpoint)); }, configured => configured.Start(new ResolutionPhaseAdapter(container)) ) .When((e, c) => { c.BuilderWasResolvable = container.Build(typeof(IBuilder)) != null; //use the session provided by configure to make sure its properly populated return(configuredEndpoint.MessageSession.Value.SendLocal(new SomeMessage())); }); }) .Done(c => c.Message != null) .Run(); Assert.AreEqual(result.Message, myComponent.Message); Assert.True(result.BuilderWasResolvable, "IBuilder should be resolvable in the container"); Assert.False(container.WasDisposed, "Externally managed containers should not be disposed"); }
public void Should_throw() { Assert.Throws <InvalidOperationException>(() => { var container = new AcceptanceTestingContainer(); var endpointConfiguration = new EndpointConfiguration("MyEndpoint"); endpointConfiguration.UseContainer(container); EndpointWithExternallyManagedContainer.Create(endpointConfiguration, new RegistrationPhaseAdapter(container)); }); }
public async Task Should_use_it_for_component_resolution() { var container = new AcceptanceTestingContainer(); container.RegisterSingleton(typeof(MyComponent), myComponent); var result = await Scenario.Define <Context>() .WithEndpoint <InternallyManagedContainerEndpoint>(b => { b.CustomConfig(c => c.UseContainer(container)); b.When(s => s.SendLocal(new SomeMessage())); }) .Done(c => c.Message != null) .Run(); Assert.AreEqual(result.Message, myComponent.Message); Assert.True(container.WasDisposed, "Internally managed containers should be disposed"); }