Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not using your mock objects correctly. When you are using mock objects you meant to be testing how your code interacts with other objects without actually using the real objects. See the code below:</p> <pre><code>using Moq; using NUnitFramework; namespace MyNameSpace { [TestFixture] public class MyClassTests { [Test] public void TestGetSomeString() { const string EXPECTED_STRING = "Some String!"; Mock&lt;IDependance&gt; myMock = new Mock&lt;IDependance&gt;(); myMock.Expect(m =&gt; m.GiveMeAString()).Returns("Hello World"); MyClass myobject = new MyClass(); string someString = myobject.GetSomeString(myMock.Object); Assert.AreEqual(EXPECTED_STRING, someString); myMock.VerifyAll(); } } public class MyClass { public virtual string GetSomeString(IDependance objectThatITalkTo) { return objectThatITalkTo.GiveMeAString(); } } public interface IDependance { string GiveMeAString(); } } </code></pre> <p>It doesn't look like it is doing anything useful when your code is just returning a string without any logic behind it. </p> <p>The real power comes if you <code>GetSomeString()</code> method did some logic that may change the result of the output string depending on the return from the <code>IDependdance</code> .<code>GiveMeAString()</code> method, then you can see how your method handles bad data being sent from the <code>IDependdance</code> interface. </p> <p>Something like:</p> <pre><code> public virtual string GetSomeString(IDependance objectThatITalkTo { if (objectThatITalkTo.GiveMeAString() == "Hello World") return "Hi"; } </code></pre> <p>Now if you have this line in your test:</p> <pre><code>myMock.Expect(m =&gt; m.GiveMeAString()).Returns(null); </code></pre> <p>What will happen to your <code>GetSomeString()</code> method?</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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