Skip to content

feat: add It.Is for equivalency#736

Merged
vbreuss merged 6 commits intomainfrom
topic/it-is-for-equivalency
Aug 25, 2025
Merged

feat: add It.Is for equivalency#736
vbreuss merged 6 commits intomainfrom
topic/it-is-for-equivalency

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Aug 25, 2025

This pull request adds support for It.Is<T>() patterns in equivalency assertions, allowing for more flexible property-based comparisons when checking object equivalence. The feature enables using constraint-based expectations on individual properties during equivalency checks.

Key Changes:

  • Introduces the It.Is<T>() API for property-level equivalency constraints
  • Adds support for evaluating these constraints within the equivalency comparison engine
  • Updates the ToString() behavior of expectation results to delegate to the underlying expectation builder

@vbreuss vbreuss self-assigned this Aug 25, 2025
Copilot AI review requested due to automatic review settings August 25, 2025 15:36
@vbreuss vbreuss added the enhancement New feature or request label Aug 25, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds support for It.Is<T>() patterns in equivalency assertions, allowing for more flexible property-based comparisons when checking object equivalence. The feature enables using constraint-based expectations on individual properties during equivalency checks.

Key Changes:

  • Introduces the It.Is<T>() API for property-level equivalency constraints
  • Adds support for evaluating these constraints within the equivalency comparison engine
  • Updates the ToString() behavior of expectation results to delegate to the underlying expectation builder

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Source/aweXpect.Core/Equivalency/It.cs New static class providing the It.Is<T>() API for equivalency constraints
Source/aweXpect.Core/Equivalency/EquivalencyExpectationBuilder.cs New expectation builder specifically for equivalency scenarios with custom constraint evaluation
Source/aweXpect.Core/Equivalency/EquivalencyComparison.Compare.cs Updates comparison logic to handle It.Is<T>() expressions during equivalency checks
Source/aweXpect.Core/Results/ExpectationResult.cs Implements IOptionsProvider<ExpectationBuilder> interface and updates ToString() behavior
Tests/aweXpect.Tests/Objects/ThatObject.IsEquivalentTo.ItIs.Tests.cs Comprehensive test suite covering various It.Is<T>() scenarios including success/failure cases
Tests/aweXpect.Core.Tests/Results/ExpectationTests.cs Updates test expectation to reflect new ToString() behavior

Comment thread Source/aweXpect.Core/Equivalency/EquivalencyExpectationBuilder.cs Outdated
@vbreuss vbreuss force-pushed the topic/it-is-for-equivalency branch from 9943df7 to 6875ed0 Compare August 25, 2025 15:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 25, 2025

Test Results

    4 files   -     34      4 suites   - 34   18s ⏱️ - 3m 11s
  917 tests  - 13 468    916 ✅  - 13 467  1 💤  - 1  0 ❌ ±0 
2 637 runs   - 37 197  2 636 ✅  - 37 196  1 💤  - 1  0 ❌ ±0 

Results for commit 0830745. ± Comparison against base commit 7f21274.

This pull request removes 13523 and adds 55 tests. Note that renamed tests count towards both.
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenAwaited_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenAwaited_WithoutReturnValue_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenNotAwaited_ShouldBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenNotAwaited_WithoutReturnValue_ShouldBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenNotAwaited_WithoutReturnValue_WithVerifyInMethod_ShouldStillBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenVerifiedStatically_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenVerifiedStatically_WithoutReturnValue_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenVerifiedWithStaticUsing_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenVerifiedWithStaticUsing_WithoutReturnValue_ShouldNotBeFlagged
aweXpect.Analyzers.Tests.AwaitExpectationAnalyzerTests ‑ WhenVerified_ShouldNotBeFlagged
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message79c0efc1-3072-48cc-a776-c1587f84d6c9")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message7d9a024f-f0eb-4465-a409-357323bc80cc")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message82e385f6-ef2b-4f1f-b501-77b666cce871")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message79e336ee-3179-4385-869a-f7fa208d1954")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messageb3cc1fa2-17c7-4598-96fa-d5b4936fe86b")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messagefaa6f7e1-ea1b-439b-99b8-793ad1df7a88")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore297f960d-7367-449d-97aa-fe8cc2117332")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore2c23c460-92a8-44e3-ab9b-751c096aefe3")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore9141371b-df32-4304-864b-6f0ba1ef165f")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason7a5936e3-e39f-4be6-a778-8fa9b5db9ad0")
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.14.0, Ubuntu 24.04.2 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.413
[Host] : .NET 8.0.19 (8.0.1925.36514), X64 RyuJIT AVX2

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 190.0 ns 1.41 ns 1.32 ns 0.0281 - 472 B
Bool_FluentAssertions 261.9 ns 4.36 ns 3.64 ns 0.0567 - 952 B
Bool_TUnit 960.8 ns 10.00 ns 9.36 ns 0.1431 - 2408 B
Equivalency_aweXpect 299,323.9 ns 1,073.06 ns 1,003.74 ns 16.6016 0.4883 284940 B
Equivalency_FluentAssertions 2,358,317.2 ns 18,539.41 ns 16,434.71 ns 273.4375 46.8750 4584416 B
Equivalency_TUnit 707,183.7 ns 3,588.34 ns 3,356.53 ns 51.7578 2.9297 880545 B
Int_GreaterThan_aweXpect 231.3 ns 3.38 ns 3.16 ns 0.0467 - 784 B
Int_GreaterThan_FluentAssertions 270.9 ns 6.62 ns 6.19 ns 0.0730 - 1224 B
Int_GreaterThan_TUnit 1,282.0 ns 7.94 ns 6.63 ns 0.1774 - 2984 B
ItemsCount_AtLeast_aweXpect 494.0 ns 5.51 ns 5.15 ns 0.0849 - 1432 B
ItemsCount_AtLeast_FluentAssertions 528.1 ns 10.92 ns 10.22 ns 0.1192 - 2008 B
ItemsCount_AtLeast_TUnit 15,163.0 ns 147.32 ns 130.60 ns 1.6174 - 27480 B
String_aweXpect 366.3 ns 6.44 ns 6.02 ns 0.0672 - 1128 B
String_FluentAssertions 499.3 ns 10.22 ns 9.06 ns 0.1287 - 2168 B
String_TUnit 1,331.4 ns 16.85 ns 15.76 ns 0.1831 - 3072 B
StringArray_aweXpect 1,447.7 ns 23.11 ns 21.62 ns 0.1640 - 2744 B
StringArray_FluentAssertions 1,367.9 ns 31.47 ns 29.43 ns 0.2480 - 4152 B
StringArray_TUnit 3,434.8 ns 27.36 ns 25.59 ns 0.3128 - 5296 B
StringArrayInAnyOrder_aweXpect 1,643.8 ns 18.94 ns 17.72 ns 0.1736 - 2920 B
StringArrayInAnyOrder_FluentAssertions 154,795.2 ns 772.49 ns 684.79 ns 3.4180 - 63788 B
StringArrayInAnyOrder_TUnit 4,147.8 ns 27.69 ns 25.91 ns 0.3815 - 6488 B

@vbreuss vbreuss force-pushed the topic/it-is-for-equivalency branch from cf5a164 to 3f2c14b Compare August 25, 2025 18:47
@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss merged commit c7267e2 into main Aug 25, 2025
14 checks passed
@vbreuss vbreuss deleted the topic/it-is-for-equivalency branch August 25, 2025 19:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 2, 2025

This is addressed in release v2.22.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Equivalency with expectations on members

2 participants