Ejemplo n.º 1
0
        public void CanConvertColorTypeToXlColor()
        {
            var color1 = new ForegroundColor {
                Rgb = new DocumentFormat.OpenXml.HexBinaryValue("FFFF0000")
            };
            var color2 = new ForegroundColor {
                Indexed = new DocumentFormat.OpenXml.UInt32Value((uint)20)
            };
            var color3 = new BackgroundColor {
                Theme = new DocumentFormat.OpenXml.UInt32Value((uint)4)
            };
            var color4 = new BackgroundColor
            {
                Theme = new DocumentFormat.OpenXml.UInt32Value((uint)4),
                Tint  = new DocumentFormat.OpenXml.DoubleValue(0.4)
            };

            var xlColor1 = color1.ToClosedXMLColor();
            var xlColor2 = color2.ToClosedXMLColor();
            var xlColor3 = color3.ToClosedXMLColor();
            var xlColor4 = color4.ToClosedXMLColor();

            Assert.AreEqual(XLColorType.Color, xlColor1.ColorType);
            Assert.AreEqual(XLColor.Red.Color, xlColor1.Color);

            Assert.AreEqual(XLColorType.Indexed, xlColor2.ColorType);
            Assert.AreEqual(20, xlColor2.Indexed);

            Assert.AreEqual(XLColorType.Theme, xlColor3.ColorType);
            Assert.AreEqual(XLThemeColor.Accent1, xlColor3.ThemeColor);
            Assert.AreEqual(0, xlColor3.ThemeTint, XLHelper.Epsilon);

            Assert.AreEqual(XLColorType.Theme, xlColor4.ColorType);
            Assert.AreEqual(XLThemeColor.Accent1, xlColor4.ThemeColor);
            Assert.AreEqual(0.4, xlColor4.ThemeTint, XLHelper.Epsilon);
        }