0

単体テストの実行で、メソッドをモックするのに間違いがありました。入力するパラメーターに応じて異なる結果を返そうとしていますが、それ以外の場合はデフォルトの回答を返します。問題は、常にデフォルトの回答を受け取っていることです。

_commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .WithAnyArguments().WillReturn(-1);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("",false,null))
            .With("BAG1", true, FamilyFaresType.Optima).WillReturn(0);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .With("BAG2", true, FamilyFaresType.Optima).WillReturn(87);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .With("BAG3", true, FamilyFaresType.Optima).WillReturn(139);
4

1 に答える 1

1

エラーは行の順序にあります。この行は、デフォルトの "WithAnyArguments" が、引数 "With" を持つ定義の後にある必要があることを返します。

            _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("",false,null))
            .With("BAG1", true, FamilyFaresType.Optima).WillReturn(0);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .With("BAG2", true, FamilyFaresType.Optima).WillReturn(87);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .With("BAG3", true, FamilyFaresType.Optima).WillReturn(139);
        _commonFunctionsMock.Expects.AtLeastOne.Method(x => x.GetFeePrice("", false, null))
            .WithAnyArguments().WillReturn(-1);
于 2014-08-07T08:53:51.887 に答える