Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using Rhino Mocks, you could set an expectation for the property. This basically states that you expect the property to be set to a certain value. Using your example, an example test method body would be this:</p> <p> var mock = MockRepository.GenerateMock(); mock.Expect(x => x.Property1 = "Test");</p> <pre><code>var classUnderTest = new ClassUnderTest(mock); classUnderTest.MethodUnderTest(); mock.VerifyAllExpectations(); </code></pre> <p>This would check to see if <code>Property1</code> had been set to "Test" at some point between the call to <code>mock.Expect</code> and the call to <code>mock.MethodUnderTest</code> (technically, <code>Property1</code> could be set in the constructor of <code>ClassUnderTest</code>).</p> <p>In order to test that the property was set and ignore what it was actually set to, just chain <code>IgnoreArguments</code> to the return of the <code>Expect</code> call, like so:</p> <p> mock.Expect(x => x.Property1 = "Test1").IgnoreArguments();</p> <p>One way to test more complex write-only properties is to use the <code>GetArgumentsForCallsMadeOn</code> method. This allows you to retrieve a list of the arguments passed to each "call" of the property. The code to do this would be like the following:</p> <p> var mock = MockRepository.GenerateMock();</p> <pre><code>var classUnderTest = new ClassUnderTest(mock); classUnderTest.MethodUnderTest(); //the argument in the Action is ignored, so just use null //Property1 is of type List&lt;string&gt; var arguments = mock.GetArgumentsForCallsMadeOn(x =&gt; x.Property1 = null); //arguments[0] contains the list of arguments for the first "call" of the //property the first index (0) of that would contain the first argument var firstCallArguments = arguments[0]; var firstArgument = (List&lt;string&gt;)firstCallArguments[0]; Assert.AreEqual(3, firstArgument.Count); </code></pre> <p>I am sure that Moq has similar functionality if you'd like to use that, instead.</p>
    singulars
    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.
 

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