Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lambda expressions instead of json path for ignore and accept #175

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

TimHolzherr
Copy link
Member

@TimHolzherr TimHolzherr commented Mar 3, 2023

When using fluent assertions, e.g. person.Should().MatchSnapshot() or the static snapshot class, e.g. Snapshot.Match(person) a generic overload now ensures that we can use lambda expressions to accept and ignore fields.

Examples:

Snapshot.Match(testPerson, snapshotName, o => o.AcceptField(p => p.Age));       
testPerson.Should().MatchSnapshot(o => o
                .AcceptField(m => m.Firstname)
                .AcceptField(m => m.DateOfBirth)
                .IgnoreFields(m => m.Children['*'].Name));

@swisslife-bot
Copy link
Contributor

swisslife-bot commented Mar 3, 2023

CLA assistant check
All committers have signed the CLA.

@sonarcloud
Copy link

sonarcloud bot commented Mar 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 16 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@nscheibe nscheibe left a comment

Choose a reason for hiding this comment

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

Looks nice

@@ -97,5 +97,18 @@ public void MatchSnapshot_Null_Throws()
// act & assert
Assert.Throws<ArgumentNullException>(() => testPerson.MatchSnapshot());
}

[Test]
public void MatchSnapshot_ShouldFluentAssertionsWithLambda_RemovesSubject()
Copy link
Member

Choose a reason for hiding this comment

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

In NUnit it does not create a accept. and the ignore we dont know yet.

public void MatchSnapshot_ShouldFluentAssertions_RemovesSubject()
{
// arrange
TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();
Copy link
Member

Choose a reason for hiding this comment

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

Try to add random input for accepted and ignored fields

@@ -14,6 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
Copy link
Member

Choose a reason for hiding this comment

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

I think we should discuss if we want to have a fluent assertions reference within snapshooter (project) or if we can create a snapshooter.fluentassertions or so...

@@ -0,0 +1,56 @@
{
"Id": "c78c698f-9ee5-4b4b-9a0e-ef729b1f8ec8",
"Firstname": "Mark",
Copy link
Member

Choose a reason for hiding this comment

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

Accept did not work

@RohrerF RohrerF force-pushed the assertions-with-lambda-expressions branch from ac40e1f to 21c9d8f Compare January 3, 2024 12:13
Copy link

sonarcloud bot commented Jan 3, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

88 New issues
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants