Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed handling of DateTime.MinValue. Issue #240 #241

Merged
merged 2 commits into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rethinkdb-net-test/DatumConverters/LongDatumConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class LongDatumConverterTests
[ExpectedException(typeof(NotSupportedException))]
public void ConvertDatum_ValueTooLargeToRepresentAsLongProperly_ThrowException()
{
PrimitiveDatumConverterFactory.Instance.Get<long>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = 1.0 + long.MaxValue});
PrimitiveDatumConverterFactory.Instance.Get<long>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = 10000.0 + long.MaxValue});
}

[Test]
[ExpectedException(typeof(NotSupportedException))]
public void ConvertDatum_ValueTooSmallToRepresentAsLongProperly_ThrowException()
{
PrimitiveDatumConverterFactory.Instance.Get<long>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = long.MinValue - 1.0});
PrimitiveDatumConverterFactory.Instance.Get<long>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = long.MinValue - 10000.0});
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class UnsignedLongDatumConverterTests
[ExpectedException(typeof(NotSupportedException))]
public void ConvertDatum_ValueTooLargeToRepresentAsLongProperly_ThrowException()
{
PrimitiveDatumConverterFactory.Instance.Get<ulong>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = 1.0 + ulong.MaxValue});
PrimitiveDatumConverterFactory.Instance.Get<ulong>().ConvertDatum(new RethinkDb.Spec.Datum(){type = RethinkDb.Spec.Datum.DatumType.R_NUM, r_num = 10000.0 + ulong.MaxValue});
}

[Test]
Expand Down
22 changes: 8 additions & 14 deletions rethinkdb-net/DatumConverters/PrimitiveDatumConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,17 @@ public override long ConvertDatum(Spec.Datum datum)
throw new NotSupportedException("Attempted to cast Datum to non-nullable long, but Datum was null");
else if (datum.type == Spec.Datum.DatumType.R_NUM)
{
var valueAsLong = (long)datum.r_num;

if (valueAsLong >= long.MaxValue || valueAsLong <= long.MinValue)
if (datum.r_num > long.MaxValue || datum.r_num < long.MinValue)
{
throw new NotSupportedException("Attempted to cast Datum to non-nullable long, but Datum outside range of valid long");
}

if (datum.r_num % 1 == 0)
{
return (long)datum.r_num;
}
else
{
throw new NotSupportedException("Attempted to cast fractional Datum to non-nullable long");
}

throw new NotSupportedException("Attempted to cast fractional Datum to non-nullable long");
}
else
throw new NotSupportedException("Attempted to cast Datum to Long, but Datum was unsupported type " + datum.type);
Expand All @@ -279,20 +276,17 @@ public override ulong ConvertDatum(Spec.Datum datum)
throw new NotSupportedException("Attempted to cast Datum to non-nullable unsigned long, but Datum was null");
else if (datum.type == Spec.Datum.DatumType.R_NUM)
{
var valueAsLong = (ulong)datum.r_num;

if (valueAsLong >= ulong.MaxValue || valueAsLong <= ulong.MinValue)
if (datum.r_num > ulong.MaxValue || datum.r_num < ulong.MinValue)
{
throw new NotSupportedException("Attempted to cast Datum to non-nullable unsigned long, but Datum outside range of valid unsigned long");
}

if (datum.r_num % 1 == 0)
{
return (ulong)datum.r_num;
}
else
{
throw new NotSupportedException("Attempted to cast fractional Datum to non-nullable unsigned long");
}

throw new NotSupportedException("Attempted to cast fractional Datum to non-nullable unsigned long");
}
else
throw new NotSupportedException("Attempted to cast Datum to unsigned Long, but Datum was unsupported type " + datum.type);
Expand Down