I have been trying to mock a shared method and Isolator has been throwing an ArgumentException when it executes.
My method returns only a boolean value:
Public Shared Function IsUserInRole(userid as long, role as Role) as Boolean
Here is my test method:
<Test> _
<Isolated> _
Public Sub Authenticate_IsValidUser_Success()
Dim objUser As UserEntity = FakeInstance(Of UserEntity)()
objUser.IsActive = True
objUser.IsRegistered = True
Dim mock As MockObject = MockManager.MockObject(GetType(IAuthenticationService))
mock.ExpectAndReturn("ValidateLogin", objUser)
Dim auth As IAuthenticationService = mock.Object
FakeSharedMethods(Of RoleService)(Members.MustSpecifyReturnValues)
Using TheseCalls.WillReturn(True)
RoleService.IsUserInRole(0, Role.Student)
End Using
Dim user As UserEntity = New AuthenticationService(auth).Authenticate("testuser", "testuser1", Role.Student)
MockManager.Verify()
End Sub
I have been scratching my head trying to figure out this one, and I've determined that the source is the multiple parameter static function. If I change my
IsUserInRole function to take only a single parameter, the test will pass.
The funny thing is, when I run the test with the 2 parameter method in debugger mode, I try to step through and find the error, but the test passes!
Any ideas on what could be causing the issue?
here is the error I am getting:
TestCase 'Tests.AuthenticationServiceTests.Authenticate__ValidUser_Success'
failed: System.ArgumentException : Method 'Void Authenticate__ValidUser_Success()' is not defined for type 'System.Object'
at System.Linq.Expressions.Expression.ValidateCallInstanceType(Type instanceType, MethodInfo method)
at System.Linq.Expressions.Expression.ValidateCallArgs(Expression instance, MethodInfo method, ReadOnlyCollection`1& arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at e4.c()
at e4.a()
at e4.b()