How to make fun of a property without a setter?

I am trying to mock the interface. The property I want to set to "MockThisProperty" has no setter. I cannot change the source of the interface. The error I get is this

Previous method 'IThirdPartyInterface.get_MockThisProperty ();' requires a return or exception for throw.

I tried DynamicMock, Strictmock, partial layout, etc.

When I try to execute SetupResult.For (thirdParty.MockThisProperty = mockedValue) will not compile because there is no setter.

using the latest nocturnal rhinos with mstest

In descending order, here is the code ...

var stuff = _Mockery.Stub<Hashtable>(); matchItem.Add(key, "Test"); var thirdParty = _Mockery.Stub<IThirdPartyInterface>(); SetupResult.For(thirdParty.MockThisProperty).Return(stuff); _Mockery.BackToRecordAll(); //more code _Mockery.ReplayAll(); Assert.IsTrue(MethodToTest(thirdParty)); _Mockery.VerifyAll(); 
+4
source share
1 answer

This worked for me:

 var thirdParty = Rhino.Mocks.MockRepository.GenerateStub<IThirdPartyInterface>(); thirdParty.Stub(x => x.MockThisProperty).Return("bar"); string mockPropertyValue = thirdParty.MockThisProperty; //returns "bar" 
+7
source

Source: https://habr.com/ru/post/1385713/


All Articles