1

If I will use dynamic mock and try to use a property that is not set up, it will simply return default(null) for this property.

I need the same behaviour in Partial Mock only for one property. I need that this property return null. (property should be not virtual)

For example:

public abstract class SomeClass
{ 
    public XmlDocument SomeProperty     
    {   
     get { return _someProperty ?? (_someProperty = SomeMethod()); } 
    //this getter should return null in my case and doesn't call SomeMethod
    }
}


[Test]
public void SomeTest()
{
    //Arrange
    var obj = MockRepository.GeneratePartialMock<SomeClass>();

    //Act
    obj.Act(); // this method will use SomeProperty

    //Assert
    ...
}
lol
  • 23
  • 3
  • Why property shouldn't be virtual? property is syntactic sugar for getter/setter methods in C#.... (just to emphasize my point; usually `DbContext` properties in EntityFramework are virtual...). The answer to you question is you can't achieve this behaviour using only `RhinoMocks`.(unless you'll change the signature of the property to virtual) – Old Fox Dec 05 '15 at 10:09
  • I cannot change property, because I cover old functionality, and it will be bad practice to change access modifiers or other modifiers of existing functionality for tests. – lol Dec 05 '15 at 10:17
  • Well your last argument isn't true; to be able to UT methods the code should be design as a testable code(you can read about it any where in SO or just google it...). I think the [chart in this answer](http://stackoverflow.com/a/31899094/4332059) might help you. – Old Fox Dec 05 '15 at 18:01
  • 1
    Rhino mocks can't mock non-virtual methods or properties, see: http://stackoverflow.com/questions/342989/rhino-mocks-setting-up-results-for-non-virtual-methods – Amittai Shapira Dec 06 '15 at 06:56

0 Answers0