Permalink
Please sign in to comment.
Browse files
corrected DecimalType byte array for Big Endian support in Java to co…
…rrect issue #83
- Loading branch information...
Showing
with
200 additions
and 8 deletions.
- +3 −0 src/System/Numerics/BigDecimal.cs
- +0 −8 src/Types/CassandraConversionHelper.cs
- +3 −0 src/Types/CassandraObject.cs
- +36 −0 src/Types/DecimalTypeConverter.cs
- +4 −0 test/FluentCassandra.Tests/CassandraDatabaseSetup.cs
- +2 −0 test/FluentCassandra.Tests/FluentCassandra.Tests.csproj
- +110 −0 test/FluentCassandra.Tests/Types/DecimalTypeTest.cs
- +42 −0 test/FluentCassandra.Tests/TypesToDatabase/DecimalTypeTest.cs
@@ -0,0 +1,110 @@ | ||
+using System; | ||
+using System.Collections.Generic; | ||
+using System.Linq; | ||
+using System.Numerics; | ||
+using System.Text; | ||
+using Xunit; | ||
+ | ||
+namespace FluentCassandra.Types | ||
+{ | ||
+ public class DecimalTypeTest | ||
+ { | ||
+ private readonly BigDecimal bigDecimal = 100002334.4563D; | ||
+ private readonly byte[] dotNetByteOrder = new byte[] { 179, 69, 9, 214, 232, 0, 4, 0, 0, 0 }; | ||
+ private readonly byte[] javaByteOrder = new byte[] { 0, 0, 0, 4, 0, 232, 214, 9, 69, 179 }; | ||
+ | ||
+ [Fact] | ||
+ public void CassandraType_Cast() | ||
+ { | ||
+ // arrange | ||
+ BigDecimal expected = bigDecimal; | ||
+ DecimalType actualType = expected; | ||
+ | ||
+ // act | ||
+ CassandraObject actual = actualType; | ||
+ | ||
+ // assert | ||
+ Assert.Equal(expected, (BigDecimal)actual); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void Implicit_ByteArray_Cast() | ||
+ { | ||
+ // arrange | ||
+ byte[] expected = dotNetByteOrder; | ||
+ | ||
+ // act | ||
+ DecimalType actualType = expected; | ||
+ byte[] actual = actualType; | ||
+ | ||
+ // assert | ||
+ Assert.True(expected.SequenceEqual(actual)); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void Implicit_BigDecimal_Cast() | ||
+ { | ||
+ // arrange | ||
+ BigDecimal expected = bigDecimal; | ||
+ | ||
+ // act | ||
+ DecimalType actual = expected; | ||
+ | ||
+ // assert | ||
+ Assert.Equal(expected, (BigDecimal)actual); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void Operator_EqualTo() | ||
+ { | ||
+ // arrange | ||
+ var value = bigDecimal; | ||
+ DecimalType type = value; | ||
+ | ||
+ // act | ||
+ bool actual = type.Equals(value); | ||
+ | ||
+ // assert | ||
+ Assert.True(actual); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void Operator_NotEqualTo() | ||
+ { | ||
+ // arrange | ||
+ var value = bigDecimal; | ||
+ DecimalType type = value; | ||
+ | ||
+ // act | ||
+ bool actual = !type.Equals(value); | ||
+ | ||
+ // assert | ||
+ Assert.False(actual); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void BigDecimal_To_JavaBytes() | ||
+ { | ||
+ // arrange | ||
+ | ||
+ // act | ||
+ DecimalType actual = bigDecimal; | ||
+ | ||
+ // assert | ||
+ Assert.True(actual.ToBigEndian().SequenceEqual(javaByteOrder)); | ||
+ } | ||
+ | ||
+ [Fact] | ||
+ public void JavaBytes_To_BigDecimal() | ||
+ { | ||
+ // arrange | ||
+ | ||
+ // act | ||
+ DecimalType actual = new DecimalType(); | ||
+ actual.SetValueFromBigEndian(javaByteOrder); | ||
+ | ||
+ // assert | ||
+ Assert.Equal(bigDecimal, (BigDecimal)actual); | ||
+ } | ||
+ } | ||
+} |
@@ -0,0 +1,42 @@ | ||
+using System; | ||
+using System.Numerics; | ||
+using Xunit; | ||
+using FluentCassandra.Types; | ||
+ | ||
+namespace FluentCassandra.TypesToDatabase | ||
+{ | ||
+ | ||
+ public class DecimalTypeTest : IUseFixture<CassandraDatabaseSetupFixture>, IDisposable | ||
+ { | ||
+ private CassandraContext _db; | ||
+ | ||
+ public void SetFixture(CassandraDatabaseSetupFixture data) | ||
+ { | ||
+ var setup = data.DatabaseSetup(); | ||
+ _db = setup.DB; | ||
+ } | ||
+ | ||
+ public void Dispose() | ||
+ { | ||
+ _db.Dispose(); | ||
+ } | ||
+ | ||
+ public const string FamilyName = "StandardDecimalType"; | ||
+ public const string TestKey = "Test1"; | ||
+ | ||
+ [Fact] | ||
+ public void Save_BigDecimal() | ||
+ { | ||
+ // arrange | ||
+ var family = _db.GetColumnFamily(FamilyName); | ||
+ BigDecimal expected = 100002334.4563D; | ||
+ | ||
+ // act | ||
+ family.InsertColumn(TestKey, expected, Math.PI); | ||
+ var actual = family.GetColumn(TestKey, expected); | ||
+ | ||
+ // assert | ||
+ Assert.Equal(expected, (BigDecimal)actual.ColumnName); | ||
+ } | ||
+ } | ||
+} |
0 comments on commit
d05b40e