Search Unity

What is the current NUnit's ApplyTo(object) implementation

Discussion in 'Testing & Automation' started by 5argon, Jun 6, 2019.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,191
    I want to make a new
    Constraint
    but surprised that I could not follow this official guidelines, because the abstract ApplyTo given by Unity's NUnit takes an object and has no type params. I want to use
    TActual
    in my
    ApplyTo
    implementation.

    Code (CSharp):
    1.         public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual);
    2.         public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del);
    3.         public abstract ConstraintResult ApplyTo(object actual);
    In the official NUnit and even from this repo https://github.com/Unity-Technologies/nunitv3 it is stated that there is no such overload, but the abstract signature already has
    TActual
    and is linked directly from
    Assert.That<TActual>(TActual ___  , ...)


    Code (CSharp):
    1.         public abstract ConstraintResult ApplyTo<TActual>(TActual actual);
    2.         public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
    3.         public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual)
    So, in the official NUnit code,
    Assert.That<TActual>(TActual ___  , ...)
    will go to the abstract one complete with
    TActual
    type params. What about Unity's? The following 3 generic overloads of
    That
    is available, I would like to know how could I get
    TActual
    into my custom
    Constraint
    . Are these information lost and became just
    object
    ?

    Code (CSharp):
    1. public static void That<TActual>(TActual actual, IResolveConstraint expression);
    2. public static void That<TActual>(TActual actual, IResolveConstraint expression, string message, params object[] args);
    3. public static void That<TActual>(TActual actual, IResolveConstraint expression, Func<string> getExceptionMessage);
    At least I want to know how
    public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual);
    could be called from
    Assert.That
    so I could use the type and just ignore the
    ref
    . As for
    ActualValueDelegate
    ones, I don't really want to write
    Assert.That( () => myValue)
    every time in order to trigger it. Or better, I want to see the source code of NUnit that is included with 2019.1. Thank you.
     
    Last edited: Jun 6, 2019