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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:10:56+00:00 2026-05-22T23:10:56+00:00

I have Equals method that I am trying to tests. this method return true

  • 0

I have Equals method that I am trying to tests. this method return true if object passed to is is same as this object.

I test true condition as following.

        var mocks = new MockRepository();
        var mockActionAlert = mocks.StrictMock<ActionAlert>();
        var mockActionAlert2 = mocks.StrictMock<ActionAlert>();
        bool comparer = mockActionAlert.Equals(mockActionAlert2);
        Assert.Equal(true, comparer);

However, how can I get a different mock object to test that equal method returns false.

Thank You,

  • 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-22T23:10:57+00:00Added an answer on May 22, 2026 at 11:10 pm

    What you have shown doesn’t appear to make any sense at all.

    You only have mocks in your test code – no real implementations at all.

    Not only are you not testing anything real, but since you are using mocks, your can even decide whether your pretend tests should fail or not.

    To do what (I think) you want, simply create an ActionAlert (one from you real code, not a mock of one) and then create a second ActionAlert with properties that should make it equal using your Equals method. Pass the second ActionAlert in and assert that the result is true (Probably best to use Assert.True() since that is more expressive of intent).

    Then when testing that the Equals method returns false, write tests with ActionAlerts with properties that make them not equals. No need for mocks at all.

    The place where you need mocks is where you have depenendencies in your classes under test that you want to either assert some behaviour on (has a dependence method been called in a certain way) or you want some predifined behaviour from (make a method return a certain value when called).

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

Sidebar

Related Questions

I have always thought that the .equals() method in java should be overridden to
Let's say that you have overridden an object's equals() and hashCode() methods, so that
All the generated webservice-stubs from our backend have an equals-method similar to this one:
I have a method that looks similar to the following: public void myMethod(MyClass c)
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
I have a Word.Field object which is a checkbox and the Type property equals
I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
is it ok if i have this X project using .net2.0, and that X
I have a generic class called Repository. This class has a function that calls
I have the following expression in linq (its a join) and i am selecting

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.