本文整理汇总了C#中Builder.BuildUp方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.BuildUp方法的具体用法?C# Builder.BuildUp怎么用?C# Builder.BuildUp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.BuildUp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCreateInstances
public void CanCreateInstances()
{
string config =
@"<object-builder-config xmlns=""pag-object-builder"">
<build-rules>
<build-rule type=""" + FullNameSimpleObject + @""" mode=""Instance"">
<constructor-params>
<value-param type=""System.Int32"">12</value-param>
</constructor-params>
</build-rule>
</build-rules>
</object-builder-config>";
Builder builder = new Builder(ObjectBuilderXmlConfig.FromXml(config));
Locator locator = CreateLocator();
SimpleObject m1 = builder.BuildUp<SimpleObject>(locator, null, null);
SimpleObject m2 = builder.BuildUp<SimpleObject>(locator, null, null);
Assert.IsNotNull(m1);
Assert.IsNotNull(m2);
Assert.AreEqual(12, m1.IntParam);
Assert.AreEqual(12, m2.IntParam);
Assert.IsTrue(m1 != m2);
}
示例2: TestBuildUp
public void TestBuildUp()
{
var builder = new Builder<Car>();
var car = builder.BuildUp();
Assert.IsNotNull(car);
Assert.AreEqual<int>(2 + 1, car.Log.Count);
Assert.AreEqual<string>(car.Log[2],"wheel");
}
示例3: EmptyBuilderWillCreateAnyValueTypeWithDefaultValue
public void EmptyBuilderWillCreateAnyValueTypeWithDefaultValue()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
int actual = builder.BuildUp<int>(locator, null, null);
Assert.AreEqual(default(int), actual);
}
示例4: EmptyBuilderWillCreateSimpleInstances
public void EmptyBuilderWillCreateSimpleInstances()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
SimpleObject o = builder.BuildUp<SimpleObject>(locator, null, null);
Assert.IsNotNull(o);
Assert.AreEqual(0, o.IntParam);
}
示例5: EmptyBuilderWillCreateComplexInstances
public void EmptyBuilderWillCreateComplexInstances()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
ComplexObject o = builder.BuildUp<ComplexObject>(locator, null, null);
Assert.IsNotNull(o);
Assert.IsNotNull(o.SimpleObject);
Assert.AreEqual(default(int), o.SimpleObject.IntParam);
}
示例6: BuilderWithNoStrategiesThrowsWhenBuilding
public void BuilderWithNoStrategiesThrowsWhenBuilding()
{
string config =
@"<object-builder-config xmlns=""pag-object-builder"">
<strategies include-default=""false"" />
</object-builder-config>";
Builder builder = new Builder(ObjectBuilderXmlConfig.FromXml(config));
Locator locator = CreateLocator();
builder.BuildUp<object>(locator, null, null);
}
示例7: BuilderCanTakeTransientPolicies
public void BuilderCanTakeTransientPolicies()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
PolicyList policies = new PolicyList();
PropertySetterPolicy policy = new PropertySetterPolicy();
policy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter<int>(96)));
policies.Set<IPropertySetterPolicy>(policy, typeof(PropertyObject), null);
PropertyObject obj = builder.BuildUp<PropertyObject>(locator, null, null, policies);
Assert.AreEqual(96, obj.IntProp);
}
示例8: CanAddPoliciesToBuilder
public void CanAddPoliciesToBuilder()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
ConstructorPolicy policy = new ConstructorPolicy();
policy.AddParameter(new ValueParameter<int>(12));
builder.Policies.Set<ICreationPolicy>(policy, typeof(MockObject), null);
MockObject obj = builder.BuildUp<MockObject>(locator, null, null);
Assert.IsNotNull(obj);
Assert.AreEqual(12, obj.IntValue);
}
示例9: CanCreateInterceptedObjectInOBChain
public void CanCreateInterceptedObjectInOBChain()
{
Builder builder = new Builder();
InterceptableClass instance
= (InterceptableClass)builder.BuildUp(null,
null,
CreatePolicyList(GetInjectionSettings(), true),
baseStrategyChain.MakeStrategyChain(),
NamedTypeBuildKey.Make<InterceptableClass>(string.Empty),
null);
Assert.IsNotNull(instance);
Assert.IsTrue(RemotingServices.IsTransparentProxy(instance));
}
示例10: RegularInstanceIsReturnedWhenInterceptionIsSwitchedOf
public void RegularInstanceIsReturnedWhenInterceptionIsSwitchedOf()
{
Builder builder = new Builder();
InterceptableClass instance
= (InterceptableClass)builder.BuildUp(null,
null,
CreatePolicyList(new PolicyInjectionSettings(), true),
baseStrategyChain.MakeStrategyChain(),
NamedTypeBuildKey.Make<InterceptableClass>(string.Empty),
null);
Assert.IsNotNull(instance);
Assert.IsFalse(RemotingServices.IsTransparentProxy(instance));
}
示例11: CanCreateConcreteObjectByAskingForInterface
public void CanCreateConcreteObjectByAskingForInterface()
{
string config =
@"<object-builder-config xmlns=""pag-object-builder"">
<build-rules>
<build-rule type=""" + FullNameISimpleObject + @""" mode=""Instance"">
<mapped-type type=""" + FullNameSimpleObject + @""" />
</build-rule>
</build-rules>
</object-builder-config>";
Builder builder = new Builder(ObjectBuilderXmlConfig.FromXml(config));
Locator locator = CreateLocator();
ISimpleObject sm = builder.BuildUp<ISimpleObject>(locator, null, null);
Assert.IsNotNull(sm);
Assert.IsTrue(sm is SimpleObject);
}
示例12: CanInjectMultiplePropertiesIncludingCreatedObjects
public void CanInjectMultiplePropertiesIncludingCreatedObjects()
{
string config =
@"<object-builder-config xmlns=""pag-object-builder"">
<build-rules>
<build-rule type=""" + FullNameSimpleObject + @""" mode=""Instance"">
<constructor-params>
<value-param type=""System.Int32"">15</value-param>
</constructor-params>
</build-rule>
<build-rule type=""" + FullNameComplexObject + @""" mode=""Instance"">
<property name=""StringProperty"">
<value-param type=""System.String"">Bar is here</value-param>
</property>
<property name=""SimpleObject"">
<ref-param type=""" + FullNameSimpleObject + @""" />
</property>
</build-rule>
</build-rules>
</object-builder-config>";
Builder builder = new Builder(ObjectBuilderXmlConfig.FromXml(config));
Locator locator = CreateLocator();
ComplexObject co = builder.BuildUp<ComplexObject>(locator, null, null);
Assert.IsNotNull(co);
Assert.IsNotNull(co.SimpleObject);
Assert.AreEqual("Bar is here", co.StringProperty);
Assert.AreEqual(15, co.SimpleObject.IntParam);
}
示例13: TransientPoliciesOverrideBuilderPolicies
public void TransientPoliciesOverrideBuilderPolicies()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
PolicyList policies = new PolicyList();
PropertySetterPolicy builderPolicy = new PropertySetterPolicy();
builderPolicy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter<int>(11)));
builder.Policies.Set<IPropertySetterPolicy>(builderPolicy, typeof(PropertyObject), null);
PropertySetterPolicy transientPolicy = new PropertySetterPolicy();
transientPolicy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter<int>(22)));
policies.Set<IPropertySetterPolicy>(transientPolicy, typeof(PropertyObject), null);
PropertyObject obj = builder.BuildUp<PropertyObject>(locator, null, null, policies);
Assert.AreEqual(22, obj.IntProp);
}
示例14: SingletonPolicyBasedOnConcreteTypeRatherThanRequestedType
public void SingletonPolicyBasedOnConcreteTypeRatherThanRequestedType()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Foo), null), typeof(IFoo), null);
builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true));
object obj1 = builder.BuildUp(locator, typeof(IFoo), null, null);
object obj2 = builder.BuildUp(locator, typeof(IFoo), null, null);
Assert.AreSame(obj1, obj2);
}
示例15: CanMapTypesWithDefaultObjectBuilder
public void CanMapTypesWithDefaultObjectBuilder()
{
Builder builder = new Builder();
Locator locator = CreateLocator();
TypeMappingPolicy policy = new TypeMappingPolicy(typeof(MockObject), null);
builder.Policies.Set<ITypeMappingPolicy>(policy, typeof(IMockObject), null);
IMockObject obj = builder.BuildUp<IMockObject>(locator, null, null);
Assert.IsTrue(obj is MockObject);
}