Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed implicit type casting for arrays and collections to explicit …

…to fix issue #39
  • Loading branch information...
commit 01c0b30add27623f998cbde4958db30897ddcf23 1 parent a9597c9
@nberardi nberardi authored
View
8 src/Types/CassandraObject.cs
@@ -153,10 +153,10 @@ private static CassandraObject ConvertFrom(object o)
public static implicit operator DateTimeOffset?(CassandraObject o) { return ConvertTo<DateTimeOffset?>(o); }
public static implicit operator BigInteger?(CassandraObject o) { return ConvertTo<BigInteger?>(o); }
- public static implicit operator object[](CassandraObject o) { return ConvertTo<object[]>(o); }
- public static implicit operator List<object>(CassandraObject o) { return ConvertTo<List<object>>(o); }
- public static implicit operator CassandraObject[](CassandraObject o) { return ConvertTo<CassandraObject[]>(o); }
- public static implicit operator List<CassandraObject>(CassandraObject o) { return ConvertTo<List<CassandraObject>>(o); }
+ public static explicit operator object[](CassandraObject o) { return ConvertTo<object[]>(o); }
+ public static explicit operator List<object>(CassandraObject o) { return ConvertTo<List<object>>(o); }
+ public static explicit operator CassandraObject[](CassandraObject o) { return ConvertTo<CassandraObject[]>(o); }
+ public static explicit operator List<CassandraObject>(CassandraObject o) { return ConvertTo<List<CassandraObject>>(o); }
#endregion
View
72 test/FluentCassandra.Tests/Bugs/Issue39CompositeTypeAsKey.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FluentCassandra.Types;
+using Xunit;
+
+namespace FluentCassandra.Bugs
+{
+ public class Issue39CompositeTypeAsKey : IUseFixture<CassandraDatabaseSetupFixture>, IDisposable
+ {
+ private CassandraContext _db;
+
+ public void SetFixture(CassandraDatabaseSetupFixture data)
+ {
+ var setup = data.DatabaseSetup();
+ _db = setup.DB;
+ }
+
+ public void Dispose()
+ {
+ _db.Dispose();
+ }
+
+ [Fact]
+ public void Test()
+ {
+ // arrange
+ var keyspace = _db.Keyspace;
+
+ // create column family using API
+ _db.TryDropColumnFamily("Data");
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
+ FamilyName = "Data",
+ KeyValueType = CassandraType.CompositeType(CassandraType.AsciiType, CassandraType.AsciiType),
+ ColumnNameType = CassandraType.AsciiType,
+ DefaultColumnValueType = CassandraType.BytesType
+ });
+
+ InsertMarketData("TT", "A", new Dictionary<string, string> { { "Status", "Working" } });
+
+ // act
+ var actual = GetData("TT", "A", "Status");
+
+ // assert
+ Assert.NotNull(actual);
+ Assert.Equal(1, actual.Columns.Count);
+ }
+
+ public void InsertMarketData(string key1, string key2, Dictionary<string, string> values)
+ {
+ var productFamily = _db.GetColumnFamily("Data");
+ var key = new CompositeType<AsciiType, AsciiType>(key1, key2);
+
+ var post = productFamily.CreateRecord(key);
+ _db.Attach(post);
+
+ foreach (var fieldValue in values)
+ post.TrySetColumn(fieldValue.Key, fieldValue.Value);
+
+ _db.SaveChanges();
+ }
+
+ public FluentColumnFamily GetData(string key1, string key2, params CassandraObject[] columns)
+ {
+ var productFamily = _db.GetColumnFamily("Data");
+ var key = new CompositeType<AsciiType, AsciiType>(key1, key2);
+
+ return productFamily.Get(key).FetchColumns(columns).FirstOrDefault();
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.