Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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,496
    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
unityunity