public void CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass() { var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(Session, config); table.CreateIfNotExists(); VerifyQuery(CreateCqlCaseSensitive, 1); var mapper = new Mapper(Session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); VerifyBoundStatement( $"INSERT INTO \"{table.Name}\" ({ManyDataTypesPoco.GetCaseSensitiveColumnNamesStr()}) " + $"VALUES ({string.Join(", ", ManyDataTypesPoco.GetColumnNames().Select(_ => "?"))})", 1, manyTypesInstance.GetParameters()); var cqlSelect = $"SELECT * from \"{table.Name}\" where \"StringType\"='{manyTypesInstance.StringType}'"; TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess(ManyDataTypesPoco.GetColumnsAndTypes(), r => r.WithRow(manyTypesInstance.GetParameters()))); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); ManyDataTypesPoco.AssertListEqualsList(new List <ManyDataTypesPoco> { manyTypesInstance }, instancesQueried); }
public void CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass() { var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(Session, config); Assert.AreNotEqual(table.Name, table.Name.ToLower()); // make sure the case sensitivity rule is being used table.CreateIfNotExists(); VerifyQuery(CreateCqlCaseSensitive, 1); var mapper = new Mapper(Session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); VerifyBoundStatement( $"INSERT INTO \"{table.Name}\" ({ManyDataTypesPoco.GetCaseSensitiveColumnNamesStr()}) " + $"VALUES ({string.Join(", ", ManyDataTypesPoco.GetColumnNames().Select(_ => "?"))})", 1, manyTypesInstance.GetParameters()); TestCluster.PrimeFluent( b => b.WhenQuery( $"SELECT {ManyDataTypesPoco.GetCaseSensitiveColumnNamesStr()} FROM \"{table.Name}\"") .ThenRowsSuccess(ManyDataTypesPoco.GetColumnsAndTypes(), r => r.WithRow(manyTypesInstance.GetParameters()))); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>().ToList(); Assert.AreEqual(instancesQueried.Count, 1); manyTypesInstance.AssertEquals(instancesQueried[0]); }
public void CqlClientConfiguration_UseIndividualMappings_EmptyTypeDefinitionList() { // Setup var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(c => c.StringType)); var table = new Table <ManyDataTypesPoco>(_session, config); table.CreateIfNotExists(); // validate default lower-casing Assert.AreNotEqual(typeof(ManyDataTypesPoco).Name.ToLower(), typeof(ManyDataTypesPoco).Name); Assert.AreNotEqual(table.Name.ToLower(), table.Name); Assert.AreEqual(typeof(ManyDataTypesPoco).Name.ToLower(), table.Name.ToLower()); // Test var mapper = new Mapper(_session, config); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); // Verify results string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name.ToLower(), "stringtype", manyTypesInstance.StringType); ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List <ManyDataTypesPoco>() { manyTypesInstance }); }
public void CreateTable_MakeAllPropertiesCaseSensitiveAtOnce() { var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(u => u.StringType) .TableName("tbl_case_sens_once") .CaseSensitive()); var table = new Table <ManyDataTypesPoco>(Session, config); table.Create(); VerifyQuery( "CREATE TABLE \"tbl_case_sens_once\" " + $"({string.Join(", ", ManyDataTypesPoco.ColumnsToTypes.Select(k => $"\"{k.Key}\" {k.Value.Value}"))}, " + "PRIMARY KEY (\"StringType\"))", 1); var mapper = new Mapper(Session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); var cqlSelect = $"SELECT * from \"{table.Name}\" where \"StringType\"='{manyTypesInstance.StringType}'"; TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess(ManyDataTypesPoco.GetColumnsAndTypes(), r => r.WithRow(manyTypesInstance.GetParameters()))); var objectsRetrieved = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); Assert.AreEqual(1, objectsRetrieved.Count); objectsRetrieved[0].AssertEquals(manyTypesInstance); }
public void Fetch_NoArgDefaultsToSelectAll() { var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); table.Create(); var mapper = new Mapper(_session, config); List <ManyDataTypesPoco> manyTypesList = new List <ManyDataTypesPoco>(); for (int i = 0; i < 10; i++) { manyTypesList.Add(ManyDataTypesPoco.GetRandomInstance()); } foreach (var manyTypesRecord in manyTypesList) { mapper.Insert(manyTypesRecord); } List <ManyDataTypesPoco> instancesRetrieved = mapper.Fetch <ManyDataTypesPoco>().ToList(); Assert.AreEqual(manyTypesList.Count, instancesRetrieved.Count); foreach (var instanceRetrieved in instancesRetrieved) { ManyDataTypesPoco.AssertListContains(manyTypesList, instanceRetrieved); } }
public void Insert_UnconfiguredTable() { // Setup var mapper = new Mapper(_session, new MappingConfiguration()); ManyDataTypesPoco manyTypesPoco = ManyDataTypesPoco.GetRandomInstance(); // Validate Error Message var e = Assert.Throws <InvalidQueryException>(() => mapper.Insert(manyTypesPoco)); StringAssert.IsMatch(typeof(ManyDataTypesPoco).Name.ToLower(), e.Message); }
public void Insert_UnconfiguredTable() { // Setup var mapper = new Mapper(_session, new MappingConfiguration()); ManyDataTypesPoco manyTypesPoco = ManyDataTypesPoco.GetRandomInstance(); // Validate Error Message var e = Assert.Throws <InvalidQueryException>(() => mapper.Insert(manyTypesPoco)); string expectedErrMsg = "unconfigured columnfamily " + typeof(ManyDataTypesPoco).Name.ToLower(); Assert.AreEqual(expectedErrMsg, e.Message); }
public void CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass_() { var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); Assert.AreNotEqual(table.Name, table.Name.ToLower()); // make sure the case sensitivity rule is being used table.Create(); var mapper = new Mapper(_session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>().ToList(); Assert.AreEqual(1, instancesQueried.Count); manyTypesInstance.AssertEquals(instancesQueried[0]); }
public void CreateTable_FluentMapping_Success() { var mappingConfig = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, mappingConfig); table.Create(); var mapper = new Mapper(_session, mappingConfig); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType); List <ManyDataTypesPoco> instancesQueried = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); Assert.AreEqual(1, instancesQueried.Count); instancesQueried[0].AssertEquals(manyTypesInstance); }
public void CqlClientConfiguration_UseIndividualMappings_StaticMappingClass() { var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); table.CreateIfNotExists(); var mapper = new Mapper(_session, config); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType); ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List <ManyDataTypesPoco>() { manyTypesInstance }); }
public void CreateTable_MakeAllPropertiesCaseSensitiveAtOnce() { var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(u => u.StringType) .CaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); table.Create(); var mapper = new Mapper(_session, config); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType); List <ManyDataTypesPoco> objectsRetrieved = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); Assert.AreEqual(1, objectsRetrieved.Count); objectsRetrieved[0].AssertEquals(manyTypesInstance); }
public void CqlClientConfiguration_UseIndividualMappings_EmptyTypeDefinitionList() { // Setup var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(c => c.StringType)); var table = new Table <ManyDataTypesPoco>(Session, config); table.CreateIfNotExists(); VerifyQuery(CreateCql, 1); // validate default lower-casing Assert.AreNotEqual(typeof(ManyDataTypesPoco).Name.ToLower(), typeof(ManyDataTypesPoco).Name); Assert.AreNotEqual(table.Name.ToLower(), table.Name); Assert.AreEqual(typeof(ManyDataTypesPoco).Name.ToLower(), table.Name.ToLower()); // Test var mapper = new Mapper(Session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); VerifyBoundStatement( $"INSERT INTO {table.Name} ({ManyDataTypesPoco.GetColumnNamesStr()}) " + $"VALUES ({string.Join(", ", ManyDataTypesPoco.GetColumnNames().Select(_ => "?"))})", 1, manyTypesInstance.GetParameters()); // Verify results var cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name.ToLower(), "stringtype", manyTypesInstance.StringType); TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess(ManyDataTypesPoco.GetColumnsAndTypes(), r => r.WithRow(manyTypesInstance.GetParameters()))); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); ManyDataTypesPoco.AssertListEqualsList(new List <ManyDataTypesPoco> { manyTypesInstance }, instancesQueried); }
public void CreateTable_MakeAllPropertiesCaseSensitiveAtOnce() { var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(u => u.StringType) .TableName("tbl_case_sens_once") .CaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); table.Create(); var mapper = new Mapper(_session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); var cqlSelect = $"SELECT * from \"{table.Name}\" where \"StringType\"='{manyTypesInstance.StringType}'"; var objectsRetrieved = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); Assert.AreEqual(1, objectsRetrieved.Count); objectsRetrieved[0].AssertEquals(manyTypesInstance); }
public void CqlClientConfiguration_UseIndividualMappingGeneric_StaticMappingClass() { // Use separate keyspace to avoid interfering with other tests _uniqueKsName = TestUtils.GetUniqueKeyspaceName(); _session.CreateKeyspace(_uniqueKsName); _session.ChangeKeyspace(_uniqueKsName); var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); Assert.AreNotEqual(table.Name, table.Name.ToLower()); // make sure the case sensitivity rule is being used table.CreateIfNotExists(); var mapper = new Mapper(_session, config); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>().ToList(); Assert.AreEqual(instancesQueried.Count, 1); manyTypesInstance.AssertEquals(instancesQueried[0]); }
public void CqlClientConfiguration_UseIndividualMappingClassType_StaticMappingClass() { // Use separate keyspace to avoid interfering with other tests _uniqueKsName = TestUtils.GetUniqueKeyspaceName(); _session.CreateKeyspace(_uniqueKsName); _session.ChangeKeyspace(_uniqueKsName); var config = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(_session, config); table.CreateIfNotExists(); var mapper = new Mapper(_session, config); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name, "StringType", manyTypesInstance.StringType); ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List <ManyDataTypesPoco>() { manyTypesInstance }); }
public void CqlClientConfiguration_MappingOmitted() { // Setup var config = new MappingConfiguration().Define(new Map <ManyDataTypesPoco>() .PartitionKey(c => c.StringType)); var table = new Table <ManyDataTypesPoco>(_session, config); table.Create(); // Test var mapper = new Mapper(_session, config); ManyDataTypesPoco manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); // Check results string cqlSelect = string.Format("SELECT * from \"{0}\" where \"{1}\"='{2}'", table.Name.ToLower(), "stringtype", manyTypesInstance.StringType); ManyDataTypesPoco.KeepTryingSelectAndAssert(mapper, cqlSelect, new List <ManyDataTypesPoco>() { manyTypesInstance }); }
public void CreateTable_FluentMapping_Success() { var mappingConfig = new MappingConfiguration().Define(new ManyDataTypesPocoMappingCaseSensitive()); var table = new Table <ManyDataTypesPoco>(Session, mappingConfig); table.Create(); VerifyQuery( "CREATE TABLE \"ManyDataTypesPoco\" " + $"({string.Join(", ", ManyDataTypesPoco.ColumnsToTypes.Select(k => $"\"{k.Key}\" {k.Value.Value}"))}, " + "PRIMARY KEY (\"StringType\"))", 1); var mapper = new Mapper(Session, mappingConfig); var manyTypesInstance = ManyDataTypesPoco.GetRandomInstance(); mapper.Insert(manyTypesInstance); VerifyBoundStatement( "INSERT INTO \"ManyDataTypesPoco\" (" + $"{string.Join(", ", ManyDataTypesPoco.ColumnsToTypes.Select(k => $"\"{k.Key}\""))})" + $" VALUES ({string.Join(", ", Enumerable.Range(0, ManyDataTypesPoco.ColumnsToTypes.Count).Select(_ => "?"))})", 1, ManyDataTypesPoco.Columns.Values.Select(func => func(manyTypesInstance)).ToArray()); var cqlSelect = $"SELECT * from \"{table.Name}\" where \"StringType\"='{manyTypesInstance.StringType}'"; TestCluster.PrimeFluent( b => b.WhenQuery(cqlSelect) .ThenRowsSuccess(ManyDataTypesPoco.GetColumnsAndTypes(), r => r.WithRow(manyTypesInstance.GetParameters()))); var instancesQueried = mapper.Fetch <ManyDataTypesPoco>(cqlSelect).ToList(); Assert.AreEqual(1, instancesQueried.Count); instancesQueried[0].AssertEquals(manyTypesInstance); }