Exemplo n.º 1
0
        public void TriState_IFormattableWithFormatN_GivesSameResultAsToStringNegativeEqualPositive()
        {
            TriState testTriState = (Random.Next() % 3 - 1);

            Assert.AreEqual(
                testTriState.ToString("N", null),
                testTriState.ToString(TriState.Style.NegativeEqualPositive),
                "The result of IFormattable.ToString with format 'N' should be the same as ToString with style NegativeEqualPositive.");
        }
Exemplo n.º 2
0
        public void TriState_IFormattableWithFormatT_GivesSameResultAsToStringTrueUndefinedFalse()
        {
            TriState testTriState = (Random.Next() % 3 - 1);

            Assert.AreEqual(
                testTriState.ToString("T", null),
                testTriState.ToString(TriState.Style.TrueUndefinedFalse),
                "The result of IFormattable.ToString with format 'T' should be the same as ToString with style TrueUndefinedFalse.");
        }
Exemplo n.º 3
0
        public void TriState_IFormattableWithFormatY_GivesSameResultAsToStringYesUnknownNo()
        {
            TriState testTriState = (Random.Next() % 3 - 1);

            Assert.AreEqual(
                testTriState.ToString("Y", null),
                testTriState.ToString(TriState.Style.YesUnknownNo),
                "The result of IFormattable.ToString with format 'Y' should be the same as ToString with style YesUnknownNo.");
        }
Exemplo n.º 4
0
        public void TriState_ToString_DefaultsToYesNoUnknownStyle()
        {
            TriState testTriState = (Random.Next() % 3 - 1);

            Assert.AreEqual(
                testTriState.ToString(TriState.Style.YesUnknownNo),
                testTriState.ToString(),
                "The string representation of a TriState should default to YesUnknownNo formatting.");
        }
Exemplo n.º 5
0
        public void TriState_IFormattableWithValidStyle_GivesSameResultAsToString()
        {
            Random   randSource   = new Random();
            TriState testTriState = (Random.Next() % 3 - 1);

            TriState.Style testStyle =
                (new List <TriState.Style>
            {
                TriState.Style.YesUnknownNo,
                TriState.Style.NegativeEqualPositive,
                TriState.Style.TrueUndefinedFalse
            }).OrderBy(x => randSource.Next()).First();
            Assert.AreEqual(
                testTriState.ToString(testStyle),
                testTriState.ToString(testStyle.ToString(), null),
                "The result of IFormattable.ToString with the string representation of a style as the format should be the same as ToString with that same style.");
        }
Exemplo n.º 6
0
        public void TriState_IFormattableWithInvalidStyle_ThrowsFormatException()
        {
            Random   randSource       = new Random();
            TriState testTriState     = (Random.Next() % 3 - 1);
            String   testInvalidStyle = "ThisIsNotAValidStyleType";

            TriState.Style testStyle;
            Assert.IsFalse(Enum.TryParse(testInvalidStyle, false, out testStyle));
            String value = testTriState.ToString("ThisIsNotAValidStyleType", null);
        }
Exemplo n.º 7
0
        public void TriState_ToStringWithInvalidStyle_ThrowsArgumentOutOfRangeException()
        {
            TriState             testTriState = (Random.Next() % 3 - 1);
            const TriState.Style testStyle    = (TriState.Style) 4;

            // note: this test assumes there is no style with value 4
            Assert.AreEqual(
                "4",
                testStyle.ToString(),
                "For this test to correctly function, the style used should be invalid. When this holds, the string representation of the style is a number.");
            testTriState.ToString(testStyle);
        }