2016-03-10 4 views
0

Предположим, что у меня есть методMS Подделки: Проставки с заданным входом

public void SomeFunction (int a) 
{ 
    return AnotherFunction (a + 1); 
} 

Есть ли способ, чтобы Призонная шайба AnotherFunction с определенными параметрами? Я думаю о чем-то вроде:

using (ShimContext.Create()) 
{ 
    ShimMyClass.AnotherFunctionInt = (3) => 34; // return 34 if the given value is 3 
    ShimMyClass.AnotherFunctionInt = (4) => 44; // return 44 if the given value is 4 
    ShimMyClass.AnotherFunctionInt = (a) => 22; // default value 
} 

ответ

1

Просто добавьте код к вашему переопределению вместо возврата жестко заданного значения. Что-то вроде

[TestMethod] 
    public void SimpleTest() 
    { 
     TestUnitTestClass tutClass = new TestUnitTestClass(); 
     using (ShimsContext.Create()) 
     { 
      ShimTestUnitTestClass shimClass = new ShimTestUnitTestClass(tutClass); 
      shimClass.AnotherFunctionInt32 = (val) => 
      { 
       if (val == 3) 
        return 34; 

       if (val == 4) 
        return 44; 

       return 22; 
      }; 

      int curInt = tutClass.AnotherFunction(3); 
      Console.WriteLine(curInt); 
     } 
    } 

 Смежные вопросы

  • Нет связанных вопросов^_^