【发布时间】:2011-01-10 19:03:58
【问题描述】:
我正在将我的测试移植到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 属性的行为,我将不胜感激!
【问题讨论】:
标签: autofixture