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.
///<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.