Click or drag to resize

SmartTestCaseT Method (ExpressionFuncT, Object, Criteria)

Creates an instance of Case class for a specific parameter path Criteria.

Namespace:  SmartTests
Assembly:  SmartTests (in SmartTests.dll) Version: 1.12.0
Syntax
public static Case Case<T>(
	Expression<Func<T, Object>> path,
	Criteria criteria
)

Parameters

path
Type: System.Linq.ExpressionsExpressionFuncT, Object
An Expression of the path for the created Case.
criteria
Type: SmartTestsCriteria
The Criteria for the created Case.

Type Parameters

T
The type of the parameter

Return Value

Type: Case
The newly created Case.
Remarks

Warning: Not all lambda can be used.

It has to have 2 constraints:

  1. Valid Parameter Name -
  2. Valid Parameter Type -
  3. Valid Path -
Examples
static class DateTimeHelper
{
    public static bool IsWeekEnd(DateTime date)
    {
        return date.DayOfWeek == DayOfWeek.Saturday ||
               date.DayOfWeek == DayOfWeek.Sunday;
    }
}

...

private static DateTime GenerateDateOnWeekDay( DayOfWeek day )
{
    var result = DateTime.Now;
    return result.AddDays( day - result.DayOfWeek );
}

[Test]
public void WeekEndTest()
{
    // You will have a warning because you do not test other days of the week
    var result = RunTest( Case( (DateTime date) => date.DayOfWeek,
                                SmartTest.Enum.Values( out value, DayOfWeek.Saturday, DayOfWeek.Sunday ) ),
                          () => DateTimeHelper.IsWeekEnd( GenerateDateOnWeekDay( value ) ) );

    Assert.IsTrue( result );
}
See Also