public void BuildWithCustomProfileAndAvalonComponentConfiguration() { String contents = "<container>" + " <components baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <component lifestyle=\"singleton\" key=\"mail\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Avalon.IMailServer\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Avalon.MailServer2\"> " + " <configuration>" + " <port>1001</port>" + " <server>mailserver</server>" + " </configuration>" + " </component>" + " </components>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); ContainerBuilder builder = new ContainerBuilder(); IContainer container = builder.Build( profile ); IMailServer mailServer = (IMailServer) container.Resolve( typeof(IMailServer) ); AssertNotNull( mailServer ); AssertEquals( 1001, mailServer.Port ); AssertEquals( "mailserver", mailServer.Server ); }
public void BuildFromStringWithBaseAssembly() { String contents = "<container>" + " <components baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <component key=\"a\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.IService\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.DefaultService\"> " + " <configuration>" + " </configuration>" + " </component>" + " </components>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); AssertProfileComponent(profile); }
public void BuildFromStringWithFacilities() { String contents = "<container>" + " <facilities baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <facility key=\"myfacility\" type=\"Apache.Avalon.Castle.Windsor.Test.Component.Facility.MyFacility\" />" + " </facilities>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); AssertNotNull( profile ); AssertEquals( 1, profile.Facilities.Length ); IFacilityProfile facility = profile.Facilities[0]; AssertNotNull( facility ); AssertEquals( "myfacility", facility.Key ); AssertEquals( typeof(MyFacility), facility.Implementation ); }
public void BuildWithCustomProfileAndOverridedComponentSettings() { String contents = "<container>" + " <components baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <component lifestyle=\"singleton\" key=\"a\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.IService\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.DefaultService\"> " + " <configuration>" + " </configuration>" + " </component>" + " </components>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); ContainerBuilder builder = new ContainerBuilder(); IContainer container = builder.Build( profile ); IService service1 = (IService) container.Resolve( typeof(IService) ); IService service2 = (IService) container.Resolve( typeof(IService) ); AssertNotNull( service1 ); AssertNotNull( service2 ); Assert( Object.ReferenceEquals(service1, service2) ); }
public void BuildFromStringWithSubsystems() { String contents = "<container>" + " <subsystems baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <subsystem key=\"configuration\" type=\"Apache.Avalon.Castle.Windsor.Test.Component.Subsystem.MySubSystem\" />" + " </subsystems>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); AssertNotNull( profile ); AssertEquals( 1, profile.SubSystems.Length ); ISubSystemProfile subsystem = profile.SubSystems[0]; AssertNotNull( subsystem ); AssertEquals( "configuration", subsystem.Key ); AssertEquals( typeof(MySubSystem), subsystem.Implementation ); }
public void BuildFromStringWithNestedContainers() { String contents = "<container>" + " <components baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <component key=\"a\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.IService\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.DefaultService\"> " + " <configuration>" + " </configuration>" + " </component>" + " </components>" + "" + " <container>" + " <components baseAssembly=\"Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\">" + " <component key=\"a\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.IOtherService\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.DefaultOtherService\"> " + " <configuration>" + " </configuration>" + " </component>" + " </components>" + " </container>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); AssertProfileComponent(profile); AssertEquals( 1, profile.SubContainers.Length ); profile = profile.SubContainers[0]; AssertProfileComponent( profile, "a", typeof(IOtherService), typeof(DefaultOtherService) ); }
public void BuildFromStringWithLifestyleAndActivationOverride() { String contents = "<container>" + " <components>" + " <component key=\"a\" lifestyle=\"singleton\" activation=\"start\" service=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.IService,Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\" " + " implementation=\"Apache.Avalon.Castle.Windsor.Test.Component.Simple.DefaultService,Apache.Avalon.Castle.Windsor.Test, Version=1.0.0.0\"> " + " <configuration>" + " </configuration>" + " </component>" + " </components>" + "</container>"; IContainerProfile profile = new XmlProfileBuilder().Build(contents); IComponentProfile component = profile.ComponentProfiles[0]; AssertEquals( Lifestyle.Singleton, component.Lifestyle ); AssertEquals( Activation.Start, component.Activation ); }