예제 #1
0
 /// <summary>
 /// Fluent language: return this, but the contents of the flow have the specified foreground color.
 /// </summary>
 public Flow ForeColor(Color color)
 {
     AddSetter(AssembledStyles.ForeColorSetter(color));
     return(this);
 }
예제 #2
0
        public void PropSetters()
        {
            // Simple check of two kinds of setters
            var setter       = AssembledStyles.FontWeightSetter(700);
            var baseStyle    = new AssembledStyles();
            var derivedStyle = baseStyle.WithProperties(setter);

            Assert.That(derivedStyle.FontWeight, Is.EqualTo(700));
            Assert.That(baseStyle.WithProperties(null), Is.EqualTo(baseStyle));

            var setterRed     = AssembledStyles.ForeColorSetter(Color.Red);
            var derivedStyle2 = baseStyle.WithProperties(setterRed);

            Assert.That(derivedStyle2.ForeColor.ToArgb(), Is.EqualTo(Color.Red.ToArgb()));

            // Can't modify a setter that has been used.
            Assert.Throws <ArgumentException>(() => setter.AppendProp(setterRed));

            // Can combine two setters.
            setter = AssembledStyles.FontWeightSetter(700);
            setter.AppendProp(setterRed);
            var derivedStyle3 = baseStyle.WithProperties(setter);

            Assert.That(derivedStyle3.ForeColor.ToArgb(), Is.EqualTo(Color.Red.ToArgb()));
            Assert.That(derivedStyle3.FontWeight, Is.EqualTo(700));

            // Or even three.
            setter    = AssembledStyles.FontWeightSetter(700);
            setterRed = AssembledStyles.ForeColorSetter(Color.Red);
            var setterGreen = AssembledStyles.BackColorSetter(Color.Green);

            setter.AppendProp(setterRed);
            setter.AppendProp(setterGreen);
            var derivedStyle4 = baseStyle.WithProperties(setter);

            Assert.That(derivedStyle4.ForeColor.ToArgb(), Is.EqualTo(Color.Red.ToArgb()));
            Assert.That(derivedStyle4.FontWeight, Is.EqualTo(700));
            Assert.That(derivedStyle4.BackColor.ToArgb(), Is.EqualTo(Color.Green.ToArgb()));

            // All three should be unavailable for modification.
            var anotherSetter = AssembledStyles.FontWeightSetter(600);

            Assert.Throws <ArgumentException>(() => setter.AppendProp(anotherSetter));
            Assert.Throws <ArgumentException>(() => setterRed.AppendProp(anotherSetter));
            Assert.Throws <ArgumentException>(() => setterGreen.AppendProp(anotherSetter));

            // For efficiency we want custom equality on setters.
            var setterCopy      = AssembledStyles.FontWeightSetter(700);
            var setterRedCopy   = AssembledStyles.ForeColorSetter(Color.Red);
            var setterGreenCopy = AssembledStyles.BackColorSetter(Color.Green);

            setterCopy.AppendProp(setterRedCopy);
            setterCopy.AppendProp(setterGreenCopy);
            Assert.That(setterGreen, Is.EqualTo(setterGreenCopy));
            Assert.That(setter, Is.EqualTo(setterCopy));
            Assert.That(setter.GetHashCode(), Is.EqualTo(setterCopy.GetHashCode()));

            // Minimal testing on the rest
            Assert.That(baseStyle.WithProperties(AssembledStyles.UnderlineColorSetter(Color.Yellow)).UnderlineColor.ToArgb(),
                        Is.EqualTo(Color.Yellow.ToArgb()));
            Assert.That(baseStyle.WithProperties(AssembledStyles.UnderlineSetter(FwUnderlineType.kuntStrikethrough)).Underline,
                        Is.EqualTo(FwUnderlineType.kuntStrikethrough));
            Assert.That(baseStyle.WithProperties(AssembledStyles.FontSizeSetter(13000)).FontSize,
                        Is.EqualTo(13000));
            Assert.That(baseStyle.WithProperties(AssembledStyles.BaselineOffsetSetter(2000)).BaselineOffset,
                        Is.EqualTo(2000));
            Assert.That(baseStyle.WithProperties(AssembledStyles.FontItalicSetter(FwTextToggleVal.kttvForceOn)).FontItalic,
                        Is.True);
            var italicStyle = baseStyle.WithProperties(AssembledStyles.FontItalicSetter(FwTextToggleVal.kttvInvert));

            Assert.That(italicStyle.FontItalic, Is.True);
            Assert.That(italicStyle.WithProperties(AssembledStyles.FontItalicSetter(FwTextToggleVal.kttvInvert)).FontItalic,
                        Is.False);
            Assert.That(baseStyle.WithProperties(AssembledStyles.FaceNameSetter("Symbol")).FaceName,
                        Is.EqualTo("Symbol"));
            Assert.That(baseStyle.WithProperties(AssembledStyles.RtlSetter(true)).RightToLeft, Is.True);
        }