Note that there are some explanatory texts on larger screens.

plurals
  1. PORhino mock mocking with complex object as parameter in a method
    primarykey
    data
    text
    <p>I have this scenario</p> <pre class="lang-cs prettyprint-override"><code>public class ParamObject { public int Prop1 {get; set} public int Prop2 {get; set} public int Prop3 {get; set} public int Prop4 {get; set} } public class Respository: IRepository { public string GetSomething(ParamObject myParameter) { return string.Format("Hello {0}, {1}, {2}, {3}}!", myParameter.Prop1, myParameter.Prop2, myParameter.Prop3, myParameter.Prop4) ; } } public class MyController { public void MyMethodInMyController(IRepository myRepo) { ParamObject paramObject = new ParamObject(); paramObject.Prop1 = 1; paramObject.Prop2 = 2; paramObject.Prop3 = 3; paramObject.Prop4 = 4; Console.WriteLine(myRepo.GetSomething(paramObject)); } } [TestMethod] public void Testing() { mocker = new MockRepository(); mockRepository = mocker.DynamicMock&lt;IRepository&gt;(); mockRepository .Expect(m =&gt; m.GetSomething(Arg&lt;ParamObject&gt;.Matches(p =&gt; p.Prop1 == 1 &amp;&amp; p.Prop2 == 2 &amp;&amp; p.Prop3 == 3 &amp;&amp; p.Prop4 == 4))) .Return("Bye!"); mocker.ReplyAll(); MyController myController = new MyController(); Assert.AreEqual(myController.MyMethodInMyController(mockRepository), "Bye!"); } </code></pre> <p>As you can see, I want to test <em>MyMethodInMyController</em> but it requires a call to a method with a complex object as parameter</p> <p>My test doesn't work and doesn't return an exception, just it stops when calling the method in the call from <em>MyMethodInMyController</em></p> <p>How can I mock this kind of methods which requires a complez object as parameter?</p> <p>Thanks in advance!</p> <p>Note I can't do the mock as</p> <pre class="lang-cs prettyprint-override"><code> mockRepository .Expect(new ParamObect(value1, value2, ....) .Return("Bye!"); </code></pre> <p>because the parameters are different objects and don't match.</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.
    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