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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:09:20+00:00 2026-06-10T17:09:20+00:00

In FluentAssertions I can use the AllProperties.But(obj => obj.property_I_do_not_want) to remove specific properties from

  • 0

In FluentAssertions I can use the AllProperties.But(obj => obj.property_I_do_not_want) to remove specific properties from a comparison assertion which is fine when I know the names of the properties I want to ignore but in my situation I only want to ignore unitialized properties. For now I would be willing to just ignore one’s equal to null but if there’s a solution that also excludes primitives set to their default values that would be extra handy.

I started out be trying to write an extension method for the PropertyAssertions class but can’t figure out how to create an IEnumerable<Expression<T>> that includes an Expression<T> for accessing each property to ignore to pass to the But method.

  • 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-06-10T17:09:21+00:00Added an answer on June 10, 2026 at 5:09 pm

    If you’re willing to try the 2.0 beta, you can use a lambda in the new ShouldBeEquivalentTo() API to exclude certain properties like this:

    subject.ShouldBeEquivalentTo(expected, options =>
        options.Excluding(ctx => ctx.PropertyPath == "Level.Level.Text"));
    

    If you want, you can even encapsulate this in a custom rule (a class implementing ISelectionRule) like this:

    subject.ShouldBeEquivalentTo(expected, options => 
        options.Using(new ExcludeUninitializedProperties()));
    

    In fact, you could even make this the default for particular types by overriding the factory method that creates the initial options:

    EquivalencyAssertionOptions<TSubject>>.Default = () =>    
        EquivalencyAssertionOptions<TSubject>>.Default.Using(new ExcludeUninitializedProperties())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FluentAssertions nuget package for 1.7 seems to be missing the references for System.Xml and
FluentAssertions seems to fail with NullReferece exception when I try comparing two collections with
I have two objects (instances of the same class) with a bunch of properties,
I would like to combine Fluent Assertion's collection assertions and property assertions, e.g. assert
I'm starting using Fluent Assertions and I like it a lot, but wonder if
Reading about MSTest and NUnit I couldn't really decide what to use in my
I'm trying to mock an Excel spreadsheet using NSubstitute or other mocking framework and
I have an event and a raising method as below : public class Events
After a previous question on stackoverflow regarding async / await it seemed to me
Update 1, more details My question was hard to interpret, sorry for that.... Simple

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.