Example #1
0
        /// <summary>
        /// Implements <see cref="IChecker.IsNotInstanceOfType"/>.
        /// This method generates a log entry and throws a failure exception if failed.
        /// </summary>
        /// <param name="value">The object value to check.</param>
        /// <param name="type">The object type to check.</param>
        /// <param name="message">A composite format string.</param>
        /// <param name="parameters">An Object array which contains zero or more objects to format.</param>
        public void IsNotInstanceOfType(object value, Type type, string message, params object[] parameters)
        {
            // Set text and res to the default values of successful condition.
            string      text = (message == null) ? string.Empty : message; // To store additional information
            CheckResult res  = CheckResult.Succeeded;                      // The result of the check.

            if (type == null)
            {
                // Expected type is not provided.
                res = CheckResult.Failed;
            }
            else if ((value != null) && type.IsInstanceOfType(value))
            {
                // Failed
                text = LoggingHelper.GetString(
                    "IsNotInstanceOfFailMsg",
                    type.ToString(),
                    value.GetType().ToString(),
                    (message == null) ? string.Empty : message);

                res = CheckResult.Failed;
            }

            text = GetInformationString(res, "IsNotInstanceOfType", text, parameters);
            Log(res, text);
            GenerateException(res, text, parameters);
        }
Example #2
0
        /// <summary>
        /// Implements <see cref="IChecker.AreNotEqual"/>.
        /// This method generates a log entry and throws a failure exception if failed.
        /// </summary>
        /// <typeparam name="T">The type of the objects to compare.</typeparam>
        /// <param name="expected">The first object to compare. This is the object the test expects.</param>
        /// <param name="actual">The second object to compare. This is the object the test produced.</param>
        /// <param name="message">A composite format string.</param>
        /// <param name="parameters">An Object array which contains zero or more objects to format.</param>
        public void AreNotEqual <T>(T expected, T actual, string message, params object[] parameters)
        {
            // Set text and res to the default values of successful condition.
            string      text = (message == null) ? string.Empty : message; // To store additional information
            CheckResult res  = CheckResult.Succeeded;                      // The result of the check.

            if (object.Equals(expected, actual))
            {
                // Failed
                text = LoggingHelper.GetString(
                    "AreNotEqualFailMsg",
                    FormatValueTypeString(expected),
                    FormatValueTypeString(actual),
                    (message == null) ? string.Empty : message);

                res = CheckResult.Failed;
            }

            text = GetInformationString(res, "AreNotEqual", text, parameters);
            Log(res, text);
            GenerateException(res, text, parameters);
        }
Example #3
0
        private string GetInformationString(CheckResult checkResult, string checkMethodName, string message, params object[] parameters)
        {
            // Tries to get requirement ID from parameters
            string requirementId = GetRequirementId(parameters);

            // Default information string
            string text = message;

            // Customized information string (if specified by parameters)
            if (!string.IsNullOrEmpty(message) && null == requirementId)
            {
                text = parameters != null && parameters.Length > 0 ?
                       String.Format(CultureInfo.CurrentCulture, message, parameters) : message;
            }

            // Load the format string according to the check result
            switch (checkResult)
            {
            case CheckResult.Succeeded:
                return(LoggingHelper.GetString("CheckSucceeded", checkerName, checkMethodName, text));

            case CheckResult.Failed:
                if (null == requirementId)
                {
                    return(LoggingHelper.GetString("CheckFailed", checkerName, checkMethodName, text));
                }
                else
                {
                    return(LoggingHelper.GetString("CheckFailedOnReqId",
                                                   checkerName, checkMethodName, requirementId, text));
                }

            case CheckResult.Inconclusive:
                return(LoggingHelper.GetString("CheckInconclusive", checkerName, checkMethodName, text));
            }

            return(String.Empty);
        }
Example #4
0
        /// <summary>
        /// Implements <see cref="IChecker.AreEqual"/>.
        /// This method generates a log entry and throws a failure exception if failed.
        /// </summary>
        /// <typeparam name="T">The type of the objects to compare.</typeparam>
        /// <param name="expected">The first object to compare. This is the object the test expects.</param>
        /// <param name="actual">The second object to compare. This is the object the test produced.</param>
        /// <param name="message">A composite format string.</param>
        /// <param name="parameters">An Object array which contains zero or more objects to format.</param>
        public void AreEqual <T>(T expected, T actual, string message, params object[] parameters)
        {
            // Set text and res to the default values of successful condition.
            string      text = (message == null) ? string.Empty : message; // To store additional information
            CheckResult res  = CheckResult.Succeeded;                      // The result of the check.

            if (!object.Equals(expected, actual))
            {
                // Not Equals

                // Type of the checking data is different.
                if (((actual != null) && (expected != null)) && !actual.GetType().Equals(expected.GetType()))
                {
                    text = LoggingHelper.GetString(
                        "AreEqualFailMsg",
                        FormatValueTypeString(expected),
                        FormatValueTypeString(actual),
                        ((message == null) ? string.Empty : message));
                }
                else
                {
                    // Values are not equal.
                    text = LoggingHelper.GetString(
                        "AreEqualFailMsg",
                        FormatValueTypeString(expected),
                        FormatValueTypeString(actual),
                        ((message == null) ? string.Empty : message));
                }

                res = CheckResult.Failed;
            }

            text = GetInformationString(res, "AreEqual", text, parameters);
            Log(res, text);
            GenerateException(res, text, parameters);
        }