From 1f5363e70c4fafbb679fe6d463357eb636666b25 Mon Sep 17 00:00:00 2001 From: Ken Dale Date: Wed, 18 Apr 2018 15:14:38 -0400 Subject: [PATCH 1/2] Add DateTimeOffset support, take 2 --- src/Filter/Filter.cs | 1 + src/Filter/Generic/IQueryable`1Extensions.cs | 4 ++++ tests/Filter.Tests/FilterTests.cs | 1 + .../Generic/IEnumerable`1ExtensionsTests.cs | 16 +++++++++++++ .../Generic/IQueryable`1ExtensionsTests.cs | 16 +++++++++++++ .../Generic/Integration/EfTests.cs | 23 +++++++++++++++++++ 6 files changed, 61 insertions(+) diff --git a/src/Filter/Filter.cs b/src/Filter/Filter.cs index d412bca..228ffc8 100755 --- a/src/Filter/Filter.cs +++ b/src/Filter/Filter.cs @@ -10,6 +10,7 @@ public static class Filter typeof(byte), typeof(char), typeof(DateTime), + typeof(DateTimeOffset), typeof(decimal), typeof(double), typeof(float), diff --git a/src/Filter/Generic/IQueryable`1Extensions.cs b/src/Filter/Generic/IQueryable`1Extensions.cs index 2b53998..a655861 100644 --- a/src/Filter/Generic/IQueryable`1Extensions.cs +++ b/src/Filter/Generic/IQueryable`1Extensions.cs @@ -89,6 +89,10 @@ public static IQueryable Filter( { queryableValue = queryableValue.Range(validValuePropertyName, (IRange)filterPropertyValue); } + else if (genericTypeArgument == typeof(DateTimeOffset)) + { + queryableValue = queryableValue.Range(validValuePropertyName, (IRange)filterPropertyValue); + } else if (genericTypeArgument == typeof(decimal)) { queryableValue = queryableValue.Range(validValuePropertyName, (IRange)filterPropertyValue); diff --git a/tests/Filter.Tests/FilterTests.cs b/tests/Filter.Tests/FilterTests.cs index ea8d0ae..ba7bfe0 100755 --- a/tests/Filter.Tests/FilterTests.cs +++ b/tests/Filter.Tests/FilterTests.cs @@ -16,6 +16,7 @@ public void Should_contain_only_the_following_types() typeof(byte), typeof(char), typeof(DateTime), + typeof(DateTimeOffset), typeof(decimal), typeof(double), typeof(float), diff --git a/tests/Filter.Tests/Generic/IEnumerable`1ExtensionsTests.cs b/tests/Filter.Tests/Generic/IEnumerable`1ExtensionsTests.cs index b89801d..6cd7371 100755 --- a/tests/Filter.Tests/Generic/IEnumerable`1ExtensionsTests.cs +++ b/tests/Filter.Tests/Generic/IEnumerable`1ExtensionsTests.cs @@ -14,6 +14,7 @@ public class Filter : IEnumerable_1ExtensionsTests public class Person { public DateTime FavoriteDate { get; set; } + public DateTimeOffset FavoriteDateTimeOffset { get; set; } public char FavoriteLetter { get; set; } public int FavoriteNumber { get; set; } public string FirstName { get; set; } @@ -27,6 +28,7 @@ public class Person new Person() { FavoriteDate = DateTime.Parse("2000-01-01"), + FavoriteDateTimeOffset = DateTime.Parse("2010-01-01"), FavoriteLetter = 'a', FavoriteNumber = 5, FirstName = "John", @@ -36,6 +38,7 @@ public class Person new Person() { FavoriteDate = DateTime.Parse("2000-01-02"), + FavoriteDateTimeOffset = DateTime.Parse("2010-01-02"), FavoriteLetter = 'b', FavoriteNumber = 10, FirstName = "Tim", @@ -303,6 +306,19 @@ public void Should_filter_when_property_types_match_as_range_datetime() Assert.Equal("John", @return.First().FirstName); } + [Fact] + public void Should_filter_when_property_types_match_as_range_datetimeoffset() + { + var @return = People.Filter(new + { + FavoriteDateTimeOffset = Range.Range.FromString("[2010-01-01,2010-01-02)") + }); + + Assert.NotNull(@return); + Assert.Equal(1, @return.Count()); + Assert.Equal("John", @return.First().FirstName); + } + [Fact] public void Should_filter_when_property_types_match_as_range_decimal() { diff --git a/tests/Filter.Tests/Generic/IQueryable`1ExtensionsTests.cs b/tests/Filter.Tests/Generic/IQueryable`1ExtensionsTests.cs index f27045d..c51bec0 100644 --- a/tests/Filter.Tests/Generic/IQueryable`1ExtensionsTests.cs +++ b/tests/Filter.Tests/Generic/IQueryable`1ExtensionsTests.cs @@ -14,6 +14,7 @@ public class Filter : IQueryable_1ExtensionsTests public class Person { public DateTime FavoriteDate { get; set; } + public DateTimeOffset FavoriteDateTimeOffset { get; set; } public char FavoriteLetter { get; set; } public int FavoriteNumber { get; set; } public string FirstName { get; set; } @@ -26,6 +27,7 @@ public class Person new Person() { FavoriteDate = DateTime.Parse("2000-01-01"), + FavoriteDateTimeOffset = DateTimeOffset.Parse("2010-01-01"), FavoriteLetter = 'a', FavoriteNumber = 5, FirstName = "John", @@ -34,6 +36,7 @@ public class Person new Person() { FavoriteDate = DateTime.Parse("2000-01-02"), + FavoriteDateTimeOffset = DateTimeOffset.Parse("2010-01-02"), FavoriteLetter = 'b', FavoriteNumber = 10, FirstName = "Tim", @@ -287,6 +290,19 @@ public void Should_filter_when_property_types_match_as_range_datetime() Assert.Equal("John", @return.First().FirstName); } + [Fact] + public void Should_filter_when_property_types_match_as_range_datetimeoffset() + { + var @return = People.Filter(new + { + FavoriteDateTimeOffset = Range.Range.FromString("[2010-01-01,2010-01-02)") + }); + + Assert.NotNull(@return); + Assert.Equal(1, @return.Count()); + Assert.Equal("John", @return.First().FirstName); + } + [Fact] public void Should_filter_when_property_types_match_as_range_decimal() { diff --git a/tests/Filter.Tests/Generic/Integration/EfTests.cs b/tests/Filter.Tests/Generic/Integration/EfTests.cs index 5fe2de4..28808df 100755 --- a/tests/Filter.Tests/Generic/Integration/EfTests.cs +++ b/tests/Filter.Tests/Generic/Integration/EfTests.cs @@ -22,6 +22,7 @@ public EfTests(DatabaseFixture databaseFixture) new Person() { FavoriteDate = DateTime.Parse("2000-01-01"), + FavoriteDateTimeOffset = DateTimeOffset.Parse("2010-01-01"), FavoriteLetter = 'a', FavoriteNumber = 5, FirstName = "John", @@ -30,6 +31,7 @@ public EfTests(DatabaseFixture databaseFixture) new Person() { FavoriteDate = DateTime.Parse("2000-01-02"), + FavoriteDateTimeOffset = DateTimeOffset.Parse("2010-01-02"), FavoriteLetter = 'b', FavoriteNumber = 10, FirstName = "Tim", @@ -60,6 +62,26 @@ public void Can_filter_nullable_models_via_entity_framework() } } + [Fact] + public void Can_filter_datetimeoffset_via_entity_framework() + { + using (var context = new FilterDbContext(fixture.ConnectionString)) + using (var transaction = context.Database.BeginTransaction()) + { + context.People.AddRange(People); + context.SaveChanges(); + + var @return = context.People.Filter(new + { + FavoriteDateTimeOffset = (Range)"[2010-01-01,2010-01-02)" + }); + + Assert.Equal(1, @return.Count()); + + transaction.Rollback(); + } + } + [Fact] public void Should_be_able_to_handle_nullable_source() { @@ -188,6 +210,7 @@ public class Person { public int Id { get; set; } public DateTime FavoriteDate { get; set; } + public DateTimeOffset FavoriteDateTimeOffset { get; set; } public char FavoriteLetter { get; set; } public int FavoriteNumber { get; set; } public string FirstName { get; set; } From 2ce7eeab7df6df023b21a31b05c39aa03c1956ce Mon Sep 17 00:00:00 2001 From: Ken Dale Date: Wed, 18 Apr 2018 15:15:07 -0400 Subject: [PATCH 2/2] 0.13.1 --- build/Build.Version.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Build.Version.targets b/build/Build.Version.targets index 0593e8c..f8c0f30 100644 --- a/build/Build.Version.targets +++ b/build/Build.Version.targets @@ -3,7 +3,7 @@ 0 13 - 0 + 1