我正在将我的测试移植到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-285fef765386Name被声明为File基类的虚拟属性,然后在File中被覆盖:
public abstract class Item
{
public virtual string Name { get; set; }
...
}
public class File : Item
{
public override string Name { get; set; }
...
}如果有人对我可能尝试的东西有任何想法,或者我可能无意中定制了Name属性的行为,我将不胜感激!
发布于 2011-01-11 06:02:51
您刚刚在AutoFixture 2.0中发现了一个错误。我现在已经解决了这个问题,并将更改推送到存储库(changeset 3efe812aecd1),所以如果您download the latest source并编译它,它应该可以工作。
如果你感兴趣,它与一个虚拟属性被一个子类重写有关-显然我不经常做的事情。
很抱歉有个bug。如果问题还没有解决,或者您有其他问题,请告诉我。
https://stackoverflow.com/questions/4650424
复制相似问题