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; } } }
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); }
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); }
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); }
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); }
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); }
public void Constructor_Invalid_Values(int value, PixelPercentUnits units) { // Assert Assert.Throws <ArgumentOutOfRangeException>(() => new PixelPercent(value, units)); }
public void Constructor_Invalid_Values(int value, PixelPercentUnits units) { // Assert Assert.Throws<ArgumentOutOfRangeException>(() => new PixelPercent(value, units)); }
public PixelPercent(string text, IFormatProvider provider, PixelPercentUnits units) : this() { SetValues(text, provider, units); }