public void register_a_service_by_value() { var myContainer = new Container(); var myFacility = new StructureMapContainerFacility(myContainer); var registry = new UrlRegistry(); myFacility.Register(typeof (IUrlRegistry), new ObjectDef { Value = registry }); myFacility.BuildFactory(); myContainer.GetInstance<IUrlRegistry>().ShouldBeTheSameAs(registry); }
public void SetUp() { container = new Container(); graph = new FubuRegistry(x => { x.Route<InputModel>("/area/sub/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route<InputModel>("/area/sub2/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route<InputModel>("/area/sub3/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Models.ConvertUsing<ExampleConverter>().ConvertUsing<ExampleConverter2>(); }).BuildGraph(); facility = new StructureMapContainerFacility(container); graph.EachService(facility.Register); factory = facility.BuildFactory(); }
public void should_register_an_endpoint_authorizor_if_there_are_any_authorization_rules() { var chain = new BehaviorChain(); chain.AddToEnd(ActionCall.For<OneController>(x => x.Query(null))); chain.Authorization.AddRole("Role 1"); chain.Prepend(chain.Authorization); var container = new Container(); var facility = new StructureMapContainerFacility(container); chain.As<IRegisterable>().Register(DiagnosticLevel.None, facility.Register); facility.BuildFactory(); container.GetInstance<IEndPointAuthorizor>(chain.UniqueId.ToString()) .ShouldNotBeNull().ShouldBeOfType<EndPointAuthorizor>(); }
public void should_not_register_an_endpoint_authorizor_if_there_are_no_authorization_roles() { var chain = new BehaviorChain(); chain.AddToEnd(ActionCall.For<OneController>(x => x.Query(null))); //chain.Authorization.AddRole("Role 1"); var container = new Container(); var facility = new StructureMapContainerFacility(container); chain.As<IRegisterable>().Register(facility.Register); facility.BuildFactory(DiagnosticLevel.None); Debug.WriteLine(chain.UniqueId); Debug.WriteLine(container.WhatDoIHave()); container.GetInstance<IEndPointAuthorizor>(chain.UniqueId.ToString()) .ShouldBeOfType<NulloEndPointAuthorizor>(); }
public void register_a_service_by_value() { var myContainer = new Container(); var myFacility = new StructureMapContainerFacility(myContainer); var registry = new TypeResolver(); myFacility.Register(typeof(ITypeResolver), new ObjectDef { Value = registry }); myFacility.BuildFactory(DiagnosticLevel.None); myContainer.GetInstance<ITypeResolver>().ShouldBeTheSameAs(registry); }
public void SetUp() { container = new Container(x => x.For<IFileSystem>().Use<FileSystem>()); graph = new FubuRegistry(x => { x.Route("/area/sub/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route("/area/sub2/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route("/area/sub3/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Models.ConvertUsing<ExampleConverter>().ConvertUsing<ExampleConverter2>(); x.Services(s => s.AddService<IActivator>(new StubActivator())); x.Services(s => s.AddService<IActivator>(new StubActivator())); x.Services(s => s.AddService<IActivator>(new StubActivator())); }).BuildGraph(); facility = new StructureMapContainerFacility(container); graph.As<IRegisterable>().Register(facility.Register); factory = facility.BuildFactory(DiagnosticLevel.None); }
public void SetUp() { container = new Container(x => { x.For<IFileSystem>().Use<FileSystem>(); x.For<IStreamingData>().Use(MockRepository.GenerateMock<IStreamingData>()); x.For<IHttpWriter>().Use(new NulloHttpWriter()); x.For<ICurrentChain>().Use(new CurrentChain(null, null)); x.For<ICurrentHttpRequest>().Use(new StubCurrentHttpRequest{ TheApplicationRoot = "http://server" }); x.For<IResourceHash>().Use(MockRepository.GenerateMock<IResourceHash>()); }); container.Configure(x => x.For<IContainerFacility>().Use<StructureMapContainerFacility>()); graph = BehaviorGraph.BuildFrom(x => { x.Route("/area/sub/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route("/area/sub2/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Route("/area/sub3/{Name}/{Age}") .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson(); x.Models.ConvertUsing<ExampleConverter>().ConvertUsing<ExampleConverter2>(); x.Services(s => s.AddService<IActivator>(new StubActivator())); x.Services(s => s.AddService<IActivator>(new StubActivator())); x.Services(s => s.AddService<IActivator>(new StubActivator())); }); facility = new StructureMapContainerFacility(container); graph.As<IRegisterable>().Register(facility.Register); factory = facility.BuildFactory(); }