Skip to content

Chained PropertyConstraint constraints report incorrect ActualValue #2121

Closed
@erica-kretsch

Description

@erica-kretsch

When a constraint includes multiple .Property() calls, the actual value portion of any error message indicates the value of the first property rather than the value being compared.

In the top portion of the following example, the ActualValue property is set to 3. However, the ActualValue property in the bottom portion is set to the anonymous type in the property Foo, resulting in less useful messages in the various test runners.

var inputObject = new { Foo = new { Bar = "Baz" } };

// Single property
var result = ((IResolveConstraint)Has
    .Length.EqualTo(3))
    .Resolve()
    .ApplyTo(inputObject.Foo.Bar);

Console.WriteLine("Expected: " + result.Description);
Console.WriteLine("Actual: " + result.ActualValue);

Console.WriteLine();

// Nested property
result = ((IResolveConstraint)Has
    .Property("Foo").Property("Bar").Length.EqualTo(3))
    .Resolve()
    .ApplyTo(inputObject);

Console.WriteLine("Expected: " + result.Description);
Console.WriteLine("Actual: " + result.ActualValue);

This issue was introduced November 17, 2012 as part of a refactoring effort. The previous functionality could be restored by returning the ActualValue supplied by the BaseConstraint instead of the value of the property.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions