Example #1
0
        /// <summary>
        /// Creates a new validation exception from the specified parameters.
        /// </summary>
        /// <param name="testMethodName">
        /// The name of the test method that contains the call to the validation method.
        /// </param>
        /// <param name="context"> The caller context that contains information about the validated type. </param>
        /// <param name="actual"> The actual value that was validated by this instance. </param>
        /// <param name="expected"> The expected value. </param>
        /// <param name="because">
        /// An optional reason why the <paramref name="actual"/> value should equal the <paramref name="expected"/> value.
        /// </param>
        /// <returns> An exception with the a formatted an human readable validation message. </returns>
        public Exception GetFormattedException(string testMethodName, string context, string actual, string expected,
                                               string because = null)
        {
            var messageFormatter = TestConfiguration.GetMessageFormatterFor(testMethodName);
            var message          = messageFormatter?.FormatMessage(context, actual, expected, because) ?? string.Empty;

            return(new XunitException(message));
        }
Example #2
0
        public void ResetMessageFormatterSuccess()
        {
            // Given

            // When
            TestConfiguration.ResetMessageFormatterFor(nameof(TestConfigurationTest.ResetMessageFormatterSuccess));
            var formatter = TestConfiguration.GetMessageFormatterFor(nameof(TestConfigurationTest.ResetMessageFormatterSuccess));

            // Then
            Assert.NotNull(formatter);
            Assert.IsType <MessageFormatter>(formatter);
        }