Note that there are some explanatory texts on larger screens.

plurals
  1. POPartial mocking - expectations being ignored (Rhino Mocks)
    primarykey
    data
    text
    <p>I am trying to test a class similar to the example below:</p> <pre><code>public class Service : IService { public string A(string input) { int attemptCount = 5; while (attemptCount &gt; 0) { try { return TryA(input); } catch (ArgumentOutOfRangeException) { attemptCount--; if (attemptCount == 0) { throw; } // Attempt 5 more times Thread.Sleep(1000); } } throw new ArgumentOutOfRangeException(); } public string TryA(string input) { // try actions, if fail will throw ArgumentOutOfRangeException } } [TestMethod] public void Makes_5_Attempts() { // Arrange var _service = MockRepository.GeneratePartialMock&lt;Service&gt;(); _service.Expect(x=&gt;x.TryA(Arg&lt;string&gt;.Is.Anything)).IgnoreArguments().Throw(new ArgumentOutOfRangeException()); // Act Action act = () =&gt; _service.A(""); // Assert // Assert TryA is attempted to be called 5 times _service.AssertWasCalled(x =&gt; x.TryA(Arg&lt;string&gt;.Is.Anything), opt =&gt; opt.Repeat.Times(5)); // Assert the Exception is eventually thrown act.ShouldThrow&lt;ArgumentOutOfRangeException&gt;(); } </code></pre> <p>The partial mocking doesn't seem to accept my expectation. When I run the test I receive an error about the input. When I debug, I see that the actual implementation of the method is being executed instead of the expectation.</p> <p>Am I doing this test correctly? According to the documentation ( <a href="http://ayende.com/wiki/Rhino%20Mocks%20Partial%20Mocks.ashx" rel="nofollow">http://ayende.com/wiki/Rhino%20Mocks%20Partial%20Mocks.ashx</a> ): "A partial mock will call the method defined on the class unless you define an expectation for that method. If you have defined an expectation, it will use the normal rules for this." </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload