Permalink
Browse files

Merge pull request #1 from Aaronontheweb/master

Unit tests all pass, magically
  • Loading branch information...
2 parents 9ced334 + 4e55e64 commit f9bdadb2ffb2542dfddfb566f07ba4fa790d4c6c @Aaronontheweb Aaronontheweb committed Jan 23, 2013
@@ -17,7 +17,7 @@ public class CassandraDatabaseSetup
public CassandraSuperColumnFamily<AsciiType, AsciiType> SuperFamily;
public CassandraColumnFamily UserFamily;
- public CassandraColumnFamily CounterFamily;
+ public CassandraColumnFamily CounterFamily;
public User[] Users = new[] {
new User { Id = 1, Name = "Darren Gemmell", Email = "darren@somewhere.com", Age = 32 },
@@ -42,7 +42,7 @@ public class User
public const string TestSuperName = "SubTest1";
public static readonly string Keyspace = ConfigurationManager.AppSettings["TestKeySpace"];
- public static readonly Server Server = new Server(ConfigurationManager.AppSettings["TestServer"]);
+ public static readonly Server Server = new Server(ConfigurationManager.AppSettings["TestServer"]);
public CassandraDatabaseSetup(bool reset = false)
{
@@ -54,7 +54,7 @@ public CassandraDatabaseSetup(bool reset = false)
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily("Users");
- CounterFamily = DB.GetColumnFamily("Counters");
+ CounterFamily = DB.GetColumnFamily("Counters");
if (exists && !reset)
return;
@@ -86,12 +86,12 @@ public void ResetDatabase()
keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
- keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema()
- {
- FamilyName = "Counters",
- ColumnNameType = CassandraType.AsciiType,
- DefaultColumnValueType = CassandraType.CounterColumnType
- });
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema()
+ {
+ FamilyName = "Counters",
+ ColumnNameType = CassandraType.AsciiType,
+ DefaultColumnValueType = CassandraType.CounterColumnType
+ });
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardDecimalType",
ColumnNameType = CassandraType.DecimalType
@@ -105,25 +105,25 @@ public void ResetDatabase()
ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
});
- db.ExecuteNonQuery(@"
+ db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
Id int PRIMARY KEY,
Name ascii,
Email ascii,
Age int
);");
- db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
+ db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
db.Keyspace.ClearCachedKeyspaceSchema();
var family = db.GetColumnFamily<AsciiType>("Standard");
var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
- var userFamily = db.GetColumnFamily("Users");
- var counterFamily = db.GetColumnFamily("Counter");
+ var userFamily = db.GetColumnFamily("Users");
+ var counterFamily = db.GetColumnFamily("Counters");
ResetFamily(family);
ResetSuperFamily(superFamily);
- ResetUsersFamily(userFamily);
- ResetCounterColumnFamily(counterFamily);
+ ResetUsersFamily(userFamily);
+ ResetCounterColumnFamily(counterFamily);
}
}
@@ -177,19 +177,19 @@ public void ResetSuperFamily(CassandraSuperColumnFamily superFamily = null)
superFamily.InsertColumn(TestKey2, TestSuperName, "Test3", Math.PI);
}
- public void ResetCounterColumnFamily(CassandraColumnFamily counterFamily = null)
- {
- counterFamily = counterFamily ?? CounterFamily;
+ public void ResetCounterColumnFamily(CassandraColumnFamily counterFamily = null)
+ {
+ counterFamily = counterFamily ?? CounterFamily;
- counterFamily.RemoveAllRows();
+ counterFamily.RemoveAllRows();
- counterFamily.InsertCounterColumn(TestKey1, "Test1", 1);
- counterFamily.InsertCounterColumn(TestKey1, "Test2", 2);
- counterFamily.InsertCounterColumn(TestKey1, "Test3", 3);
+ counterFamily.InsertCounterColumn(TestKey1, "Test1", 1);
+ counterFamily.InsertCounterColumn(TestKey1, "Test2", 2);
+ counterFamily.InsertCounterColumn(TestKey1, "Test3", 3);
- counterFamily.InsertCounterColumn(TestKey2, "Test1", 2);
- counterFamily.InsertCounterColumn(TestKey2, "Test2", 4);
- counterFamily.InsertCounterColumn(TestKey2, "Test3", 6);
- }
+ counterFamily.InsertCounterColumn(TestKey2, "Test1", 2);
+ counterFamily.InsertCounterColumn(TestKey2, "Test2", 4);
+ counterFamily.InsertCounterColumn(TestKey2, "Test3", 6);
+ }
}
}
@@ -44,11 +44,12 @@ public void Save_DateTime_Local()
// arrange
var family = _db.GetColumnFamily<TimeUUIDType>(FamilyName);
var expected = new DateTime(2010, 11, 20, 0, 0, 0, DateTimeKind.Local);
+ var expectedGuid = GuidGenerator.GenerateTimeBasedGuid(expected);
// act
- family.InsertColumn(TestKey, expected, Math.PI);
- var actualColumn = family.GetColumn(TestKey, expected);
- var actual = ((DateTime)actualColumn.ColumnName).ToLocalTime();
+ family.InsertColumn(TestKey, expectedGuid, Math.PI);
+ var actualColumn = family.GetColumn(TestKey, expectedGuid);
+ var actual = GuidGenerator.GetLocalDateTime((Guid)actualColumn.ColumnName);
// assert
Assert.Equal(expected, actual);
@@ -60,13 +61,15 @@ public void Save_DateTime_Universal()
// arrange
var family = _db.GetColumnFamily<TimeUUIDType>(FamilyName);
var expected = new DateTime(2010, 11, 21, 0, 0, 0, DateTimeKind.Utc);
+ var expectedGuid = GuidGenerator.GenerateTimeBasedGuid(expected);
// act
- family.InsertColumn(TestKey, expected, Math.PI);
- var actual = family.GetColumn(TestKey, expected);
+ family.InsertColumn(TestKey, expectedGuid, Math.PI);
+ var actualColumn = family.GetColumn(TestKey, expectedGuid);
+ var actual = GuidGenerator.GetUtcDateTime((Guid) actualColumn.ColumnName);
// assert
- Assert.Equal(expected, (DateTime)actual.ColumnName);
+ Assert.Equal(expected, actual);
}
[Fact]
@@ -75,13 +78,15 @@ public void Save_DateTimeOffset()
// arrange
var family = _db.GetColumnFamily<TimeUUIDType>(FamilyName);
var expected = new DateTimeOffset(2010, 11, 22, 0, 0, 0, TimeSpan.Zero);
+ var expectedGuid = GuidGenerator.GenerateTimeBasedGuid(expected);
// act
- family.InsertColumn(TestKey, expected, Math.PI);
- var actual = family.GetColumn(TestKey, expected);
+ family.InsertColumn(TestKey, expectedGuid, Math.PI);
+ var actualColumn = family.GetColumn(TestKey, expectedGuid);
+ var actual = GuidGenerator.GetDateTimeOffset((Guid)actualColumn.ColumnName);
// assert
- Assert.Equal(expected, (DateTimeOffset)actual.ColumnName);
+ Assert.Equal(expected, actual);
}
}
}

0 comments on commit f9bdadb

Please sign in to comment.