3 Answers, 1 is accepted
0
Hi Rob,
Thanks again for the bringing up the question. To mock private methods, you can take a look at the following link from online documentation that has quite a bit example to check out:
http://www.telerik.com/help/justmock/advanced-usage-mocking-non-public-members-and-types.html
Please let us know if you still having problems.
Kind Regards,
Ricky
the Telerik team
Thanks again for the bringing up the question. To mock private methods, you can take a look at the following link from online documentation that has quite a bit example to check out:
http://www.telerik.com/help/justmock/advanced-usage-mocking-non-public-members-and-types.html
Please let us know if you still having problems.
Kind Regards,
Ricky
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
Chris
Top achievements
Rank 1
answered on 03 Jun 2011, 03:28 PM
I have the same issue as above. The problem I am having is that I am not mocking the private method but I am using the MSTest private accessor object in order to call the private method I am testing. The mocked objects are public here is some code to illustrate the issue.
When I call the ProcessIncomingMessage method I expect that StoreMessages and ClearBuffers are mocked, yet it goes and executes those methods as if they were not mocked.
Thank you in advance.
///<summary>
/// A test for ProcessIncomingMessage
///</summary>
[DataSource(
"Microsoft.VisualStudio.TestTools.DataSource.XML"
,
"|DataDirectory|\\incoming.xml"
,
"Event"
, DataAccessMethod.Sequential), DeploymentItem(
"TestResources\\Unified\\incoming.xml"
), TestMethod]
public
void
ProcessIncomingMessageTest()
{
var expectedTower = TestContext.DataRow[
"Tower"
].ToString();
var expectedEventDescription = TestContext.DataRow[
"EventDescription"
].ToString().TrimStart(
'\r'
,
'\n'
,
' '
);
expectedEventDescription = expectedEventDescription.TrimEnd(
' '
,
'\n'
,
'\r'
,
'\0'
);
var rawDataToUse = Convert.FromBase64String(TestContext.DataRow[
"RawData"
].ToString());
var target =
new
UnifiedProtocolTranslator_Accessor();
// TODO: Initialize to an appropriate value
bool
called;
Mock.Arrange(() => target.StoreMessages(Arg.IsAny<
byte
[]>(), Arg.AnyInt)).IgnoreArguments().DoInstead((
byte
[] arg1,
int
arg2) => called =
true
).MustBeCalled();
Mock.Arrange(()=> target.ClearBuffers()).DoNothing().MustBeCalled();
bool
expected =
true
;
// TODO: Initialize to an appropriate value
bool
actual;
actual = target.ProcessIncomingMessage(rawDataToUse, rawDataToUse.Length);
Assert.AreEqual(expected, actual);
Mock.Assert(target);
}
When I call the ProcessIncomingMessage method I expect that StoreMessages and ClearBuffers are mocked, yet it goes and executes those methods as if they were not mocked.
Thank you in advance.
0
Hi Chris,
Kind Regards,
Mehfuz
the Telerik team
Thanks for sending the issue. At this point, i would like to ask if StoreMessages and ClearBuffers are internal methods or these have been already invoked somewhere else (other test method) in the test class that you have used in the lines below:
Mock.Arrange(() => target.StoreMessages(Arg.IsAny<
byte
[]>(), Arg.AnyInt)).IgnoreArguments().DoInstead((
byte
[] arg1,
int
arg2) => called =
true
).MustBeCalled();
Mock.Arrange(()=> target.ClearBuffers()).DoNothing().MustBeCalled();
Kind Regards,
Mehfuz
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