문제

나를 구현하기 위해 노력하고 일부는 다시 시도 논리가 있을 경우에는 예외가 나의 코드입니다.내가 쓰는 코드는 지금은 나가려고 코뿔소를 조롱하여 시뮬레이션 시나리오이다.이 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);
            }
        }
    }

무슨 일어날 것 같은 예외가 발생됩 할 때마다 대신적인 용도로만 인쇄할 수 있습니다.나는 무엇을 해야 변경 설정을 할 수?

도움이 되었습니까?

해결책

를 사용해야 합니다.전화 대신 SetupResult:

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

        Expect.Call(provider.Execute(23))
                   .IgnoreArguments()
                   .Return("result");
    }

Rhino.Mocks wiki 말

사용 SetupResult.()를 위한 완전히 무시하 기대가 모델에서 Rhino Mocks

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top