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

Implement an all-errors-in-once feature for multiple checks #122

Open
tpierrain opened this issue Nov 17, 2014 · 5 comments
Open

Implement an all-errors-in-once feature for multiple checks #122

tpierrain opened this issue Nov 17, 2014 · 5 comments

Comments

@tpierrain
Copy link
Owner

something like:

var lazyCheck = new LazyCheck();
lazyCheck.That("Batman").Contains("man').And.StartsWith("Bat");
lazyCheck.That(robin.Age).IsGreaterThan(30);
...
lazyCheck.Execute(); // all checks will be executed here.
@tpierrain
Copy link
Owner Author

Here is the working code I successfully spiked:

    [Test]
    public void ShouldExecuteAllRegisteredChecksInOnceUpToTheExecuteMethodCall()
    {
        var bienOuBien = true;
        var hero = new Person() { Age = 40, Name = "Thomas", Nationality = Nationality.American };

        var lazyChecks = new LazyChecks();

        lazyChecks.That(bienOuBien).IsTrue();
        lazyChecks.That('c').IsALetter();
        lazyChecks.That(hero.Name).Contains("oma");
        lazyChecks.That(hero).Not.IsInstanceOf<string>();
        lazyChecks.That(hero).IsNotNull().And.IsInstanceOf<Person>();

        lazyChecks.Execute();
    }

When it fails like in the test below:

    [Test]
    public void ShouldRaiseAllFailuresInOneShotAtTheEnd()
    {
        var bienOuBien = true;
        var lazyChecks = new LazyChecks();

        lazyChecks.That(bienOuBien).IsFalse();
        lazyChecks.That('.').IsALetter();

        lazyChecks.Execute();
    }

The exception message looks like:

2 lazy checks failed:
-----------
The checked boolean is true whereas it must be false.
The checked boolean:
    [True]
-----------
The checked char is not a letter.
The checked char:
    ['.']
-----------

The next step for me would be to introduce a new operator As("Check of the name") for anyone to be able to set some metadata that would be output with the error messages. e.g.:

    [Test]
    public void ShouldRaiseAllFailuresInOneShotAtTheEnd()
    {
        var bienOuBien = true;
        var lazyChecks = new LazyChecks();

        for(int counter....)
        {
            lazyChecks.That(bienOuBien).As("first lame test for "+counter).IsFalse();
            lazyChecks.That('.').As("Check the character for "+counter).IsALetter();
        }

        lazyChecks.Execute();
    }

Any interest for that feature anyone?

@miiitch
Copy link
Contributor

miiitch commented Nov 18, 2014

+1 for As or something like:

Check.For("vigilante Name").That("Batman....

Michel

-----Message d'origine-----
De : "Thomas PIERRAIN" [email protected]
Envoyé : ‎18/‎11/‎2014 08:23
À : "tpierrain/NFluent" [email protected]
Objet : Re: [NFluent] Implement an all-errors-in-once feature for multiplechecks (#122)

Here is the working code I successfully spiked:
[Test]
public void ShouldExecuteAllRegisteredChecksInOnceUpToTheExecuteMethodCall()
{
var bienOuBien = true;
var hero = new Person() { Age = 40, Name = "Thomas", Nationality = Nationality.American };

    var lazyChecks = new LazyChecks();

    lazyChecks.That(bienOuBien).IsTrue();
    lazyChecks.That('c').IsALetter();
    lazyChecks.That(hero.Name).Contains("oma");
    lazyChecks.That(hero).Not.IsInstanceOf<string>();
    lazyChecks.That(hero).IsNotNull().And.IsInstanceOf<Person>();

    lazyChecks.Execute();
}

When it fails like in the test below:
[Test]
public void ShouldRaiseAllFailuresInOneShotAtTheEnd()
{
var bienOuBien = true;
var lazyChecks = new LazyChecks();

    lazyChecks.That(bienOuBien).IsFalse();
    lazyChecks.That('.').IsALetter();

    lazyChecks.Execute();
}

The exception message looks like:

2 lazy checks failed:

The checked boolean is true whereas it must be false.
The checked boolean:

[True]

The checked char is not a letter.
The checked char:

['.']

The next step for me would be to introduce a new operator As("Check of the name") for anyone to be able to set some metadata that would be output with the error messages. e.g.:
[Test]
public void ShouldRaiseAllFailuresInOneShotAtTheEnd()
{
var bienOuBien = true;
var lazyChecks = new LazyChecks();

    for(int counter....)
    {
        lazyChecks.That(bienOuBien).As("first lame test for "+counter).IsFalse();
        lazyChecks.That('.').As("Check the character for "+counter).IsALetter();
    }

    lazyChecks.Execute();
}

Any interest for that feature anyone?

Reply to this email directly or view it on GitHub.=

@dupdob
Copy link
Collaborator

dupdob commented Nov 18, 2014

I think it's due time to clarify anticipated use cases for the lazy checks.

@miitch: I like your proposed syntax: Check.For("label").That(xxx)

It should easy to add.

@tpierrain
Copy link
Owner Author

Thank you @MIIICH , this is brilliant!

@cyrille : I suggest you add an "issue" to draft your notion of "reusable contract" and let people comment and iterate on it.

I'm bringing my laptop again today, so we could work on it together if you are available.

NFluent v2 is coming.... ;-)

@tpierrain tpierrain added this to the v 2.0 milestone Nov 21, 2014
@dupdob dupdob modified the milestones: For Future consideration, v 2.0 Aug 12, 2017
@dupdob
Copy link
Collaborator

dupdob commented May 14, 2018

Hi, V2.3 version has been massively refactored and open the door to such an evolution

@dupdob dupdob modified the milestones: # For Future consideration, V 3.0 May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants