Thank you for coming back to us.
As I can understand from your first reply, you are trying to fake datum. Unfortunately this is not possible in JustMock, neither in other mocking tools. What our product is expected to do is to fake
an object by mocking
: You create a fake class, so that you can comfortably arrange the new behavior of its functionality, or methods.
However, as I noted above, mocking or faking datum
is not directly allowed. Nevertheless, there are ways and principles in programming that can permit you, fake the value of a certain variable. One of them, I would recommend, is the using of a property, that is acting directly with your private member variable. Having such, you can easily mock its get
function, so that it returns
a certain data.
Let`s assume you are having this "SomeClass" class.
_myProperty = 123;
._myProperty = value; }
As you can see there is a member variable "_myProperty", that is taking its value inside the constructor. The mandatory here is that, we have a property "MyProperty", that can show or change the variable`s value. From now on, it is good to use 'MyProperty', instead of "_myProperty", to cover the rest of "SomeClass" functional logic. If we continue to the testing part, you will notice that, now it is very easy to fake the whole behavior of our class:
var mock = Mock.Create<SomeClass>();
Mock.Arrange(() => mock.MyProperty).Returns(321);
var actualValue = mock.MyProperty;
var origValue = mock._myProperty;
As for your second concern, I must say that you are right. Having a private setter won`t let you fake the returning value. You will need a private property with both get
functions, or atleast with a getter
, so that you can arrange that function to return the desired value, the same way, as you are arranging methods for example:
Note that, you will need to specify the property type ("<IEventAggregator>
") first. Then you have to point the previously mocked class/interface ("foo") with its property/method you would like to arrange against ("EventAggregator"). Finally you need to fake its get
function, so that it returns your "fakeEA
", instead of the original value (".Returns(fakeEA)
I hope you will find this information useful and it will lead you to solving you issue. Please, let me know if I can be helpful with anything else.
the Telerik team