Skip to content

Commit

Permalink
Merge pull request #53 from kendaleiv/add-datetimeoffset-support
Browse files Browse the repository at this point in the history
Add DateTimeOffset support, take 2 -- version 0.13.1
  • Loading branch information
khalidabuhakmeh authored Apr 18, 2018
2 parents d5b41ff + 2ce7eea commit 7a6d701
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/Build.Version.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<MajorVersion>0</MajorVersion>
<MinorVersion>13</MinorVersion>
<PatchVersion>0</PatchVersion>
<PatchVersion>1</PatchVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Filter/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Filter
typeof(byte),
typeof(char),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(decimal),
typeof(double),
typeof(float),
Expand Down
4 changes: 4 additions & 0 deletions src/Filter/Generic/IQueryable`1Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public static IQueryable<T> Filter<T>(
{
queryableValue = queryableValue.Range(validValuePropertyName, (IRange<DateTime>)filterPropertyValue);
}
else if (genericTypeArgument == typeof(DateTimeOffset))
{
queryableValue = queryableValue.Range(validValuePropertyName, (IRange<DateTimeOffset>)filterPropertyValue);
}
else if (genericTypeArgument == typeof(decimal))
{
queryableValue = queryableValue.Range(validValuePropertyName, (IRange<decimal>)filterPropertyValue);
Expand Down
1 change: 1 addition & 0 deletions tests/Filter.Tests/FilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions tests/Filter.Tests/Generic/IEnumerable`1ExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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<DateTimeOffset>("[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()
{
Expand Down
16 changes: 16 additions & 0 deletions tests/Filter.Tests/Generic/IQueryable`1ExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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<DateTimeOffset>("[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()
{
Expand Down
23 changes: 23 additions & 0 deletions tests/Filter.Tests/Generic/Integration/EfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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<DateTimeOffset>)"[2010-01-01,2010-01-02)"
});

Assert.Equal(1, @return.Count());

transaction.Rollback();
}
}

[Fact]
public void Should_be_able_to_handle_nullable_source()
{
Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 7a6d701

Please sign in to comment.