2008-09-19 79 views
0

我想实现一些重试逻辑,如果我的代码中有异常。我编写了代码,现在我试图让Rhino Mocks模拟这种情况。代码的JIST如下:犀牛嘲笑有序回复,抛出异常问题

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); 
      } 
     } 
    } 

有什么事发生的是,异常被抛出每次而不是只一次。我应该怎样改变设置?

回答