我正在尝试针对某些 EF4 对象编写一些 Mspec 测试。然而,他们正在返回误报。我不知道这是我编写测试的方式还是发生了其他事情。测试类如下:
[Subject(typeof (Product))]
public class When_loading_a_known_product
{
protected static Product product;
protected static ProductDbContext dbContext;
Establish context = () =>
{
dbContext = new ProductDbContext(ConnectionStringProvider.GetConnectionString(BusinessDomain.Product));
};
Because of = () =>
{
product = dbContext.Products.First(x => x.Id == 2688);
};
// The next four tests should be false but all pass ( the actual count is 4 for the given record)
It should_have_a_known_number_of_Classifications = () => product.Classifications.Count().Equals(9999);
It should_have_a_known_number_of_Classifications2 = () => product.Classifications.Count().Equals(1);
It should_have_a_known_number_of_Classifications3 = () => product.Classifications.Count().Equals(-99);
It should_have_a_known_number_of_Classifications4 = () => product.Classifications.Count().Equals(4.5);
//
}
在 Nunit 中编写的相同测试可以正常工作。
[Test]
public void It_should_have_a_known_number_of_Classifications()
{
private ProductDbContext dbContext = new ProductDbContext(ConnectionStringProvider.GetConnectionString(BusinessDomain.Product));;
Product product = dbContext.Products.Find(2688);
// true
Assert.That(product.Classifications.Count(), Is.EqualTo(4));
// All of these will correctly regester as false
//Assert.That(product.Classifications.Count(), Is.EqualTo(9999));
//Assert.That(product.Classifications.Count(), Is.EqualTo(1));
//Assert.That(product.Classifications.Count(), Is.EqualTo(-99));
//Assert.That(product.Classifications.Count(), Is.EqualTo(4.5));
}
作为 EF4 和 MSpec 的新手,我希望有人能指出我的错误。