Пример #1
0
        private void SetValues(string text, IFormatProvider provider, PixelPercentUnits units)
        {
            if (string.IsNullOrEmpty(text))
            {
                Value = 0;
                Units = PixelPercentUnits.Undefined;
            }
            else
            {
                var s = text.Trim();

                if (s.EndsWith("%"))
                {
                    units = PixelPercentUnits.Percentage;
                    s = s.TrimEnd('%');
                }

                int value;
                if (int.TryParse(s, NumberStyles.Integer, provider, out value))
                {
                    Value = value;
                    Units = units;
                }
                else
                {
                    Units = PixelPercentUnits.Undefined;
                    Value = 0;
                }
            }
        }
Пример #2
0
        public void Constructor_Valid_Values_With_Units(string text, int expectedValue, PixelPercentUnits units)
        {
            // Act
            var sut = new PixelPercent(text, CultureInfo.InvariantCulture, units);

            // Assert
            Assert.AreEqual(expectedValue, sut.Value);
        }
Пример #3
0
        public void Constructor_Valid_Values(int value, PixelPercentUnits units)
        {
            // Act
            var sut = new PixelPercent(value, units);

            // Assert
            Assert.AreEqual(value, sut.Value);
            Assert.AreEqual(units, sut.Units);
        }
Пример #4
0
        public void Constructor_Valid_Values(int value, PixelPercentUnits units)
        {
            // Act
            var sut = new PixelPercent(value, units);

            // Assert
            Assert.AreEqual(value, sut.Value);
            Assert.AreEqual(units, sut.Units);
        }
Пример #5
0
        public void Constructor_Invalid_Values_With_Units(string text, PixelPercentUnits units)
        {
            // Act
            var sut = new PixelPercent(text, CultureInfo.InvariantCulture, units);

            // Assert
            Assert.AreEqual(0, sut.Value);
            Assert.AreEqual(PixelPercentUnits.Undefined, sut.Units);
        }
Пример #6
0
        public PixelPercent(int value, PixelPercentUnits units) : this()
        {
            if (value < 0)
                throw new ArgumentOutOfRangeException(nameof(value), value, "value must be greater than zero");

            if (value > 100 && units == PixelPercentUnits.Percentage)
                throw new ArgumentOutOfRangeException(nameof(value), value,
                    "value when percent must be less or equal to 100");

            SetValues(value.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture, units);
        }
Пример #7
0
        public PixelPercent(int value, PixelPercentUnits units) : this()
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(value), value, "value must be greater than zero");
            }

            if (value > 100 && units == PixelPercentUnits.Percentage)
            {
                throw new ArgumentOutOfRangeException(nameof(value), value,
                                                      "value when percent must be less or equal to 100");
            }

            SetValues(value.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture, units);
        }
Пример #8
0
        public void Constructor_Valid_Values_With_Units(string text, int expectedValue, PixelPercentUnits units)
        {
            // Act
            var sut = new PixelPercent(text, CultureInfo.InvariantCulture, units);

            // Assert
            Assert.AreEqual(expectedValue, sut.Value);
        }
Пример #9
0
 public void Constructor_Invalid_Values(int value, PixelPercentUnits units)
 {
     // Assert
     Assert.Throws <ArgumentOutOfRangeException>(() => new PixelPercent(value, units));
 }
Пример #10
0
 public void Constructor_Invalid_Values(int value, PixelPercentUnits units)
 {
     // Assert
     Assert.Throws<ArgumentOutOfRangeException>(() => new PixelPercent(value, units));
 }
Пример #11
0
 public PixelPercent(string text, IFormatProvider provider, PixelPercentUnits units)
     : this()
 {
     SetValues(text, provider, units);
 }
Пример #12
0
 public PixelPercent(string text, IFormatProvider provider, PixelPercentUnits units) : this()
 {
     SetValues(text, provider, units);
 }