public void TestBoundaryBinder() { var lower = new DateTimeWithRange(); var upper = new DateTimeWithRange(); var binder = new BoundaryBinder(lower, upper); binder.Bind(); Assert.Null(lower.End); Assert.Null(upper.Start); lower.Value = DateTime.Today.AddDays(-2); Assert.NotNull(upper.Start); Assert.Equal(DateTime.Today.AddDays(-2), upper.Start.Value); lower.Value = DateTime.Today.AddDays(-3); Assert.NotNull(upper.Start); Assert.Equal(DateTime.Today.AddDays(-3), upper.Start.Value); lower.Value = null; Assert.Null(upper.Start); upper.Value = DateTime.Today.AddDays(2); Assert.NotNull(lower.End); Assert.Equal(DateTime.Today.AddDays(2), lower.End.Value); upper.Value = DateTime.Today.AddDays(3); Assert.NotNull(lower.End); Assert.Equal(DateTime.Today.AddDays(3), lower.End.Value); upper.Value = null; Assert.Null(lower.Start); }
public void TestDataRange() { int isValidCounter = 0; int startCounter = 0; int endCounter = 0; int valueCounter = 0; var dr = new DateTimeWithRange(); ExpressionExtensions.AttachActionTo(() => isValidCounter++, () => dr.IsValid); ExpressionExtensions.AttachActionTo(() => startCounter++, () => dr.Start); ExpressionExtensions.AttachActionTo(() => endCounter++, () => dr.End); ExpressionExtensions.AttachActionTo(() => valueCounter++, () => dr.Value); Assert.Equal(DateTime.MinValue, dr); Assert.True(dr.IsValid); Assert.Equal(0, valueCounter); dr.Value = DateTime.Today; Assert.True(dr.IsValid); Assert.Equal(0, isValidCounter); Assert.Equal(1, valueCounter); dr.Start = DateTime.Today + TimeSpan.FromDays(1); Assert.False(dr.IsValid); Assert.Equal(1, valueCounter); Assert.Equal(1, isValidCounter); Assert.Equal(1, startCounter); dr.Value = DateTime.Today + TimeSpan.FromDays(3); Assert.True(dr.IsValid); Assert.Equal(2, valueCounter); Assert.Equal(2, isValidCounter); dr.End = DateTime.Today + TimeSpan.FromDays(2); Assert.False(dr.IsValid); Assert.Equal(1, endCounter); Assert.Equal(3, isValidCounter); dr.Value = DateTime.Today + TimeSpan.FromDays(2); Assert.True(dr.IsValid); Assert.Equal(4, isValidCounter); Assert.Equal(3, valueCounter); }