2008-09-19 5 views
0

코드에 예외가있는 경우 일부 재시도 논리를 구현하려고합니다. 코드를 작성 했으므로 Rhino Mocks에서 시나리오를 시뮬레이션하려고합니다. 일어날 것으로 보인다 무엇Rhino mocks가 응답을 명령했으나 예외 예외가 발생했습니다.

class Program 
    { 
     static void Main(string[] args) 
     { 
      MockRepository repo = new MockRepository(); 
      IA provider = repo.CreateMock<IA>(); 

      using (repo.Record()) 
      { 
       SetupResult.For(provider.Execute(23)) 
          .IgnoreArguments() 
          .Throw(new ApplicationException("Dummy exception")); 

       SetupResult.For(provider.Execute(23)) 
          .IgnoreArguments() 
          .Return("result"); 
      } 

      repo.ReplayAll(); 

      B retryLogic = new B { Provider = provider }; 
      retryLogic.RetryTestFunction(); 
      repo.VerifyAll(); 
     } 
    } 

    public interface IA 
    { 
     string Execute(int val); 
    } 

    public class B 
    { 
     public IA Provider { get; set; } 

     public void RetryTestFunction() 
     { 
      string result = null; 
      //simplified retry logic 
      try 
      { 
       result = Provider.Execute(23); 
      } 
      catch (Exception e) 
      { 
       result = Provider.Execute(23); 
      } 
     } 
    } 

예외가 매번 대신 한번의 슬로우됩니다 있다는 것입니다 : 코드의 JIST은 다음과 같다. 설정을 변경하려면 어떻게해야합니까?

답변