示例#1
0
        public void SetUp()
        {
            string xml =
                @"
<StructureMap Id='Generics'>
  <Assembly Name='StructureMap.Testing.GenericWidgets'/>

  <PluginFamily Assembly='StructureMap.Testing.GenericWidgets' Type='StructureMap.Testing.GenericWidgets.IThing`2' DefaultKey='Red'>
    <Plugin Assembly='StructureMap.Testing.GenericWidgets' Type='StructureMap.Testing.GenericWidgets.ColorThing`2' ConcreteKey='Color' />
    <Plugin Assembly='StructureMap.Testing.GenericWidgets' Type='StructureMap.Testing.GenericWidgets.ComplexThing`2' ConcreteKey='Complex' />

    <Instance Key='Red' Type='Color'>
      <Property Name='color' Value='Red'/>
    </Instance>

    <Instance Key='Complicated' Type='Complex'>
      <Property Name='name' Value='Jeremy' />
      <Property Name='age' Value='32' />
      <Property Name='ready' Value='true' />
    </Instance>
  </PluginFamily>

  <PluginFamily Assembly='StructureMap.Testing.GenericWidgets' Type='StructureMap.Testing.GenericWidgets.ISimpleThing`1' DefaultKey='Simple'>
    <Plugin Assembly='StructureMap.Testing.GenericWidgets' Type='StructureMap.Testing.GenericWidgets.SimpleThing`1' ConcreteKey='Simple' />
  </PluginFamily>
  
</StructureMap>
";

            PluginGraph graph = DataMother.BuildPluginGraphFromXml(xml);

            manager = new Container(graph);
        }
示例#2
0
        public void SetUp()
        {
            string xml =
                @"
<StructureMap MementoStyle='Attribute'>
  <DefaultInstance PluginType='StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget' PluggedType='StructureMap.Testing.Widget.ColorWidget,StructureMap.Testing.Widget' color='Red' />  
  <DefaultInstance PluginType='StructureMap.Testing.Widget.Rule,StructureMap.Testing.Widget' PluggedType='StructureMap.Testing.Widget.ColorRule,StructureMap.Testing.Widget' color='Blue' Scope='Singleton' Key='TheBlueOne'/>  
</StructureMap>
";

            _graph   = DataMother.BuildPluginGraphFromXml(xml);
            _manager = new Container(_graph);
        }
示例#3
0
        private Container buildContainer()
        {
            PluginGraph pluginGraph =
                DataMother.BuildPluginGraphFromXml(
                    @"
<StructureMap>
	<Assembly Name='StructureMap.Testing.Widget'/>
	<Assembly Name='StructureMap.Testing.Widget5'/>
	
	<PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey='Money'>
		<Source Type='XmlFile' FilePath='FullTesting.XML' XPath='Widgets' NodeName='Widget'/>
		<Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='NotPluggable'/>
	</PluginFamily>

	<PluginFamily Type='StructureMap.Testing.Widget.Rule' Assembly='StructureMap.Testing.Widget' DefaultKey='Blue'>
		<Instance Key='Bigger' Type='GreaterThan'>
			<Property Name='Attribute' Value='MyDad' />
			<Property Name='Value' Value='10' />
		</Instance>
		<Instance Key='Blue' Type='Color'>
			<Property Name='color' Value='Blue' />
		</Instance>
		<Instance Key='Red' Type='Color'>
			<Property Name='color' Value='Red' />
		</Instance>
	</PluginFamily>

	<PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''>
		<Source Type='XmlFile' FilePath='GridColumnInstances.xml' XPath='//GridColumns' NodeName='GridColumn'/>
		<Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'>
			<Setter Name='ColumnName' />
			<Setter Name='FontStyle' />
			<Setter Name='Rules' />
			<Setter Name='Widget' />
			<Setter Name='WrapLines' />
		</Plugin>
	</PluginFamily>
	
	<Instances/>
</StructureMap>


");


            return(new Container(pluginGraph));
        }
示例#4
0
        public void Log_241_when_a_designated_setter_does_not_exist()
        {
            string errorXml =
                @"
                <StructureMap>
	                <PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''>
		                <Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'>
			                <Setter Name='ReadOnly' />
		                </Plugin>
	                </PluginFamily>
                </StructureMap>
                ";


            PluginGraph graph = DataMother.BuildPluginGraphFromXml(errorXml);

            graph.Log.AssertHasError(240);
        }
示例#5
0
        public void read_instance_from_xml_with_optional_setter_not_defined()
        {
            Debug.WriteLine(typeof(ClassWithDependency).AssemblyQualifiedName);

            PluginGraph graph =
                DataMother.BuildPluginGraphFromXml(
                    @"
<StructureMap MementoStyle='Attribute'>
    <DefaultInstance 
        PluginType='StructureMap.Xml.Testing.ClassWithDependency, StructureMap.Xml.Testing' 
        PluggedType='StructureMap.Xml.Testing.ClassWithDependency, StructureMap.Xml.Testing'>

    </DefaultInstance>
</StructureMap>

");

            var container = new Container(graph);

            container.GetInstance <ClassWithDependency>().Rule.ShouldBeNull();
        }
        public void read_instance_from_xml_with_optional_setter_defined()
        {
            Debug.WriteLine(typeof(ClassWithDependency).AssemblyQualifiedName);

            PluginGraph graph =
                DataMother.BuildPluginGraphFromXml(
                    @"
<StructureMap MementoStyle='Attribute'>
    <DefaultInstance 
        PluginType='StructureMap.Testing.Pipeline.ClassWithDependency, StructureMap.Testing' 
        PluggedType='StructureMap.Testing.Pipeline.ClassWithDependency, StructureMap.Testing'>
        
        <Rule PluggedType='StructureMap.Testing.Widget.ColorRule, StructureMap.Testing.Widget' color='Red' />
    </DefaultInstance>
</StructureMap>

");

            var container = new Container(graph);

            container.GetInstance <ClassWithDependency>().Rule.IsType <ColorRule>().Color.ShouldEqual("Red");
        }
        public void BuildsInterceptionChain()
        {
            PluginGraph pluginGraph =
                DataMother.BuildPluginGraphFromXml(
                    @"
<StructureMap>
	<PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''>
		<Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='NotPluggable'/>
	</PluginFamily>
	
	<PluginFamily Type='StructureMap.Testing.Widget.Rule' Assembly='StructureMap.Testing.Widget' DefaultKey='Blue'>
		<Interceptors>
			<Interceptor Type='Singleton'></Interceptor>
		</Interceptors>
	</PluginFamily>
</StructureMap>
");

            pluginGraph.FindFamily(typeof(Rule)).Lifecycle.ShouldBeOfType(typeof(SingletonLifecycle));

            // The PluginFamily for IWidget has no intercepters configured
            pluginGraph.FindFamily(typeof(IWidget)).Lifecycle.ShouldBeNull();
        }
        private void assertErrorIsLogged(int errorCode, string xml)
        {
            PluginGraph graph = DataMother.BuildPluginGraphFromXml(xml);

            graph.Log.AssertHasError(errorCode);
        }