This repository has been archived by the owner on May 25, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
corrected DecimalType byte array for Big Endian support in Java to co…
…rrect issue #83
- Loading branch information
Showing
8 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/FluentCassandra.Tests/TypesToDatabase/DecimalTypeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |