title: How to capture the setting of a property value with Mock (Moq)
body: <p>In my test project, I want to capture a property set by the SUT to a mocked object. I have tried many things, but none seem to allow me to capture that.</p>
  
  <p>I set up a short example:</p>
  
  <p>The mocked interface:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface ISomeInterface
  {
      string SomeProperty { get; set; }
  }
  </code></pre>
  
  <p>The SUT:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class SomeSystemUnderTest
  {
      public void AssignSomeValueToThis(ISomeInterface obj)
      {
          obj.SomeProperty = Guid.NewGuid().ToString();
      }
  }
  </code></pre>
  
  <p>The test:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestClass]
  public class SomeTests
  {
      [TestMethod]
      public void TestSomeSystem()
      {
          // Arrange
          var someInterfaceMock = new Mock&lt;ISomeInterface&gt;();
  
          someInterfaceMock.SetupSet(m =&gt; m.SomeProperty = It.IsAny&lt;string&gt;()).Verifiable();
  
          // Act
          var sut = new SomeSystemUnderTest();
          sut.AssignSomeValueToThis(someInterfaceMock.Object);
  
          // Assert
          // HERE I WOULD LIKE TO READ WHAT VALUE WAS ASSIGNED
          string myVal = someInterfaceMock.Object.SomeProperty;
      }
  }
  </code></pre>
  
  <p>The "myVal" variable stays null, and by examining the mock, we can see the property is still null. I did not really expected it to have some value, just trying.</p>
  
  <p>I tried with Setup, with a callback, I get compilation errors.</p>
  
  <p>In real life project, the SUT is to transform a mocked object property to something dependant to another object property. To know if the object is doing its job, I need to be able to read the property. Note, I cannot re-designed the mocked interfaces, they are 3rd party.</p>
  
  <p>I tried to use VerifySet, but it seems to take a hard-coded value only.</p>
  
  <p>Thank you,
  Michel</p>