Esempio n. 1
0
        /// <summary>
        /// Tests that the value matches the expected value by doing a deep comparison
        /// between the two values. This will recurse into lists and child objects and
        /// will not do a reference check at any point - only equality checks.
        /// </summary>
        /// <param name="expected"></param>
        public void ToEqual(object expected)
        {
            var path     = "value";
            var areEqual = DeepCompareHelper.DeepCompare(expected, _value, ref path, out var mismatchingLeft, out var mismatchingRight);

            ThrowIfFailed(
                areEqual,
                $"Expected {SafeToString(mismatchingRight)} to be equal to {SafeToString(mismatchingLeft)} at path " + path + ".",
                "Expected values to differ but they are equal.");
        }
Esempio n. 2
0
        /// <summary>
        /// Tests that the value is an object or list containing the given object's
        /// properties, list items or list items with a subset of properties.
        /// </summary>
        /// <param name="value"></param>
        public void ToContain(object value)
        {
            var path         = string.Empty;
            var conditionMet = DeepCompareHelper.DeepContains(_value, value, ref path);

            ThrowIfFailed(
                conditionMet,
                $"Expected value {SafeToString(_value)} to contain /{SafeToString(value)}/.",
                $"Expected value {SafeToString(_value)} not to contain /{SafeToString(value)}/.");
        }
Esempio n. 3
0
        /// <summary>
        /// Tests that the value matches the expected value by doing a deep comparison
        /// between the two values. This will recurse into lists and child objects and
        /// will not do a reference check at any point - only equality checks.
        /// </summary>
        /// <param name="expected"></param>
        public void ToEqual(object expected)
        {
            var path     = "value";
            var areEqual = DeepCompareHelper.DeepCompare(expected, _value, ref path);

            ThrowIfFailed(
                areEqual,
                "Expected values to be equal but they differ at path " + path + ".",
                "Expected values to differ but they are equal.");
        }
Esempio n. 4
0
        /// <summary>
        /// Tests that the method being spied on was called at least once with the given set of parameters.
        /// Parameters are compared using deep equality checks, not reference checks.
        /// </summary>
        /// <param name="parameters">The expected parameters.</param>
        public void ToHaveBeenCalledWith(params object[] parameters)
        {
            if (parameters == null)
            {
                parameters = new object[0];
            }

            if (parameters.Length != _spy.Method.GetParameters().Length)
            {
                throw new ArgumentException("Incorrect number of parameters specified for ToHaveBeenCalled.", nameof(parameters));
            }

            var matchFound = false;

            foreach (var call in _spy.CallLog)
            {
                var isMatch = true;

                for (var i = 0; i < parameters.Length && isMatch; i++)
                {
                    var path  = "p" + (i + 1);
                    var left  = parameters[i];
                    var right = call[i];

                    isMatch = DeepCompareHelper.DeepCompare(left, right, ref path);
                }

                if (isMatch)
                {
                    matchFound = true;
                    break;
                }
            }

            if (!matchFound && !_inverted)
            {
                throw new JazExpectationException(
                          "Expected call to spy with [ "
                          + string.Join(", ", parameters)
                          + " ] but actual calls were ["
                          + string.Join(", ", _spy.CallLog.Select(x => " [ " + string.Join(", ", x) + "]"))
                          + " ].",
                          1);
            }

            if (matchFound && _inverted)
            {
                throw new JazExpectationException("Expected no call to spy with [ " + string.Join(", ", parameters) + " ] but a call was made.", 1);
            }
        }