I have a unit test that is attempting to test a very simple method. The method under test simply calls two other methods (interface methods that are marked as virtual in the implementation). I use the following code in the unit test....
The Target method is....
and here is the mocking setup....
The problem is the test says that expected called once but was called 0 times. What I see when I debug the code is that my passedMessage variable goes from a byte array to some other type of object (goes from saying byte[16] to count = 0 after the first method is called.
Any thoughts?
IEnumerable<
byte
> passedMessage1 =
new
byte
[16];
Mock.Arrange(() => MessageOperationsMock.InsertNetworkAddressIntoMessage
(Target.PrimaryReportingAddress, passedMessage1, 3))
.DoNothing()
.Returns(passedMessage1)
.OccursOnce();
Mock.Arrange(() => MessageOperationsMock.InsertNetworkAddressIntoMessage
(Target.AlternateReportingAddress, passedMessage1, 25))
.DoNothing()
.Returns(passedMessage1)
.OccursOnce();
Target.PrimaryReportingAddress = LocalTestScenarios.TestIPAddress1;
Target.AlternateReportingAddress = LocalTestScenarios.TestIPAddress2;
Target.InsertNetworkAddressesIntoPart(passedMessage1);
Mock.Assert(MessageOperationsMock);
The Target method is....
internal
virtual
IEnumerable<
byte
> InsertNetworkAddressesIntoPart(IEnumerable<
byte
> messageBeingCreated)
{
messageBeingCreated = MessageOperationsHelper.InsertNetworkAddressIntoMessage(PrimaryReportingAddress, messageBeingCreated, 3);
messageBeingCreated = MessageOperationsHelper.InsertNetworkAddressIntoMessage(AlternateReportingAddress, messageBeingCreated, 25);
return
messageBeingCreated;
}
and here is the mocking setup....
protected
HardCodedMonitoringSettingsEntity Target;
protected
IDependencyInjection InjectorMock;
protected
IValidationOperations ValidatorMock;
protected
IMessageOperations MessageOperationsMock;
[SetUp]
public
void
InitializeBase()
{
Target = Mock.Create<HardCodedMonitoringSettingsEntity>(Behavior.CallOriginal);
InjectorMock = Mock.Create<IDependencyInjection>();
ValidatorMock = Mock.Create<IValidationOperations>();
MessageOperationsMock = Mock.Create<IMessageOperations>();
Target.DependencyInjector = InjectorMock;
Target.ValidationOperationsHelper = ValidatorMock;
Target.MessageOperationsHelper = MessageOperationsMock;
}
The problem is the test says that expected called once but was called 0 times. What I see when I debug the code is that my passedMessage variable goes from a byte array to some other type of object (goes from saying byte[16] to count = 0 after the first method is called.
Any thoughts?