moq - Should Mock<SomeClassType>.SetupAllProperties() cause properties to return the values they are assigned? -


when use setupallproperties on mock, works expected:

/// <summary> /// demos setupallproprties on interface.  seems work fine. /// </summary> [test] public void demo_setupallproperties_foraninterface() {     var mock = new mock<iaddress>();      mock.setupallproperties();     var stub = mock.object;     stub.city = "blahsville";      var retrievedcity = stub.city;     assert.areequal("blahsville", retrievedcity); } 

however, when try on class, fails:

/// <summary> /// demos setupallproprties on class.  seems work fine mocking interfaces, not classes.  :(  accessor returns null after setting property. /// </summary> [test] public void demo_setupallproperties_foraclass() {     var mock = new mock<address>();      mock.setupallproperties();     var stub = mock.object;     stub.city = "blahsville";      var retrievedcity = stub.city;     assert.areequal("blahsville", retrievedcity); } 

did wrong? trying unsupported moq?

for measure, here iaddress interface , address class:

public interface iaddress {     string city { get; set; }     string state { get; set; }     void somemethod(string arg1, string arg2);     string getformattedaddress(); }  public class address : iaddress {     #region iaddress members     public virtual string city { get; set; }     public virtual string state { get; set; }     public virtual string getformattedaddress()     {         return city + ", " + state;     }      public virtual void somemethod(string arg1, string arg2)     {         // blah!     }     #endregion } 

i copied code new project not reproduce problem. set breakpoint in demo_setupallproperties_foraclass() @ assert.areequal line , retrievedcity did have value "blahsville".

i using xunit, don't think make difference. version of moq using? using 4.0.10510.6.


Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -