Beispiel #1
0
 /// <summary>
 /// Verifies exception.
 /// </summary>
 /// <param name="testInfo">
 /// A <see cref="TestInfo"/>.
 /// </param>
 /// <param name="expected">
 /// A <see cref="ExpectedExceptionInfo"/> expected exception info.
 /// </param>
 /// <param name="exception">
 /// A <see cref="Exception"/> of actual.
 /// </param>
 private void VerifyException(TestInfo testInfo, ExpectedExceptionInfo expected, Exception exception)
 {
     this.SendVerificationTraceInfo(testInfo, exception, expected);
     exception.GetType().ToString().Should().Be(expected.ExceptionType);
     exception.Message.Should().Contain(expected.ExceptionMessageLike);
 }
Beispiel #2
0
        /// <summary>
        /// Verifies the results of a test.
        /// </summary>
        /// <param name="test">
        /// A <see cref="TestInfo"/> of test.
        /// </param>
        /// <param name="resultsType">
        /// A <see cref="ResultsType"/> of result type.
        /// </param>
        /// <param name="results">
        /// A <see cref="IDictionary{TKey,TValue}"/> of results.
        /// </param>
        /// <param name="variables">
        /// A <see cref="IDictionary{TKey,TValue}"/> of variables.
        /// </param>
        private void VerifyResults(TestInfo test, ResultsType resultsType, IDictionary <string, object> results, IDictionary <string, object> variables)
        {
            try
            {
                if (resultsType == ResultsType.Primitive)
                {
                    var finalExpectedValue = this.EvaluateParameters(
                        new Dictionary <string, object>()
                    {
                        { "result", test.ReturnValue },
                    }, variables).First();
                    var result = results["result"];
                    this.Verify(test, () => result, finalExpectedValue.Value);
                }
                else if (resultsType == ResultsType.Void)
                {
                    // Nothing to verify.
                }
                else if (resultsType == ResultsType.Object)
                {
                    var evaluatedExpectedValues = this.EvaluateParameters(test.GetExpectedResults(), variables);
                    if (evaluatedExpectedValues.Any())
                    {
                        var returnObject = results["result"];
                        var output       = JsonConvert.SerializeObject(returnObject, Formatting.Indented);
                        File.WriteAllText(@"c:\temp\test.json", output);
                        var expectedObjectJson = JsonConvert.SerializeObject(evaluatedExpectedValues.First().Value);
                        var returnType         = results["resultType"];
                        var expectedObject     = JsonConvert.DeserializeObject(expectedObjectJson?.ToString(), returnType as Type);

                        // Verify dictionary.
                        this.SendVerificationTraceInfo(test, returnObject, expectedObject);
                        returnObject.Should().BeEquivalentTo(expectedObject, test.Name);
                    }
                }
                else
                {
                    var evaluatedExpectedValues = this.EvaluateParameters(test.GetExpectedResults(true), variables);
                    if (evaluatedExpectedValues.Any())
                    {
                        // Verify dictionary.
                        results.Remove("resultType");
                        this.SendVerificationTraceInfo(test, results, evaluatedExpectedValues);
                        results.Should().BeEquivalentTo(evaluatedExpectedValues, test.Name);
                    }
                }
            }
            catch (Exception e)
            {
                var expectedObjectJson = JsonConvert.DeserializeObject <ExpectedExceptionInfo>(
                    JsonConvert.SerializeObject(test.GetExpectedResults()));
                if (expectedObjectJson.Exception)
                {
                    this.VerifyException(test, expectedObjectJson, e);
                }
                else
                {
                    throw;
                }
            }
        }