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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:32:51+00:00 2026-05-30T11:32:51+00:00

I have a simple class: public class MyClass() { public string Property1 {get;set;} public

  • 0

I have a simple class:

public class MyClass()
{
  public string Property1 {get;set;}
  public string Property2 {get;set;}
}

Is there any way to asssert two instances of this class for equality without Equal method implementation (I guess reflection could suit well here)? I don’t want to implement Equal just for tests).

  • 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-30T11:32:52+00:00Added an answer on May 30, 2026 at 11:32 am

    See this excerpt from the official documentation:
    https://fluentassertions.com/introduction

    You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the Convert class). As an example, consider a Customer entity from some arbitrary domain model and its DTO counterpart CustomerDto. You can assert that the DTO has the same values as the entity using this syntax:

    dto.ShouldHave().AllProperties().EqualTo(customer);
    

    As long as all properties of dto are also available on customer, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the ID property:

    dto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer);
    

    Which is equivalent to:

    dto.ShouldHave().AllProperties().But(d => d.Id).EqualTo(customer);
    

    The other way around is also possible. So if you only want to include two specific properties, use this syntax.

    dto.ShouldHave().Properties(d => d.Name, d => d.Address).EqualTo(customer);
    

    And finally, if you only want to compare the properties that both objects have, you can use the SharedProperties() method like this:

      dto.ShouldHave().SharedProperties().EqualTo(customer);
    

    Obviously, you can chain that with a But() method to exclude some of the shared properties.

    Additionally, you can take structural comparison a level further by including the IncludingNestedObjects property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested properties of the subject match the nested properties of the expected object. However, if you do specify SharedProperties, then it will only compare the equally named properties between the nested objects. For instance:

    dto.ShouldHave().SharedProperties().IncludingNestedObjects.EqualTo(customer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class like this: public class myClass { public List<string> innerList;
If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)
I have a: public class MyClass { private string PrivateString; } and I have
I have a simple object: [DataContract] public class MyClass { [DataMember(Name = MyClassNo)] public
I have the simple class using auto-implemented properies: Public Class foo { public foo()
For example I have a simple class like public class Person{ public int Age
All, I have a simple class. public class Container : UserControl { public bool
I have a simple Java class that has some methods: public class Utils {
I have this very simple C++ class: class Tree { public: Node *head; };
Suppose I have the following (trivially simple) base class: public class Simple { public

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.