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.

Detect and reject an "argument constraint factory method" that produces two constraints

See original GitHub issue

It’s a weird situation to be in, but if it comes up, we should complain about it.

Specifically, this spec fails, because no exception is thrown (we just use the first constraint, not even the one that’s returned from the method):

[Scenario]
public static void ConstraintFactoryThatMakesTwoConstraints(
    IHaveAnObjectParameter fake,
    Func<object> constraintFactory,
    Exception exception)
{
    "Given a fake"
        .x(() => fake = A.Fake<IHaveAnObjectParameter>());

    "And a delegate that produces two constraints"
        .x(() => constraintFactory = () =>
            {
                A<object>.That.Matches(i => i is object);
                return A<object>.That.Matches(i => i is null);
            });

    "When I try to configure a method of the fake with this delegate"
        .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(constraintFactory())).Returns(1)));

    "Then the call configuration throws a FakeConfigurationException"
        .x(() => exception.Should().BeAnExceptionOfType<FakeConfigurationException>());
}

(Of course, if we weren’t using a method to create constraints, and just specifying one inline via an expression, it’s only possible to create a single constraint.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Sep 23, 2019

Good point!

(As an aside, maybe we should be throwing a FakeConfigurationException.)

Maybe. I don’t think we’re very consistent in the types of exceptions we throw…

0reactions
blairconradcommented, Oct 16, 2019

This change has been released as part of FakeItEasy 5.3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple constraint annotations confused on Java Bean ...
I defined two custom constraints ACheck and BCheck. @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) @ ...
Read more >
Overloading and generic constraints - Jon Skeet's coding blog
Okay, so we've got two methods called M with different constraints. I've given them both parameters of different reference types.
Read more >
C++ Reference: class Solver - OR-Tools
This method creates a relation between two interval vars. MakeIntervalVarRelationWithDelay. Return type: Constraint*. Arguments: IntervalVar* const t1, ...
Read more >
Integer Programming
There are two types of constraints for the model: i) the demand dj of each customer must be filled from the warehouses; and...
Read more >
iris — Iris 3.7.0.dev35 documentation
Constraints are the mechanism by which cubes can be pattern matched and filtered according to specific criteria. Once a constraint has been defined,...
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