public void Min_MinimumIsSpecifiedTypeAndTheValueIsEqualTo_Validates() { long value = 1; var sut = new MinAttribute(typeof(long), "1"); Assert.IsTrue(sut.IsValid(value)); }
public void Min_MinimumIsDoubleAndTheValueIsGreaterThan_Validates() { double value = 2.2; var sut = new MinAttribute(1.1); Assert.IsTrue(sut.IsValid(value)); }
public void Min_MinimumIsDoubleAndTheValueIsLessThan_Fails() { double value = 0; var sut = new MinAttribute(1.1); Assert.IsFalse(sut.IsValid(value)); }
public void Min_MinimumIsIntegerAndTheValueIsLessThan_Fails() { int value = 0; var sut = new MinAttribute(1); Assert.IsFalse(sut.IsValid(value)); }
public void Min_MinimumIsDoubleAndTheValueIsEqualTo_Validates() { double value = 1.1; var sut = new MinAttribute(1.1); Assert.IsTrue(sut.IsValid(value)); }
public void Min_MinimumIsIntegerAndTheValueIsEqualTo_Validates() { int value = 1; var sut = new MinAttribute(1); Assert.IsTrue(sut.IsValid(value)); }
public void Min_MinimumIsIntegerAndTheValueIsGreaterThan_Validates() { int value = 2; var sut = new MinAttribute(1); Assert.IsTrue(sut.IsValid(value)); }
public void Min_MinimumIsSpecifiedTypeAndTheValueIsLessThan_Fails() { long value = 0; var sut = new MinAttribute(typeof(long), "1"); Assert.IsFalse(sut.IsValid(value)); }
public void IsValidDoubleTests() { const double min = 3.50f; var attribute = new MinAttribute(min); Assert.IsTrue(attribute.IsValid(null)); // Optional values are always valid Assert.IsTrue(attribute.IsValid("4")); Assert.IsTrue(attribute.IsValid("4.5")); Assert.IsTrue(attribute.IsValid(100)); Assert.IsTrue(attribute.IsValid("100.42")); Assert.IsFalse(attribute.IsValid(3)); Assert.IsFalse(attribute.IsValid("3.498")); Assert.IsFalse(attribute.IsValid("-5")); Assert.IsFalse(attribute.IsValid("INVALID STRING")); }
public void IsValid() { var v = new MinAttribute(); Assert.IsTrue(v.IsValid(0, null)); v = new MinAttribute(2); Assert.IsTrue(v.IsValid(3, null)); Assert.IsTrue(v.IsValid(2, null)); Assert.IsTrue(v.IsValid((decimal)200.0, null)); Assert.IsTrue(v.IsValid(null, null)); Assert.IsTrue(v.IsValid("5", null)); Assert.IsTrue(v.IsValid((long)int.MaxValue + 1, null)); Assert.IsFalse(v.IsValid(1, null)); Assert.IsFalse(v.IsValid("aaa", null)); Assert.IsFalse(v.IsValid(new object(), null)); }
public void CheckDoubleValidation(double value, bool expected) { var attribute = new MinAttribute(0); Assert.Equal(expected, attribute.IsValid(value)); }
public void Min_EmptyValue_Validates() { var sut = new MinAttribute(1); Assert.IsTrue(sut.IsValid(string.Empty)); }
public void Min_NullValue_Validates() { var sut = new MinAttribute(1); Assert.IsTrue(sut.IsValid(null)); }
public void IsValidIntegerTests() { const int min = 42; var attribute = new MinAttribute(min); Assert.IsTrue(attribute.IsValid(null)); // Optional values are always valid Assert.IsTrue(attribute.IsValid("42")); Assert.IsTrue(attribute.IsValid(42.5)); Assert.IsTrue(attribute.IsValid("50")); Assert.IsTrue(attribute.IsValid(100)); Assert.IsTrue(attribute.IsValid("10000000000")); Assert.IsFalse(attribute.IsValid("41")); Assert.IsFalse(attribute.IsValid("10")); Assert.IsFalse(attribute.IsValid(0)); Assert.IsFalse(attribute.IsValid("-1")); Assert.IsFalse(attribute.IsValid(-50)); Assert.IsFalse(attribute.IsValid("fifty")); }
public void Extreme() { var v = new MinAttribute { Value = -10000 }; Assert.IsTrue(v.IsValid(-10000, null)); Assert.IsTrue(v.IsValid(-10000L, null)); Assert.IsTrue(v.IsValid(123UL, null)); Assert.IsTrue(v.IsValid(123U, null)); Assert.IsTrue(v.IsValid((ushort)5, null)); Assert.IsTrue(v.IsValid((short)5, null)); Assert.IsTrue(v.IsValid(true, null)); Assert.IsTrue(v.IsValid((byte)100, null)); Assert.IsTrue(v.IsValid((sbyte)100, null)); Assert.IsTrue(v.IsValid(AEnum.A, null)); Assert.IsTrue(v.IsValid(CarOptions.Spoiler | CarOptions.FogLights, null)); Assert.IsTrue(v.IsValid('A', null)); Assert.IsTrue(v.IsValid(-9999.99999f, null)); Assert.IsTrue(v.IsValid(-9999.9999999999999999999999999d, null)); Assert.IsFalse(v.IsValid(decimal.MinValue, null)); Assert.IsFalse(v.IsValid(decimal.MinValue.ToString(), null)); Assert.IsFalse(v.IsValid(double.MinValue, null)); Assert.IsFalse(v.IsValid(double.MinValue + "9", null)); }