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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:48:26+00:00 2026-05-30T00:48:26+00:00

I want to be able to compare the two following objects for likeness using

  • 0

I want to be able to compare the two following objects for likeness using AutoFixture.SemanticComparison:

public class Object1
{
  public int a;
}

public class Object2
{
  public int a;
  public int b;
}

Now, when I do it this way:

var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().ShouldEqual(o2);

I get the following exception: “The following members did not match: – b.”

I found out that I can omit the ‘b’ member like this:

var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().Without(object2 => object2.b).ShouldEqual(o2);

However, I find that this is quite cumbersome, because whenever I add a new member to class Object2, I have to correct my unit tests (or at least unit test helpers).

Is there a way to say “I want to compare for likeness just for the subset that exists in both objects”?

  • 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-30T00:48:29+00:00Added an answer on May 30, 2026 at 12:48 am

    It sounds like you’d like to compare two objects based on the intersection of their properties. This is not currently supported by the Likeness class. The reasoning is this:

    Right now the destination type (in the above example, that would be Object2) is the decisive template upon which matching is done. This provides quite a strong statement for an assertion: every public property or field of this class must be matched.

    However, a statement about matching the intersection of properties would be a very weak statement, because that intersection might be empty. This could result in False Negatives.

    Even if you are TDDing and following the Red/Green/Refactor cycle and you’ve seen a unit test failing with such a hypothetical Likeness intersection, subsequent refactorings might turn such an assertion into a False Negative, as you remove the last property or field the two objects have in common – and you’ll never notice.

    However, AutoFixture is open source and all, so you’re welcome to suggest this feature or send a pull request.

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

Sidebar

Related Questions

I need to compare two arrays. If I test if Object1==Object2 I am testing
I want to be able to compare two doubles disregarding a possible precision loss.
I have the following code: public class OMyObject { public int Id { get;
I want to convert two strings to ints to be able to compare them.
I want to be able to compare an image taken from a webcam to
I want to be able to read line by line from a pdf, compare
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects
Say that I have a rather large repository, and I want to compare two
Currently I have two larger vectors of 50+ strings I want to be able

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.