我将我的测试移植到AutoFixture 2.0,我遇到了一些我无法解释或修复的奇怪行为。这个简单的测试对我来说失败了:
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
属性的行为,我将不胜感激!