Пример #1
0
        public void RoundTrip()
        {
            WebColorConverter wcc = new WebColorConverter();

            Color c = (Color)wcc.ConvertFrom(null, null, " captiontext ");

            Assert.AreEqual("ActiveCaptionText", wcc.ConvertTo(null, null, c, typeof(string)), "#1");
        }
Пример #2
0
        public void Basic()
        {
            WebColorConverter conv;
            Color             c;

            conv = new WebColorConverter();

            Assert.AreEqual(true, conv.CanConvertFrom(null, typeof(string)), "B1");
            Assert.AreEqual(true, conv.CanConvertTo(null, typeof(string)), "B2");
            Assert.AreEqual(false, conv.CanConvertFrom(null, typeof(int)), "B3");
            Assert.AreEqual(false, conv.CanConvertTo(null, typeof(int)), "B4");

            c = Color.Fuchsia;
            Assert.AreEqual("Fuchsia", conv.ConvertTo(null, null, c, typeof(string)), "B5");

            c = Color.FromArgb(1, 2, 3);
            Assert.AreEqual("#010203", conv.ConvertTo(null, null, c, typeof(string)), "B6");

            c = Color.FromArgb(5, 1, 2, 3);
            Assert.AreEqual("#010203", conv.ConvertTo(null, null, c, typeof(string)), "B7");

            c = Color.FromArgb(254, 253, 252);
            Assert.AreEqual("#FEFDFC", conv.ConvertTo(null, null, c, typeof(string)), "B8");

            c = Color.FromKnownColor(KnownColor.BlanchedAlmond);
            Assert.AreEqual("BlanchedAlmond", conv.ConvertTo(null, null, c, typeof(string)), "B9");

            c = Color.FromName("OingoBoingo");
            Assert.AreEqual("#000000", conv.ConvertTo(null, null, c, typeof(string)), "B10");

            Assert.AreEqual(Color.FromArgb(0, 0, 79, 80), conv.ConvertFrom(null, null, "020304"), "B11");
            Assert.AreEqual(Color.FromArgb(0, 0, 79, 80), conv.ConvertFrom(null, null, "20304"), "B12");
            Assert.AreEqual(Color.FromArgb(127, 255, 255, 255), conv.ConvertFrom(null, null, "2147483647"), "B13");
            Assert.AreEqual(Color.FromArgb(128, 0, 0, 1), conv.ConvertFrom(null, null, "-2147483647"), "B14");
            Assert.AreEqual(Color.FromArgb(255, 2, 3, 4), conv.ConvertFrom(null, null, "#FF020304"), "B15");
            Assert.AreEqual(Color.FromArgb(2, 3, 4), conv.ConvertFrom(null, null, "#020304"), "B16");
            Assert.AreEqual(Color.FromArgb(0, 2, 3, 4), conv.ConvertFrom(null, null, "#20304"), "B17");
            Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "Fuchsia"), "B18");
            Assert.AreEqual(Color.FromArgb(0, 0, 2, 52), conv.ConvertFrom(null, null, "#234"), "B19");

            // Garbage/whitespace tests
            c = Color.FromName("\rGarbage\n");
            Assert.AreEqual("#000000", conv.ConvertTo(null, null, c, typeof(string)), "B20");
            Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "\rFuchsia\n"), "B21");
            Assert.AreEqual(Color.FromArgb(255, 1, 2, 3), conv.ConvertFrom(null, null, "#010203"), "B22");

            Assert.AreEqual(Color.Empty, conv.ConvertFrom(null, null, ""), "B23");

            Assert.AreEqual(Color.FromArgb(0, 0, 0, 1), conv.ConvertFrom(null, null, "#1"), "B24");
            Assert.AreEqual(Color.FromArgb(0, 0, 0, 0x12), conv.ConvertFrom(null, null, "#12"), "B25");
            Assert.AreEqual(Color.FromArgb(0, 0, 1, 0x23), conv.ConvertFrom(null, null, "#123"), "B26");
            Assert.AreEqual(Color.FromArgb(0, 0, 0x12, 0x34), conv.ConvertFrom(null, null, "#1234"), "B27");
            Assert.AreEqual(Color.FromArgb(0, 1, 0x23, 0x45), conv.ConvertFrom(null, null, "#12345"), "B28");
            Assert.AreEqual(Color.FromArgb(0xff, 0x12, 0x34, 0x56), conv.ConvertFrom(null, null, "#123456"), "B29");
            Assert.AreEqual(Color.FromArgb(0x1, 0x23, 0x45, 0x67), conv.ConvertFrom(null, null, "#1234567"), "B30");
            Assert.AreEqual(Color.FromArgb(0x12, 0x34, 0x56, 0x78), conv.ConvertFrom(null, null, "#12345678"), "B31");
        }