Browse files

Merge branch 'master' of https://github.com/dokie/fluentcassandra int…

…o issue-27
  • Loading branch information...
2 parents 45e21d0 + 370772c commit 9c53c2a813888b1ab7194e2dbd6f8f8344d9824e @nberardi nberardi committed May 16, 2012
Showing with 63 additions and 8 deletions.
  1. +3 −0 .gitignore
  2. +32 −7 src/Types/CassandraType.cs
  3. +28 −1 test/FluentCassandra.Tests/Types/CassandraTypeTest.cs
View
3 .gitignore
@@ -48,6 +48,9 @@ ipch/
_ReSharper*
.JustCode*
+# DotCover is a code coverage tool
+*.dotCover
+
# Installshield output folder
[Ee]xpress
View
39 src/Types/CassandraType.cs
@@ -35,7 +35,7 @@ public sealed class CassandraType
public CassandraType(string type)
{
- if (type == null || type.Length == 0)
+ if (string.IsNullOrEmpty(type))
throw new ArgumentNullException("type");
_dbType = type;
@@ -74,18 +74,29 @@ public Type FluentType
}
}
- private void Parse()
+ private void Parse()
{
- int compositeStart = _dbType.IndexOf('(');
+ // Pay attention to any ReversedType on the Column Index
+ const string reversedTypeString = "ReversedType(";
+ var reversedIndex = _dbType.IndexOf(reversedTypeString, StringComparison.Ordinal);
+ var workingtype = _dbType;
+ if (reversedIndex > 0)
+ {
+ workingtype = workingtype.Substring(reversedIndex + reversedTypeString.Length);
+ var lastClosing = workingtype.LastIndexOf(")", StringComparison.Ordinal);
+ workingtype = workingtype.Substring(0, lastClosing).TrimEnd('.');
+ }
+
+ var compositeStart = workingtype.IndexOf('(');
// check for composite type
if (compositeStart == -1) {
- _type = Parse(_dbType);
+ _type = Parse(workingtype);
return;
}
- var part1 = _dbType.Substring(0, compositeStart);
- var part2 = _dbType.Substring(compositeStart);
+ var part1 = workingtype.Substring(0, compositeStart);
+ var part2 = workingtype.Substring(compositeStart);
_type = Parse(part1);
@@ -157,7 +168,7 @@ private Type Parse(string dbType)
case "compositetype": type = typeof(CompositeType); break;
case "dynamiccompositetype": type = typeof(DynamicCompositeType); break;
case "countercolumntype": type = typeof(CounterColumnType); break;
- default: throw new CassandraException("Type '" + _dbType + "' not found.");
+ default: throw new CassandraException("Type '" + _dbType + "' not found.");
}
return type;
@@ -266,5 +277,19 @@ public static CassandraType GetCassandraType(Type sourceType)
{
return GetCassandraType(type);
}
+
+ public static CassandraType Reversed(CassandraType baseType)
+ {
+ var underlyingType = baseType.DatabaseType;
+ // Add the Reversed keyword
+ var lastDot = underlyingType.LastIndexOf('.');
+ underlyingType = underlyingType.Insert(lastDot + 1, "ReversedType(");
+ underlyingType = underlyingType + ")";
+
+ var result = new CassandraType(underlyingType);
+ result.Parse();
+
+ return result;
+ }
}
}
View
29 test/FluentCassandra.Tests/Types/CassandraTypeTest.cs
@@ -43,7 +43,21 @@ public void Parse_Type()
Assert.AreEqual(expected, actual);
}
- [Test, ExpectedException(typeof(CassandraException))]
+ [Test]
+ public void Parse_Reverse_Type()
+ {
+ // arrange
+ Type expected = typeof(LongType);
+ string cassandraString = "org.apache.cassandra.db.marshal.ReversedType(LongType)";
+
+ // act
+ Type actual = new CassandraType(cassandraString).FluentType;
+
+ // assert
+ Assert.AreEqual(expected, actual);
+ }
+
+ [Test, ExpectedException(typeof(CassandraException))]
public void Parse_CompositeType_UnknownInnerType()
{
// arranage
@@ -73,5 +87,18 @@ public void Parse_UnknownTypeWithParams()
// act
Type actual = new CassandraType(cassandraString).FluentType;
}
+
+ [Test]
+ public void ReversedTypeHelper()
+ {
+ // arrange
+ Type expected = typeof (AsciiType);
+
+ // act
+ var actual = CassandraType.Reversed(CassandraType.AsciiType).FluentType;
+
+ // assert
+ Assert.AreEqual(expected, actual);
+ }
}
}

0 comments on commit 9c53c2a

Please sign in to comment.