public void Test_Operator_IsGreaterThan() { var descriptor = new DateTimeFilterDescriptor(); descriptor.Value = DefaultDate; descriptor.Operator = NumericalOperator.IsGreaterThan; var memberAccess = new ViewModelMemberAccess(); descriptor.MemberAccess = memberAccess; var model = new ViewModel() { Date = DefaultDate.AddDays(1), DateOffset = new DateTimeOffset(DefaultDate.AddDays(1), DefaultTimeSpan) }; Assert.IsTrue(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate.AddDays(1); Assert.IsFalse(descriptor.PassesFilter(model)); // DateTimeOffset descriptor.Value = new DateTimeOffset(DefaultDate, DefaultTimeSpan); memberAccess.IsDateOffset = true; Assert.IsTrue(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate; Assert.IsTrue(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate.AddDays(1).AddHours(TimeZoneInfo.Local.BaseUtcOffset.Hours - 1); Assert.IsFalse(descriptor.PassesFilter(model)); }
public void Test_Operator_DoesNotEqualTo() { var descriptor = new DateTimeFilterDescriptor(); descriptor.Value = DefaultDate; descriptor.Operator = NumericalOperator.DoesNotEqualTo; var memberAccess = new ViewModelMemberAccess(); descriptor.MemberAccess = memberAccess; var model = this.GetItems(1).First(); Assert.IsFalse(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate.AddDays(1); Assert.IsTrue(descriptor.PassesFilter(model)); // DateTimeOffset descriptor.Value = new DateTimeOffset(DefaultDate, DefaultTimeSpan); memberAccess.IsDateOffset = true; Assert.IsFalse(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate; Assert.IsTrue(descriptor.PassesFilter(model)); descriptor.Value = DefaultDate.AddHours(TimeZoneInfo.Local.BaseUtcOffset.Hours - 1); Assert.IsFalse(descriptor.PassesFilter(model)); }
public void Test_Operator_IsGreaterThan() { var descriptor = new NumericalFilterDescriptor(); descriptor.Operator = NumericalOperator.IsGreaterThan; var model = CreateViewModel(10); var memberAccess = new ViewModelMemberAccess(); descriptor.MemberAccess = memberAccess; foreach (object value in this.GetNumericValues(8)) { descriptor.Value = value; foreach (NumericalType type in Enum.GetValues(typeof(NumericalType))) { memberAccess.Type = type; Assert.IsTrue(descriptor.PassesFilter(model)); } } foreach (object value in this.GetNumericValues(10)) { descriptor.Value = value; foreach (NumericalType type in Enum.GetValues(typeof(NumericalType))) { memberAccess.Type = type; Assert.IsFalse(descriptor.PassesFilter(model)); } } }
public void Test_ConvertValue_FromString() { var descriptor = new DateTimeFilterDescriptor(); descriptor.Value = "1/1/2010"; var memberAccess = new ViewModelMemberAccess(); descriptor.MemberAccess = memberAccess; var model = new ViewModel() { Date = new DateTime(2010, 1, 1) }; Assert.IsTrue(descriptor.PassesFilter(model)); descriptor.Value = "1/2/2010"; Assert.IsFalse(descriptor.PassesFilter(model)); }
public void Test_ConvertValue_FromString() { var descriptor = new NumericalFilterDescriptor(); descriptor.Operator = NumericalOperator.IsLessThanOrEqualTo; var model = CreateViewModel(10); var memberAccess = new ViewModelMemberAccess(); descriptor.MemberAccess = memberAccess; foreach (object value in this.GetNumericValues(8.5)) { descriptor.Value = value.ToString(); foreach (NumericalType type in Enum.GetValues(typeof(NumericalType))) { memberAccess.Type = type; Assert.IsFalse(descriptor.PassesFilter(model)); } } foreach (object value in this.GetNumericValues(10)) { descriptor.Value = value.ToString(); foreach (NumericalType type in Enum.GetValues(typeof(NumericalType))) { memberAccess.Type = type; Assert.IsTrue(descriptor.PassesFilter(model)); } } foreach (object value in this.GetNumericValues(12.22)) { descriptor.Value = value.ToString(); foreach (NumericalType type in Enum.GetValues(typeof(NumericalType))) { memberAccess.Type = type; Assert.IsTrue(descriptor.PassesFilter(model)); } } }