我有一个类具有另一种类类型的属性:
public class MyClass
{
public DepdendenceClass DependenceProp { get; set; }
private MyClass(){}
public MyClass(MyClassFactory factory)
{
this.DependenceProp = factory.DependenceProp;
}
}
public class DepdendenceClass
{
public int key { get; set; }
private DepdendenceClass() { }
public DepdendenceClass(DepdendenceClassFactory factory)
{
this.key = factory.key;
}
}
我隐藏了基本构造函数,因为我不希望它可以创建空实例
每个都有一个流利的有序构造函数,让我编写这个测试:
[Test]
public void MyClassConstructorTest()
{
DepdendenceClass depdendencePropExpected = DepdendenceClassFactory.InitCreation()
.WithKey(1)
.Create();
MyClass myClassActual = MyClassFactory.InitCreation()
.WithDependency(depdendencePropExpected)
.Create();
Assert.That(myClassActual.DependenceProp, Is.EqualsTo(depdendencePropExpected));
}
有没有办法将 MyClassConstructor Test 与第二类的构造函数隔离开来?