I have a unit test that creates a mocked instance of a class and arranges some of its properties. The test then executes some extension methods of that class.
When I run the test under visual studio 2017 (JustMock 2019.1.207.1) my tests pass. When I run the same test using the VsTest v2 build task the test fails due to an unarranged mock on the class which corresponds to a call of an extension method.
The code looks something like :
public
class
Person {
public
string
Name {
get
; }
}
public
static
PersonExtensions {
public
int
NameLength(
this
Person person) {
return
person.Name.Length;
}
}
var fakePerson = Mock.Create<Person>(Behavoir.Strict);
Mock.Arrange(() => fakePerson.Name).Returns(
"Toto"
):
var expected = 4;
var actual = fakePerson.NameLength();
// <--- exception here
// ...etc.
First strange thing is the test works in visual studio but on the build server.
Second strange thing is the exception says I have declared a strict mock on the PersonExtensions static class :
Telerik.JustMock.Core.StrictMockException: Called unarranged member 'Int32 NameLength(Person)' on strict mock of type 'PersonExtensions'<
br
>at Telerik.JustMock.Core.Behaviors.StrictBehavior.Process(Invocation invocation)
at Telerik.JustMock.Core.MocksRepository.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
at PersonExtensions.NameLength(Person person)...
If I could reproduce the error in visual studio it would be easier to find a way around it, I will probably do some CallOriginal arranges on the extension methods of the class.
Have you any ideas ?
Thanks,
Rob