Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单元测试:检查在测试中传递给方法的表达式_C#_Nunit_Rhino Mocks - Fatal编程技术网

C# 单元测试:检查在测试中传递给方法的表达式

C# 单元测试:检查在测试中传递给方法的表达式,c#,nunit,rhino-mocks,C#,Nunit,Rhino Mocks,我目前正在研究如何最好地测试下面的代码段,在这里,通过使用不同的表达式调用相同的方法 if (boolResult) { service.Update( x => x.Id == newId && x.Version == version, x => new Foo { FooId = newId, OtherProp = otherValue })

我目前正在研究如何最好地测试下面的代码段,在这里,通过使用不同的表达式调用相同的方法

if (boolResult)
{
    service.Update(
        x => x.Id == newId && x.Version == version,
        x => new Foo
        {
            FooId = newId,
            OtherProp = otherValue
        });
}
else if (some other scenario)
{
    service.Update(x => x.Id == newId,
        x => new Foo
        {
            FooId = newId
        });
}
在单元测试中,我想断言
service.Update
调用是使用预期的表达式运行的。我希望实现的目标如下:

//set up the expressions
Expression<Func<Foo, bool>> expression = x => x.Id == newId && x.Version <= newVersion;
Expression<Func<Foo, Foo>> updateExpression = x => new Foo
{
    Id = newId,
    OtherProp = otherValue
};

//assert
m_service.AssertWasCalled(x => x.Update(Arg<Expression<Func<Foo, bool>>>.Is.Equal(expression), Arg<Expression<Func<Foo, Foo>>>.Is.Equal(updateExpression)));
//设置表达式
Expression=x=>x.Id==newId&&x.Version新Foo
{
Id=newId,
OtherProp=otherValue
};
//断言
调用m_service.assertwas(x=>x.Update(Arg.Is.Equal(表达式),Arg.Is.Equal(updateExpression));
这样做失败了,但是想知道这种方法是否正确,以及如何最好地检查是否已将正确的表达式传递到函数中。
注意,在测试中,
m_服务
是一个
MockRepository.GenerateMock()

不验证被测装置的内部构件;而是验证其效果

一个表达式执行另一个表达式不执行的操作:它更新另一个属性。验证此属性是否已更新