Permalink
Browse files

Added Reversed begaviour to CassandraType

  • Loading branch information...
Mike Williams
Mike Williams committed May 11, 2012
1 parent e0c819f commit 370772cd9ff2d6d4c91c98b497bfc2fb3e2dbf1e
Showing with 30 additions and 3 deletions.
  1. +17 −3 src/Types/CassandraType.cs
  2. +13 −0 test/FluentCassandra.Tests/Types/CassandraTypeTest.cs
View
@@ -74,17 +74,17 @@ public Type FluentType
}
}
- private void Parse()
+ private void Parse()
{
// Pay attention to any ReversedType on the Column Index
- const string reversedTypeString = ".ReversedType(";
+ 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);
+ workingtype = workingtype.Substring(0, lastClosing).TrimEnd('.');
}
var compositeStart = workingtype.IndexOf('(');
@@ -277,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;
+ }
}
}
@@ -87,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 370772c

Please sign in to comment.