question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Should be with predicate?

See original GitHub issue

Before you file a bug, have you:

Description

I often come across functions that don’t exist, for instance "A".Should().BeUpperCase(), and I was wondering if it would make sense to have an overload that takes a Predicate<T> that determines the expectancy.

Complete minimal example reproducing the issue

// Arrange
string input = "MyString";

// Act
string actual = input.ToUpperInvariant();

Desired behavior:

// Arrange
string input = "MyString";

// Act
string actual = input.ToUpperInvariant();

// Assert
actual.Should().Be(actual => actual.All(ch => char.IsUpper(ch)));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
weitzhandlercommented, Jul 29, 2020
var expectation = new
{
    Some = new
    {
        Foo = 1
    },
    Other = new
    {
        Bar = 2
    }
};

// this will ignore `A.Some.Note` and `A.Other.OtherNote` as they are not present in `expectation`.

First of all Jonas, thanks for your nice comprehensive example. This comment is the missing bit I was unaware of. I didn’t know you can use anonymous types for verification, and I also thought it’ll fail if the properties do not match. That is a perfect solution. Thank you for your time and patience explaining all that.

1reaction
jnyrupcommented, Jul 17, 2020

Match is the assertion you’re looking for.

actual.Should().Match(actual => actual.All(ch => char.IsUpper(ch)));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request: Predicate pushdown - FoundationDB Core
It would parse the predicate in whatever way it wants to for the layer's goal (regex, comparing numbers, etc.) and return true or...
Read more >
Predicate mutations while moving predicates between ...
Are there any plans to remove this limitation by allowing mutations while predicates are being moved to a different group? Feature request: ...
Read more >
Can I get type inference on multiple variables through a ...
There's a longstanding open feature request at microsoft/TypeScript#26916 asking for the ability to return multiple type predicates in a ...
Read more >
[Pitch] Swift Predicates - Core Libraries
A predicate is a construct that performs a true/false test on a provided set of input values. It is very common for developers...
Read more >
Predicate Boolean Support for prismicio.core - Features
Feature Idea (one per thread): Add additional type to predicate to enable query by boolean value in .NET Core package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found