Please see the narrowed down code-example below.
What I expect is the method IsElf() to return a value of TRUE.
When I debug the UnitTest, mensMock.Leeftijd returns a value of 11. When I look at the value of actual, it's value = false???
It seems that the Mock object is not 'routing' the call as expected...
When I use the Behaviour.CallOriginal setting (which is not documented BTW) when Creating the Mock everything works as expected. Loose and Strict mode both fail.
I really like your concept of mocking, could you please tell me what I'm doing wrong?
Kind regards from Holland & TIA,
Ronald.
----
What I expect is the method IsElf() to return a value of TRUE.
When I debug the UnitTest, mensMock.Leeftijd returns a value of 11. When I look at the value of actual, it's value = false???
It seems that the Mock object is not 'routing' the call as expected...
When I use the Behaviour.CallOriginal setting (which is not documented BTW) when Creating the Mock everything works as expected. Loose and Strict mode both fail.
I really like your concept of mocking, could you please tell me what I'm doing wrong?
Kind regards from Holland & TIA,
Ronald.
----
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
using PatrickMocks;
namespace PatrickMocks
{
public class Mens
{
public int Leeftijd { get; set; }
public virtual bool IsElf()
{
// this.Foo();
return (this.Leeftijd == 11);
}
public virtual void Foo()
{
this.Leeftijd++;
this.Leeftijd--;
}
}
}
namespace MockTest
{
[TestClass()]
public class MensTest
{
[TestMethod()]
public void IsElfTest()
{
// Arrange
Mens mensMock = Mock.Create<PatrickMocks.Mens>();
//Mens mensMock = Mock.Create<PatrickMocks.Mens>(Behavior.CallOriginal); //<== THIS WORKS OK!!!
Mock.Arrange(() => mensMock.Foo()).CallOriginal().MustBeCalled();
// Act
bool expected = true; // TODO: Initialize to an appropriate value
bool actual = true;
mensMock.Leeftijd = 11;
actual = mensMock.IsElf();
// Assert
Assert.AreEqual(expected, actual);
Mock.Assert(mensMock); // Check dat deze method gedraaid heeft!
}
}
}