Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 915589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:54:49+00:00 2026-05-15T17:54:49+00:00

I have a function that updates a user in the asp.net membership provider. <AcceptVerbs(HttpVerbs.Post)>

  • 0

I have a function that updates a user in the asp.net membership provider.

<AcceptVerbs(HttpVerbs.Post)>
Public Function EnableUser(ByVal id As String) As JsonResult
  Dim usr As StargatePortalUser = _membershipService.GetUser(id, Nothing)
  usr.IsApproved = True
  _membershipService.UpdateUser(usr)
  Dim response As New AjaxResponse(usr.UserName)
  Return Json(response)
End Function

I am trying to test this function to ensure the IsApproved property is set correctly

<TestMethod()>
Public Sub Service_Can_Enable_A_User_Account()
  ' Arrange
  Dim usr As New Mock(Of MembershipUser)
  usr.SetupProperty(Function(u) u.IsApproved)

  _membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)

  Dim target As New UsersController(_membershipService.Object)
  target.ControllerContext = New ControllerContext(FakeAuthenticatedHttpContext("testuser", String.Empty, True, True, False), New RouteData, target)

  ' Act
  Dim actual As JsonResult = target.EnableUser("userId")

  ' Assert
  Assert.IsTrue(DirectCast(actual.Data, AjaxResponse).Success)
  _membershipService.Verify(Sub(m) m.UpdateUser(It.IsAny(Of MembershipUser)), Times.Once)
  usr.Verify(Function(u) u.IsApproved = True)
End Sub

When I try to verify that the IsApproved property has been set to True an exception is returned:

System.ArgumentException: Expression is not a method invocation: u => (u.IsApproved == True)

There are so few examples of using Moq in VB that I can’t figure this out, any help would be appreciated.

This is an ASP.NET MVC2 app in VB.NET 10 (.NET 4.0)

EDIT:

Ok, turns out it’s not quite so straight forward in VB.

usr.Verify(Function(u) u.IsApproved = True)

needs to be

usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))

and you need to add the following function:

Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
  target = value
  Return value
End Function

FURTHER EDIT:

Thinking around the problem I arrived at a more simple solution. I changed

Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)

for

Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
Dim usrObj = usr.Object
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usrObj)

and then can replace

usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))

with the more straightforward

Assert.IsTrue(usrOb.IsApproved)

Sometimes I just don’t see the simple solution 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:54:50+00:00Added an answer on May 15, 2026 at 5:54 pm

    You want to use the following (from http://code.google.com/p/moq/wiki/QuickStart):

    // or verify the setter directly
    mock.VerifySet(foo => foo.Name = “foo”);

    Right now the thing that you’re feeding in is a comparison rather than an assignment, so even if Moq did process the statement without an exception, it would still not be Doing What You Mean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model function that updates a user in my CodeIgniter application: //
I have an ASP.Net UpdatePanel that updates on a timer. Within the UpdatePanel and
I have a function that updates several tables. As an example, let's say it
Inside my Controller i have function that runs after user clicks on item, which
So I'm using ASP.NET with C#. And I have an item that is queried
I have an asp.net web application (c#) in visual studio 2010 that is heavily
I have a ListView in an ASP.NET web application. When a user clicks the
I have an ASP.Net MVC 3 application that uses a jQuery .ajax call to
I have a function that does a long task and I want to update
I have a function that's called hundreds of thousands of times per update, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.