Example #1
0
 public static void FormatValue_DecimalIsWrittenWithTrailingM()
 {
     Assert.That(MsgUtils.FormatValue(0.5m), Is.EqualTo("0.5m"));
 }
Example #2
0
 public static void FormatValue_DecimalIsWrittenToTwentyNineDigits()
 {
     Assert.That(MsgUtils.FormatValue(12345678901234567890123456789m), Is.EqualTo("12345678901234567890123456789m"));
 }
Example #3
0
 public static void FormatValue_FloatIsWrittenWithTrailingF()
 {
     Assert.That(MsgUtils.FormatValue(0.5f), Is.EqualTo("0.5f"));
 }
Example #4
0
        public static void FormatValue_DoubleIsWrittenToSeventeenDigits()
        {
            string s = MsgUtils.FormatValue(0.33333333333333333333333333333333333333333333d);

            Assert.That(s.Length, Is.EqualTo(20)); // add 3 for leading 0, decimal and trailing d
        }
Example #5
0
 public static void FormatValue_IntegerIsWrittenAsIs()
 {
     Assert.That(MsgUtils.FormatValue(42), Is.EqualTo("42"));
 }
Example #6
0
        public static void FormatValue_TwoElementsValueTupleTest()
        {
            string s = MsgUtils.FormatValue(ValueTuple.Create("Hello", 123));

            Assert.That(s, Is.EqualTo("(\"Hello\", 123)"));
        }
Example #7
0
        public static void FormatValue_KeyValuePairTest(object key, object value, string expectedResult)
        {
            string s = MsgUtils.FormatValue(new KeyValuePair <object, object>(key, value));

            Assert.That(s, Is.EqualTo(expectedResult));
        }
Example #8
0
        public static void FormatValue_ContextualCustomFormatterInvoked_FactoryArg()
        {
            TestContext.AddFormatter(next => val => (val is CustomFormattableType) ? "custom_formatted" : next(val));

            Assert.That(MsgUtils.FormatValue(new CustomFormattableType()), Is.EqualTo("custom_formatted"));
        }
Example #9
0
 public static void FormatValue_DoubleIsWrittenWithTrailingD()
 {
     Assert.That(MsgUtils.FormatValue(0.5d), Is.EqualTo("0.5d"));
 }
Example #10
0
 public static void FormatValue_CharTest(char c, string expected)
 {
     Assert.That(MsgUtils.FormatValue(c), Is.EqualTo(expected));
 }
Example #11
0
        public void PercentTolerance_Failure(object actual, object expected, object tolerance)
        {
            var ex = Assert.Throws <AssertionException>(
                () => Assert.That(actual, Is.GreaterThanOrEqualTo(expected).Within(tolerance).Percent),
                "Assertion should have failed");

            Assert.That(ex.Message, Contains.Substring("Expected: greater than or equal to " + MsgUtils.FormatValue(expected) + " within " + MsgUtils.FormatValue(tolerance) + " percent"));
        }
Example #12
0
        public void SimpleTolerance_Failure(object actual, object expected, object tolerance)
        {
            var ex = Assert.Throws <AssertionException>(
                () => Assert.That(actual, Is.LessThan(expected).Within(tolerance)),
                "Assertion should have failed");

            Assert.That(ex.Message, Contains.Substring("Expected: less than " + MsgUtils.FormatValue(expected) + " within " + MsgUtils.FormatValue(tolerance)));
        }
Example #13
0
#pragma warning restore IDE1006

        /// <summary>
        /// Construct a TypeConstraint for a given Type
        /// </summary>
        /// <param name="type">The expected type for the constraint</param>
        /// <param name="descriptionPrefix">Prefix used in forming the constraint description</param>
        protected TypeConstraint(Type type, string descriptionPrefix)
            : base(type)
        {
            this.expectedType = type;
            this.Description  = descriptionPrefix + MsgUtils.FormatValue(expectedType);
        }
Example #14
0
 public static void FormatValue_DateTimeTest()
 {
     Assert.That(MsgUtils.FormatValue(new DateTime(2007, 7, 4, 9, 15, 30, 123)), Is.EqualTo("2007-07-04 09:15:30.123"));
 }
Example #15
0
        public static void FormatValue_EmptyValueTupleTest()
        {
            string s = MsgUtils.FormatValue(ValueTuple.Create());

            Assert.That(s, Is.EqualTo("()"));
        }
Example #16
0
 public static void FormatValue_DateTimeOffsetTest()
 {
     Assert.That(MsgUtils.FormatValue(new DateTimeOffset(2007, 7, 4, 9, 15, 30, 123, TimeSpan.FromHours(8))), Is.EqualTo("2007-07-04 09:15:30.123+08:00"));
 }
Example #17
0
        public static void FormatValue_OneElementTupleTest()
        {
            string s = MsgUtils.FormatValue(Tuple.Create("Hello"));

            Assert.That(s, Is.EqualTo("(\"Hello\")"));
        }
Example #18
0
        public static void FormatValue_ContextualCustomFormatterInvoked_FormatterArg()
        {
            TestContext.AddFormatter <CustomFormattableType>(val => "custom_formatted_using_type");

            Assert.That(MsgUtils.FormatValue(new CustomFormattableType()), Is.EqualTo("custom_formatted_using_type"));
        }
Example #19
0
        public static void FormatValue_ThreeElementsTupleTest()
        {
            string s = MsgUtils.FormatValue(Tuple.Create("Hello", 123, 'a'));

            Assert.That(s, Is.EqualTo("(\"Hello\", 123, 'a')"));
        }
Example #20
0
 public static void FormatValue_StringIsWrittenWithQuotes()
 {
     Assert.That(MsgUtils.FormatValue("Hello"), Is.EqualTo("\"Hello\""));
 }
Example #21
0
        public static void FormatValue_DirectoryEntryTest(object key, object value, string expectedResult)
        {
            string s = MsgUtils.FormatValue(new DictionaryEntry(key, value));

            Assert.That(s, Is.EqualTo(expectedResult));
        }