我正在将我的测试移植到自动夹具2.0 http://autofixture.codeplex.com/,我遇到了一些奇怪的行为,我既无法解释也无法修复。这个简单的测试对我来说失败了:
var autoFixtures = new Fixture();
var file = autoFixtures.Build<File>()
.With(f => f.Name, "bleh.txt")
.CreateAnonymous();
Assert.That(file.Name, Is.EqualTo("bleh.txt")); // Fail?!
如果我改变,测试就会成功Name
到另一个财产File
,这让我认为我有某种定制Name
当我使用 AutoFixture 1.0 时,这不起作用。不过,我已经搜索了我的代码,但找不到类似的东西。
启用跟踪似乎没有多大帮助。
autoFixtures.Behaviors.Add(new TracingBehavior());
显示,除其他外:
Requested: System.String Name
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Created: Ploeh.AutoFixture.Kernel.NoSpecimen
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.String
Created: Ploeh.AutoFixture.Kernel.NoSpecimen
Requested: System.String
Created: 8a022fda-fa4e-49b7-b0c2-285fef765386
Created: Name8a022fda-fa4e-49b7-b0c2-285fef765386
Created: Name8a022fda-fa4e-49b7-b0c2-285fef765386
FWIW, Name
被声明为虚拟财产File
的基类,然后在File
像这样:
public abstract class Item
{
public virtual string Name { get; set; }
...
}
public class File : Item
{
public override string Name { get; set; }
...
}
如果有人对我可能尝试的事情有任何想法,或者我可能无意中自定义了某个地方的行为Name
财产,我将不胜感激!