我刚写了一些单元测试,我的恐惧失败。
这里是我的测试...
[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);
}
}