public void Verify_SetPropertyShouldBeSecurity() { var myfield = new BetweenField <int>(10, 20); // equal Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.Default; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.Equal; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.NotEqual; }); // contains Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.Contains; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.NotContains; }); // like Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.LeftLike; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.RightLike; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.FullSearchLike; }); // less/greater Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.LessThan; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.LessThanOrEqual; }); Assert.Throws <ArgumentException>(() => { myfield.MinCompareMode = CompareMode.GreaterThan; }); //------- MaxCompareMode ------// // equal Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.Default; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.Equal; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.NotEqual; }); // contains Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.Contains; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.NotContains; }); // like Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.LeftLike; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.RightLike; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.FullSearchLike; }); // less/greater Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.LessThan; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.GreaterThan; }); Assert.Throws <ArgumentException>(() => { myfield.MaxCompareMode = CompareMode.GreaterThanOrEqual; }); // MinCompareMode = CompareMode.GreaterThanOrEqual should be work myfield.MinCompareMode = CompareMode.GreaterThanOrEqual; // MaxCompareMode = CompareMode.LessThanOrEqaual should be work myfield.MaxCompareMode = CompareMode.LessThanOrEqual; }
public void Verify_BaseOperatorShouldBeWork() { var myfield = new BetweenField <int>(10, 20); myfield.Min.ShouldBe(10); myfield.Max.ShouldBe(20); myfield.MaxCompareMode.ShouldBe(CompareMode.LessThanOrEqual); myfield.MinCompareMode.ShouldBe(CompareMode.GreaterThanOrEqual); myfield.Min = 1000; myfield.Max = 2000; myfield.Min.ShouldBe(1000); myfield.Max.ShouldBe(2000); }
public void Verify_BetweenFieldIntIsStatisfy_ShouldBeWork() { var myfile = new BetweenField <int>(10, 100); FieldCompareHelper.IsStatisfy(myfile, 9, 99).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, 9, 100).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, 10, 101).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, 10, -99).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, 10, 100).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 10, 50).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 11, 99).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 12, 45).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 12, 98).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 12, 97).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 98, 99).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, 10, 100).ShouldBe(true); }
public void Verify_BetweenFieldDateTimeIsStatisfy_ShouldBeWork() { var dt1 = DateTime.Now; var dt2 = DateTime.Now.AddYears(1); var myfile = new BetweenField <DateTime>(dt1, dt2); FieldCompareHelper.IsStatisfy(myfile, dt1.AddDays(-1), dt2.AddDays(-1)).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, dt1.AddHours(-1), dt2.AddHours(-1)).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, dt1.AddMinutes(-1), dt2.AddMinutes(-1)).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, dt1.AddMinutes(-1), dt1.AddMinutes(-1)).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, dt1.AddSeconds(-1), dt2.AddSeconds(-1)).ShouldBe(false); FieldCompareHelper.IsStatisfy(myfile, dt1.AddDays(1), dt2.AddSeconds(-1)).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, dt1.AddHours(1), dt2.AddHours(-1)).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, dt1.AddMinutes(1), dt2.AddMinutes(-1)).ShouldBe(true); FieldCompareHelper.IsStatisfy(myfile, dt1, dt2).ShouldBe(true); }
/// <summary> /// /// </summary> /// <typeparam name="TPrimitive"></typeparam> /// <param name="field"></param> /// <param name="min"></param> /// <param name="max"></param> /// <returns></returns> public static bool IsStatisfy <TPrimitive>(BetweenField <TPrimitive> field, TPrimitive min, TPrimitive max) where TPrimitive : struct, IConvertible, IComparable { var _min = field.Min.GetValueOrDefault(); var _max = field.Max.GetValueOrDefault(); var left = false; var right = false; if (field.Min == null) { left = true; } else { if (field.MinCompareMode == CompareMode.GreaterThanOrEqual) { left = min.CompareTo(_min) >= 0 && min.CompareTo(_max) <= 0; } } if (field.Max == null) { right = true; } { if (field.MaxCompareMode == CompareMode.LessThanOrEqual) { right = max.CompareTo(_min) >= 0 && max.CompareTo(_max) <= 0; } } if (field.Min == null && field.Max == null) { return(false); } return(left && right); }
public void Visit(BetweenField component) { component.From.Accept(this); sql.Append(" AND "); component.To.Accept(this); }
public void Visit(BetweenField component) { throw new NotImplementedException(); }