本文整理汇总了C#中System.Factory.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.Create方法的具体用法?C# Factory.Create怎么用?C# Factory.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Factory
的用法示例。
在下文中一共展示了Factory.Create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FirstTest
public void FirstTest()
{
var carFactory = new Factory<Car>();
var planeFactory = new Factory<Plane>();
IProduct<Car> carProduct = carFactory.Create<Toyota>();
IProduct<Plane> planeProduct = planeFactory.Create<Boeing>();
carProduct.Operate();
planeProduct.Operate();
carProduct = carFactory.Create<Engine<Car>>();
carProduct.Operate();
}
示例2: CreateNew_ShouldInvokePassedCallbackWithNewEntity
public void CreateNew_ShouldInvokePassedCallbackWithNewEntity()
{
var factory = new Factory();
var entity = factory.Create<TestEntity>(e => e.Name = "Explicit Value");
Assert.Equal("Explicit Value", entity.Name);
}
示例3: CreateNew_ShouldCreateInstanceOfTypeParameter
public void CreateNew_ShouldCreateInstanceOfTypeParameter()
{
var factory = new Factory();
var entity = factory.Create<SimpleTestEntity>();
Assert.NotNull(entity);
Assert.IsAssignableFrom<SimpleTestEntity>(entity);
}
示例4: CreateNew_ShouldPopulatePrimatives_WhenNotUsingFactoryFunction
public void CreateNew_ShouldPopulatePrimatives_WhenNotUsingFactoryFunction()
{
var factory = new Factory();
factory.ValueObjects.RegisterFactoryFunction(() => "Expected");
var entity = factory.Create<TestEntity>();
Assert.Equal("Expected", entity.Name);
}
示例5: CreateNew_ShouldPassItselfToRegisteredFactoryMethod_WhenFactoryMethodWantsIt
public void CreateNew_ShouldPassItselfToRegisteredFactoryMethod_WhenFactoryMethodWantsIt()
{
Factory actual = null;
var factory = new Factory();
factory.Entities.RegisterFactoryFunction<TestEntity>((f) => { actual = f; return new TestEntity(); });
factory.Create<TestEntity>();
Assert.Same(factory, actual);
}
示例6: CreateNew_ShouldInvokePassedCallbackWithNewEntity_WhenEntityIsCreatedWithRegisteredFunction
public void CreateNew_ShouldInvokePassedCallbackWithNewEntity_WhenEntityIsCreatedWithRegisteredFunction()
{
var factory = new Factory();
factory.Entities.RegisterFactoryFunction(() => new TestEntity { Name = "Initial" });
var entity = factory.Create<TestEntity>(e => e.Name = "Explicit Value");
Assert.Equal("Explicit Value", entity.Name);
}
示例7: Main
static void Main(string[] args)
{
var factory = new Factory("MyApp", new MyLogger());
// Register the type.
factory.Type("MyType", typeof(MyType));
// Create an instance and pass in constructor arguments.
var myFactoryCreatedObject = factory.Create<MyType>("MyType", "Hello", "Computer");
Console.WriteLine(myFactoryCreatedObject.Message);
}
示例8: FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor
public FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor()
{
factory = new Factory();
entity = factory.Create<SimpleTestEntity>();
}
开发者ID:davidwalker,项目名称:GuineaPig,代码行数:5,代码来源:FactoryTests_PropertySetting_WhenCreatedWithDefaultCtor.cs
示例9: CreateNew_ShouldThrowMissingMethodException_WhenTypeHasNoDefaultCtorAndNoCustomCreateMethod
public void CreateNew_ShouldThrowMissingMethodException_WhenTypeHasNoDefaultCtorAndNoCustomCreateMethod()
{
var factory = new Factory();
var exception = Assert.Throws<MissingMethodException>(
() => factory.Create<SimpleTestEntityNoDefaultCtor>());
var expectedMessage = string.Format(
"Unable to create instance of {0} because the requested type does not define a parameterless constructor and no custom factory method was registered.",
typeof(SimpleTestEntityNoDefaultCtor).FullName);
Assert.Equal(expectedMessage, exception.Message);
}
示例10: CreateNew_ShouldStillUseRegisteredFactoryFunction_WhenTypeDoesNotHaveADefaultCtor
public void CreateNew_ShouldStillUseRegisteredFactoryFunction_WhenTypeDoesNotHaveADefaultCtor()
{
var factory = new Factory();
factory.Entities.RegisterFactoryFunction(() => new SimpleTestEntityNoDefaultCtor("a"));
var entity = factory.Create<SimpleTestEntityNoDefaultCtor>();
Assert.NotNull(entity);
}
示例11: CreateNew_ShouldUseRegisteredFactoryFunction
public void CreateNew_ShouldUseRegisteredFactoryFunction()
{
var expectedEntity = new SimpleTestEntity();
var factory = new Factory();
factory.Entities.RegisterFactoryFunction(() => expectedEntity);
var entity = factory.Create<SimpleTestEntity>();
Assert.Same(expectedEntity, entity);
}