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 431901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:01:15+00:00 2026-05-12T20:01:15+00:00

Using NUnit and NMock2 I was not able to compare what I thought were

  • 0

Using NUnit and NMock2 I was not able to compare what I thought were the same SqlParameters:

SqlParameter param1 = new SqlParameter("@Id", 1);
SqlParameter param2 = new SqlParameter("@Id", 1);
Assert.IsTrue(param1.Equals(param2));  // This failed

I stumbled across this problem, when trying to test an execution of a method using NMock2

[Test]
    public void UpdateComments()
    {
        const int arbitraryId = 1;
        Comment comment = new Comment();

        SqlParameter idParam = new SqlParameter("@ChangeId", arbitraryId);

        Expect.Once.On(mockSqlDao).Method("ExecuteNonQuery")
              .With("usp_Update_Comment", idParam);

        changeDao.UpdateComment(arbitraryId, comment);

        mocks.VerifyAllExpectationsHaveBeenMet();
    }

I received this error:

NMock2.Internal.ExpectationException: unexpected invocation of sqlDao.ExecuteNonQuery(“usp_Update_Comment”, )
Expected:
1 time: sqlDao.ExecuteNonQuery(equal to “usp_Update_Comment”, equal to <@ChangeId>) [called 0 times]

Questions:

  • How do you test with NMock2 when you
    expected Parameter is SqlParameter?
  • How do you compare equality of two SqlParameters?
  • 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-12T20:01:15+00:00Added an answer on May 12, 2026 at 8:01 pm

    Because .Equals() is using the default implementation of Equals as far as I know (which means that a SqlParameter will only “equal” another SqlParameter if they are the same object), you will need to directly interrogate the properties of the parameter to ensure the correct data is being passed.

    The Has.Property call within .With allows you to check the properties of a parameter without requiring that a parameter equals some other value. Try the following:

    Expect.Once.On(mockSqlDao).Method("ExecuteNonQuery")
              .With("usp_Update_Comment", Has.Property("ParameterName").EqualTo("@Id") & 
                                          Has.Property("Value").EqualTo(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Nunit, I want to be able to write a test fixture that will
When using NUnit and the test project, we haven't been able to find a
Using NUnit 2.5 in VS 2008, i'm not sure how to test that a
I am using NUnit for unit testing (running with TD.NET). When using Assert.DoesNotThrow, i
I'm new to unit testing using nunit (and Java development in general). When creating
I am new to the Unit Testing And using Nunit i dont know how
Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why?
Using nUnit to test the output (currency formatting) for a specific culture but we
When using NUnit, I can turn off shadow copy so that my test assemblies
I am currently using NUnit and testing a class library. Up until now, I

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.