Hello,
In Moq it's easy to set up property assignment behavior, for example:
In Typemock it's not even necessary to call an analog of SetupAllProperties:
With JustMock I can't find any method that would assign a property value on a mocked instance. The following code fails in assertion:
How do I need to configure property assignment?
Thanks in advance
In Moq it's easy to set up property assignment behavior, for example:
var monkey = new Mock<IMonkey>();
monkey.SetupAllProperties();
monkey.Object.Name = "Spike";
Assert.AreEqual("Spike", monkey.Object.Name);
In Typemock it's not even necessary to call an analog of SetupAllProperties:
var monkey = Isolate.Fake.Instance<IMonkey>();
monkey.Name = "Spike";
Assert.AreEqual("Spike", monkey.Name);
With JustMock I can't find any method that would assign a property value on a mocked instance. The following code fails in assertion:
var monkey = Mock.Create<IMonkey>();
Mock.ArrangeSet(() => { monkey.Name = "Spike"; });
monkey.Name = "Spike"; Assert.AreEqual("Spike", monkey.Name); // FAILS!
How do I need to configure property assignment?
Thanks in advance
6 Answers, 1 is accepted
0
Hello Vagif,
Thanks for asking such question. Here is how to setup property assignment using JustMock:
Now , Behavior.CallOriginal works in a way that if you dont setup any expectations using Mock.Arrange , by default it will invoke the original setter or getter .
Let me know if that is helpful.
Thanks for asking such question. Here is how to setup property assignment using JustMock:
var monkey = Mock.Create<IMonkey>(Behavior.CallOriginal);
monkey.Name =
"Spike"
;
Assert.AreEqual(monkey.Name,
"Spike"
);
Now , Behavior.CallOriginal works in a way that if you dont setup any expectations using Mock.Arrange , by default it will invoke the original setter or getter .
Let me know if that is helpful.
Additionally, in extreme case if you are calling any data source during property get / set [Extremely bad practice], the above solution will fail. Therefore, I will add an backing mock field for mocked properties so that you can also do the following , when you are not setting any expectation through Mock.Arrange:
var monkey = Mock.Create<IMonkey>();
// has a default backing field
monkey.Name =
"kuddus"
;
Assert.AreEqual(monkey.Name,
"kuddus"
);
This is a tiny change , i will hopefually patch it today so that it comes with upcoming build.
P.S: While I am editing this ticket, you might have got some extra notifications. Sorry for the inconvenience.
With Regards,
the telerik Team
0

Vagif
Top achievements
Rank 1
answered on 03 Aug 2010, 09:56 AM
Nope! Doesn't work this way. Here's the code:
IMonkey is an interface, there is no original implementation of it. Here's the message I get:
Test 'Zoo.Tests.JustMockTests.Properties' failed:
Expected: "Spike"
But was: null
JustMockTests.cs(35,0): at Zoo.Tests.JustMockTests.Properties()
In other words, with Moq, RhinoMocks and others I don't need to back up properties with any implementation: I configure mocked object to accept any property assignment and in case I retrieve the property value simply return the value I set. I haven't found a way of doing this in JustMock.
var monkey = Mock.Create<IMonkey>(Behavior.CallOriginal);
monkey.Name = "Spike";
Assert.AreEqual("Spike", monkey.Name); // FAILS!!!
IMonkey is an interface, there is no original implementation of it. Here's the message I get:
Test 'Zoo.Tests.JustMockTests.Properties' failed:
Expected: "Spike"
But was: null
JustMockTests.cs(35,0): at Zoo.Tests.JustMockTests.Properties()
In other words, with Moq, RhinoMocks and others I don't need to back up properties with any implementation: I configure mocked object to accept any property assignment and in case I retrieve the property value simply return the value I set. I haven't found a way of doing this in JustMock.
0
Hi Vagif,
Thanks again for the reply. Yes you are correct at this, this can only be done for class members. Therefore, expect an update in the coming build so that you can do the following:
Should you need a fixed build earlier, please open a separate support ticket and we'll send a patched version.
Sorry for the inconvenience.
Kind regards,
the Telerik team
Thanks again for the reply. Yes you are correct at this, this can only be done for class members. Therefore, expect an update in the coming build so that you can do the following:
var monkey = Mock.Create<
IMonkey
>();
// has a default backing field
monkey.Name = "Spike";
Assert.AreEqual(monkey.Name, "Spike");
Should you need a fixed build earlier, please open a separate support ticket and we'll send a patched version.
Sorry for the inconvenience.
Kind regards,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Vagif
Top achievements
Rank 1
answered on 03 Aug 2010, 11:42 AM
Thank you for the feedback.
I don't need an urgent fix for this. I am currently comparing different mock frameworks, and when comparing property management I noticed that JustMock was not as convenient as other frameworks that had auto-assignment feature built-in. I can wait for a regular release, hopefully it will not take long time.
Vagif
I don't need an urgent fix for this. I am currently comparing different mock frameworks, and when comparing property management I noticed that JustMock was not as convenient as other frameworks that had auto-assignment feature built-in. I can wait for a regular release, hopefully it will not take long time.
Vagif
0
Hi Vagif,
The build will be available next week. Thanks for your patience.
All the best,
Chris
the Telerik team
The build will be available next week. Thanks for your patience.
All the best,
Chris
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Jeff
Top achievements
Rank 1
answered on 17 Aug 2011, 04:08 PM
I saw that this issue was resolved in the public issue tracker, but is not scheduled until the next release in the fall. Is an internal build available to download so that I can test out this functionality?