Esempio n. 1
0
        private bool ValueEquityAssertTypesMatch(object expected, object actual, bool equals)
        {
            var expectedType = expected.GetType();
            var actualType   = actual.GetType();

            if (expectedType.IsArray && actualType.IsArray)
            {
                AssertHandler.OnAssertInconclusive(
                    string.Format(AssertMessages.Assert_UnexpectedArrayFormat, equals ? "Assert.SequenceEquals" : "Assert.NotSequenceEquals"));
                return(false);
            }

            if (!ReferenceOrValueTypesMatch(expectedType, actualType))
            {
                return(false);
            }

            if (expectedType.IsCOMObject && actualType.IsCOMObject)
            {
                AssertHandler.OnAssertInconclusive(
                    string.Format(AssertMessages.Assert_UnexpectedReferenceComparisonFormat, equals ? "Assert.AreSame" : "Assert.AreNotSame"));
                return(false);
            }

            if (expectedType != actualType)
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_MismatchedTypes);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public void ParameterInRange(string parameter, double minimum, double maximum, int invocation = 1, string message = "")
        {
            var usage = GetUsageOrAssert(parameter, invocation, message);

            if (Asserted || !usage.HasValue)
            {
                return;
            }

            if (usage.Value.IsMissing)
            {
                AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_VerifyParameterNotPassed, parameter, invocation, message));
                Asserted = true;
                return;
            }

            var underTest = usage.Value.Value is ComVariant ? ((ComVariant)(usage.Value.Value)).Value : usage.Value.Value;

            if (!(underTest is double))
            {
                AssertHandler.OnAssertInconclusive(string.Format(AssertMessages.Assert_VerifyParameterNonNumeric, parameter, invocation, message));
                Asserted = true;
                return;
            }

            // passing case.
            if ((double)underTest >= minimum && (double)underTest <= maximum)
            {
                return;
            }

            AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_ParameterResultFormat, $"{minimum} - {maximum}", underTest, message));
            Asserted = true;
        }
Esempio n. 3
0
        private bool ReferenceOrValueTypesMatch(Type expectedType, Type actualType)
        {
            if (expectedType != null && !expectedType.IsCOMObject && (actualType == null || actualType.IsCOMObject))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_ValueReferenceMismatch);
                return(false);
            }

            if (actualType != null && !actualType.IsCOMObject && (expectedType == null || expectedType.IsCOMObject))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_ReferenceValueMismatch);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public void ParameterIsType(string parameter, string typeName, int invocation = 1, string message = "")
        {
            var usage = GetUsageOrAssert(parameter, invocation, message);

            if (Asserted || !usage.HasValue)
            {
                return;
            }

            //TODO
            AssertHandler.OnAssertInconclusive(AssertMessages.Assert_NotImplemented);
            //if (usage.Value.TypeName.ToLower().Equals(typeName.ToLower()))
            //{
            //    return;
            //}

            //AssertHandler.OnAssertFailed(string.Format(RubberduckUI.Assert_ParameterResultFormat, typeName, usage.Value.TypeName, message));
            //Asserted = true;
        }
Esempio n. 5
0
        private UsageInfo?GetUsageOrAssert(string parameter, int invocation, string message = "", [CallerMemberName] string methodName = "")
        {
            if (invocation > InvocationCount || invocation < 1)
            {
                // ReSharper disable once ExplicitCallerInfoArgument
                AssertHandler.OnAssertFailed(string.Format(AssertMessages.Assert_VerifyNoInvocationFormat, parameter, _usages.Count, message), methodName);
                Asserted = true;
                return(null);
            }

            var uses = _usages.Where(u => u.Parameter.Equals(parameter.ToLower()) && u.Invocation == invocation).ToArray();

            if (uses.Length != 1)
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_VerifyInternalErrorMessage);
                Asserted = true;
                return(null);
            }
            return(uses[0]);
        }
Esempio n. 6
0
        /// <summary>
        /// Verifies that two specified objects are not equal. The assertion fails if the objects are equal.
        /// </summary>
        /// <param name="expected">The expected value.</param>
        /// <param name="actual">The actual value.</param>
        /// <param name="message">An optional message to display if the assertion fails.</param>
        /// <remarks>
        /// <paramref name="expected"/> and <paramref name="actual"/> must be the same type.
        /// </remarks>
        public void AreNotEqual(object expected, object actual, string message = null)
        {
            // vbNullString is marshaled as a null. assume value semantics:
            expected = expected ?? string.Empty;
            actual   = actual ?? string.Empty;

            if (expected.GetType() != actual.GetType())
            {
                AssertHandler.OnAssertInconclusive("[expected] and [actual] values are not the same type.");
                return;
            }

            if (!expected.Equals(actual))
            {
                AssertHandler.OnAssertSucceeded();
            }
            else
            {
                AssertHandler.OnAssertFailed("AreNotEqual", string.Concat("expected: ", expected.ToString(), "; actual: ", actual.ToString(), ". ", message));
            }
        }
Esempio n. 7
0
        protected bool SequenceEquityParametersAreArrays(object expected, object actual, bool equals)
        {
            var expectedType = expected?.GetType();
            var actualType   = actual?.GetType();

            if (expectedType == null && actualType == null)
            {
                AssertHandler.OnAssertInconclusive(
                    string.Format(AssertMessages.Assert_UnexpectedNullArraysFormat, equals ? "Assert.AreSame" : "Assert.AreNotSame"));
                return(false);
            }

            if (!ReferenceOrValueTypesMatch(expectedType, actualType))
            {
                return(false);
            }

            if (expectedType != null && !expectedType.IsArray && actualType != null && actualType.IsArray)
            {
                AssertHandler.OnAssertInconclusive(string.Format(AssertMessages.Assert_ParameterIsNotArrayFormat, "[Expected]"));
                return(false);
            }

            if (actualType != null && !actualType.IsArray && expectedType != null && expectedType.IsArray)
            {
                AssertHandler.OnAssertInconclusive(string.Format(AssertMessages.Assert_ParameterIsNotArrayFormat, "[Actual]"));
                return(false);
            }

            if (actualType != null && !actualType.IsArray && (expectedType == null || expectedType.IsArray))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_NeitherParameterIsArray);
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        private bool ReferenceEquityAssertTypesMatch(object expected, object actual, bool same)
        {
            var expectedType = expected?.GetType();
            var actualType   = actual?.GetType();

            if ((expectedType == null && actualType == null) ||
                ((expectedType == null || expectedType.IsCOMObject) && (actualType == null || actualType.IsCOMObject)))
            {
                return(true);
            }

            if (!ReferenceOrValueTypesMatch(expectedType, actualType))
            {
                return(false);
            }

            if (expectedType != null && !expectedType.IsCOMObject && actualType != null && !actualType.IsCOMObject)
            {
                AssertHandler.OnAssertInconclusive(
                    string.Format(AssertMessages.Assert_UnexpectedValueComparisonFormat, same ? "Assert.AreEqual" : "Assert.AreNotEqual"));
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        private bool IsEasterEgg(object value)
        {
            if (value.GetType() == typeof(AssertClass))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_EasterEggAssertClassPassed);
                Asserted = true;
                return(true);
            }

            if (value.GetType() == typeof(IVerify))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_EasterEggIVerifyPassed);
                Asserted = true;
                return(true);
            }

            if (value.GetType() == typeof(IFake))
            {
                AssertHandler.OnAssertInconclusive(AssertMessages.Assert_EasterEggIFakePassed);
                Asserted = true;
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
 /// <summary>
 /// Indicates that the assertion cannot be verified.
 /// </summary>
 /// <param name="message">An optional message to display.</param>
 public void Inconclusive(string message = "")
 {
     AssertHandler.OnAssertInconclusive(message);
 }