I am trying to perform a unit test controller action that uses a membership provider to update user data. I use Moq, which so far has been easy to use.
The problem is that I can't get him to make fun of calls to methods that return nothing.
<TestMethod()> _ Public Sub Can_Update_User() ' Arrange _membershipService.Setup(Function(x) x.UpdateUser(It.IsAny(Of MembershipUser))) Dim controller As New UsersController(_membershipService.Object, _roleProvider.Object, _supportWorksService.Object, _portalClientService.Object) ' Act Dim result As ViewResult = controller.Edit("testUser", New FormCollection) ' Assert Assert.AreEqual("Index", result.ViewName) End Sub
Configuring a wearing membership service will not compile, error:
Overload error, because there is no accessible "Setup" you can call using these arguments:
'Public function Customization (from TResult) (expression As System.Linq.Expressions.Expression (From System.Func (From Services.IMembershipService, TResult))) As Moq.Language.Flow.ISetup (From Services.IMembershipService, TResult)' : expression does not produce value.
'Setting public functions (from TResult) (expression As System.Linq.Expressions.Expression (From System.Func (From Services.IMembershipService, TResult))) As Moq.Language.Flow.ISetup (From Services.IMembershipService, TResult)' : data type (s) of type parameter cannot be inferred from these arguments. Specifying a data type can explicitly fix this error.
'Public function Customization (expression As System.Linq.Expressions.Expression (From System.Action (From Services.IMembershipService))) As Moq.Language.Flow.ISetup (From Services.IMembershipService)': The expression does not give a value.
What did I miss? Should I create a fake class and not use Moq anytime my class has a method that I want to call?
Edit:
Well, a little reading around suggests that this is due to how lambdas are expressed in VB using Function (), which should have a result.
Has anyone found a job for this, or will I have to cut Moq for fake methods?