Esempio n. 1
0
        /// <summary>
        /// Asserts that the observable behavior of two delegates is the same.
        /// </summary>
        /// <typeparam name="T">The delegates return type.</typeparam>
        /// <param name="left">A <see cref="Func{TResult}"/> delegate that performs a user-defined action and returns a value of type <typeparamref name="T"/>.</param>
        /// <param name="right">A <see cref="Func{TResult}"/> delegate that performs a user-defined action and returns a value of type <typeparamref name="T"/>.</param>
        /// <remarks>"Same behavior" is defined as both delegates returning the same value or both delegates throwing the same exception.</remarks>
        public static void AreBehaviorsEqual <T>(
            [NotNull, InstantHandle] Func <T> left,
            [NotNull, InstantHandle] Func <T> right)
        {
            CatchResult <T> catchResult1 = Catch(left);
            CatchResult <T> catchResult2 = Catch(right);

            if (catchResult1.HasValue)
            {
                Assert.IsTrue(
                    (catchResult2.HasValue ? 1 : 0) != 0,
                    $"result '{catchResult1.Value}' <> raised '{catchResult2.ExceptionType}'");

                Assert.IsTrue(
                    (EqualityComparer <T> .Default.Equals(catchResult1.Value, catchResult2.Value) ? 1 : 0) != 0,
                    $"result '{catchResult1.Value}' <> result '{catchResult2.Value}'");
            }
            else
            {
                Assert.IsTrue(
                    (catchResult2.HasException ? 1 : 0) != 0,
                    $"raised '{catchResult1.ExceptionType}' <> return '{catchResult2.Value}'");

                Assert.IsTrue(
                    (EqualExceptions(catchResult1.Exception, catchResult2.Exception) ? 1 : 0) != 0,
                    $"raised '{catchResult1.ExceptionType}' <> raised '{catchResult2.ExceptionType}'");
            }
        }
Esempio n. 2
0
    public void EndBiteSequence(CatchResult result)
    {
        float buttonDisableDelay = 0f;

        switch (result)
        {
        case CatchResult.Success:
            CatchFish(GetRandomFishIndex());
            break;

        case CatchResult.Fail:
            buttonDisableDelay = failButtonDisableDelay;
            MissFish(GetRandomFishIndex());
            break;
        }

        if (buttonDisableDelay == 0f)
        {
            buttonSpriteRenderer.enabled = false;
        }
        else
        {
            _buttonDisableTimer = buttonDisableDelay;
        }
        DespawnFish(bitingFishID);
        bitingFishID = -1;
        gameStateManager.SaveGame();
    }
Esempio n. 3
0
        /// <summary>
        /// Asserts that the observable behavior of two delegates is the same.
        /// </summary>
        /// <overloads>Asserts that the observable behavior of two delegates is the same.</overloads>
        /// <param name="left">An <see cref="Action"/> delegate that performs a user-defined action.</param>
        /// <param name="right">An <see cref="Action"/> delegate that performs a user-defined action.</param>
        /// <remarks>"Same behavior" is defined as both delegates throwing the same exception or neither delegate throwing an exception.</remarks>
        public static void AreBehaviorsEqual(
            [NotNull, InstantHandle] Action left,
            [NotNull, InstantHandle] Action right)
        {
            CatchResult catchResult1 = Catch(left);
            CatchResult catchResult2 = Catch(right);

            if (!catchResult1.HasException)
            {
                Assert.IsTrue(
                    (!catchResult2.HasException ? 1 : 0) != 0,
                    $"returned <> raised '{catchResult2.ExceptionType}'");
            }
            else
            {
                Assert.IsTrue(
                    (catchResult2.HasException ? 1 : 0) != 0,
                    $"raised '{catchResult1.ExceptionType}' <> returned");

                Assert.IsTrue(
                    ((EqualExceptions(catchResult1.Exception, catchResult2.Exception)) ? 1 : 0) != 0,
                    $"raised '{catchResult1.ExceptionType}' <> raised '{catchResult2.ExceptionType}'");
            }
        }