Click or drag to resize

SmartTestCaseTParam, T Method (ExpressionFuncTParam, EnumTypeHelperPlaceHolderT, T, T)

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

Namespace:  SmartTests
Assembly:  SmartTests (in SmartTests.dll) Version: 1.12.0
Syntax
public static Case Case<TParam, T>(
	Expression<Func<TParam, EnumTypeHelperPlaceHolder<T>>> path,
	out T value,
	params T[] avoidedValues
)
where T : struct, new(), IComparable

Parameters

path
Type: System.Linq.ExpressionsExpressionFuncTParam, EnumTypeHelperPlaceHolderT
An Expression of the path and the criteria for the parameter of the method to test.
value
Type: T
One random value from the provided values in the equivalence class.
avoidedValues
Type: T
A value to avoid in the range. For example, when testing a property setter with a different value, you do not want the value to be the current value, even if it is within the tested range.

Type Parameters

TParam
The type of the parameter of the method to test.
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.Values( DayOfWeek.Saturday, DayOfWeek.Sunday ), out var value ),
                          () => DateTimeHelper.IsWeekEnd( GenerateDateOnWeekDay( value ) ) );

    Assert.IsTrue( result );
}
See Also

Reference

SmartTestCaseTParam, T(ExpressionFuncTParam, EnumTypeHelperPlaceHolderT, T, T)