我刚刚写了几篇单元测试,令我恐惧的是它失败了。
这是我的测试…
[TestMethod]
public void FetchWithMoreThanOneConditionUsingKnownTypes()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient() { FirstName = "Rohan", Surname = "West" };
var entity = scope.Extent<ClientEntity>().Where(c => temp.FirstName == c.FirstName && temp.Surname == c.Surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}
它给出以下异常,无法将“Entities.Testing.TempClient”类型的对象强制转换为“System.String”类型。这是正常的吗,我希望不是,下面的测试工作正常。我想解析表达式时有问题…这个会修好吗?
[TestMethod]
public void FetchWithMoreThanOneConditionUsingTempVariables()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient(){ FirstName = "Rohan", Surname = "West" };
string firstname = temp.FirstName;
string surname = temp.Surname;
var entity = scope.Extent<ClientEntity>().Where(c => c.FirstName == firstname && c.Surname == surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}