public void PersistedTypeCorrectlySet() { var pocoDataFactory = new PocoDataFactory(new MapperCollection()); var pocoData = pocoDataFactory.ForType(typeof(SuperUser)); Assert.AreEqual(typeof(BaseUser), pocoData.Type); }
public void Test11() { var fakeReader = new FakeReader(); var pocoDataFactory = new PocoDataFactory(new MapperCollection()); var newPropertyMapper = new PropertyMapper(); var pocoData = pocoDataFactory.ForType(typeof(NestedConvention)); newPropertyMapper.Init(fakeReader, pocoData); newPropertyMapper.Map(fakeReader, new RowMapperContext() { PocoData = pocoData }); var sw = Stopwatch.StartNew(); for (int j = 0; j < 1000; j++) { newPropertyMapper = new PropertyMapper(); newPropertyMapper.Init(fakeReader, pocoData); for (int i = 0; i < 1000; i++) { newPropertyMapper.Map(fakeReader, new RowMapperContext() { PocoData = pocoData }); } } sw.Stop(); Console.WriteLine("Elapsed Time (ms): {0}", sw.ElapsedMilliseconds); //250 }
/// <summary> /// Builds a ICqlClient using the configuration you've defined via the configuration interface. /// </summary> public ICqlClient BuildCqlClient() { var pocoDataFactory = new PocoDataFactory(_typeDefinitions); return(new CqlClient(_session, new MapperFactory(_typeConverter, pocoDataFactory), new StatementFactory(_session), new CqlGenerator(pocoDataFactory))); }
public CqlGenerator(PocoDataFactory pocoDataFactory) { if (pocoDataFactory == null) { throw new ArgumentNullException("pocoDataFactory"); } _pocoDataFactory = pocoDataFactory; }
public void GenerateUpdate_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate<ExplicitColumnsUser>(); Assert.AreEqual("UPDATE users SET Name = ?, AGE = ? WHERE UserId = ?", cql); }
public void PrependUpdate_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("SET Name = ? WHERE UserId = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate<ExplicitColumnsUser>(cql); Assert.AreEqual("UPDATE users SET Name = ? WHERE UserId = ?", cql.Statement); }
public void Test1() { var pocoData = new PocoDataFactory(new MapperCollection()).ForType(typeof(RecursionUser)); Assert.AreEqual(4, pocoData.Members.Count); Assert.AreEqual("Id", pocoData.Members[0].Name); Assert.AreEqual("Name", pocoData.Members[1].Name); Assert.AreEqual("Supervisor", pocoData.Members[2].Name); Assert.AreEqual("CreatedBy", pocoData.Members[3].Name); }
public void AddSelect_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("WHERE UserId = ?", Guid.Empty); cqlGenerator.AddSelect<ExplicitColumnsUser>(cql); Assert.AreEqual("SELECT UserId, Name, AGE FROM users WHERE UserId = ?", cql.Statement); }
public void GenerateUpdate_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate <ExplicitColumnsUser>(); Assert.AreEqual("UPDATE users SET Name = ?, AGE = ? WHERE UserId = ?", cql); }
public void GenerateDelete_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("USERS").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete <ExplicitColumnsUser>(); Assert.AreEqual("DELETE FROM USERS WHERE UserId = ?", cql); }
public void PrependUpdate_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("SET Name = ? WHERE UserId = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate <ExplicitColumnsUser>(cql); Assert.AreEqual("UPDATE users SET Name = ? WHERE UserId = ?", cql.Statement); }
public void AddSelect_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("WHERE UserId = ?", Guid.Empty); cqlGenerator.AddSelect <ExplicitColumnsUser>(cql); Assert.AreEqual("SELECT UserId, Name, AGE FROM users WHERE UserId = ?", cql.Statement); }
public void NestedClassShouldBeMappedAsAComplexObject() { var pocoData = new PocoDataFactory(new MapperCollection()).ForType(typeof(ComplexMap)); Assert.AreEqual(7, pocoData.Columns.Count); Assert.AreEqual(true, pocoData.Columns.ContainsKey("Id")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("Name")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("NestedComplexMap__Id")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("NestedComplexMap__NestedComplexMap2__Id")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("NestedComplexMap__NestedComplexMap2__Name")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("NestedComplexMap2__Id")); Assert.AreEqual(true, pocoData.Columns.ContainsKey("NestedComplexMap2__Name")); }
public void PrependUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"SET ""Name"" = ? WHERE ""UserId"" = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate<ExplicitColumnsUser>(cql); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ? WHERE ""UserId"" = ?", cql.Statement); }
public void GenerateUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate<ExplicitColumnsUser>(); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ?, ""AGE"" = ? WHERE ""UserId"" = ?", cql); }
public void GenerateInsert_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(true, new object[0], out object[] queryParameters); Assert.AreEqual(@"INSERT INTO USERS (ID, Name, UserAge) VALUES (?, ?, ?)", cql); }
public void GenerateInsert_Without_Nulls_Should_Throw_When_Value_Length_Dont_Match_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); Assert.Throws <ArgumentException>(() => cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, new object[] { Guid.NewGuid() }, out object[] queryParameters)); }
public void GenerateInsert_CaseSensitive_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(true, new object[0], out object[] queryParameters); Assert.AreEqual(@"INSERT INTO ""USERS"" (""Name"", ""UserAge"", ""UserId"") VALUES (?, ?, ?)", cql); }
public void GenerateDelete_CaseSensitive_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete <ExplicitColumnsUser>(); Assert.AreEqual(@"DELETE FROM ""USERS"" WHERE ""ID"" = ?", cql); }
public void FluentConfigShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var pocoDataFactory = new PocoDataFactory(y => new PocoData(y, new Mapper())); var fluentConfig = new FluentConfig(x=>pocoDataFactory); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); x.WithFluentConfig(fluentConfig); }); var database = factory.GetDatabase(); Assert.AreEqual(fluentConfig.Config(null), database.PocoDataFactory); }
public void NestedClassShouldBeAbleToGetValue() { var pocoData = new PocoDataFactory(new MapperCollection()).ForType(typeof(ComplexMap)); var obj = new ComplexMap() { Name = "Bill", NestedComplexMap = new NestedComplexMap() { Id = 9 } }; var val = pocoData.Columns["NestedComplexMap__Id"].GetValue(obj); Assert.AreEqual(9, val); }
public void GenerateUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate <ExplicitColumnsUser>(); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ?, ""AGE"" = ? WHERE ""UserId"" = ?", cql); }
public void PrependUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"SET ""Name"" = ? WHERE ""UserId"" = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate <ExplicitColumnsUser>(cql); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ? WHERE ""UserId"" = ?", cql.Statement); }
public void AddSelect_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"WHERE ""UserId"" = ?", Guid.Empty); cqlGenerator.AddSelect <ExplicitColumnsUser>(cql); Assert.AreEqual(@"SELECT ""UserId"", ""Name"", ""AGE"" FROM ""users"" WHERE ""UserId"" = ?", cql.Statement); }
public void FluentConfigShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var pocoDataFactory = new PocoDataFactory((y, r) => new PocoData(y, new Mapper(), r)); var fluentConfig = new FluentConfig(x => pocoDataFactory); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); x.WithFluentConfig(fluentConfig); }); var database = factory.GetDatabase(); Assert.AreEqual(fluentConfig.Config(null), database.PocoDataFactory); }
public void GenerateInsert_Without_Nulls_First_Value_Null_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var values = new object[] { null, "name", 100 }; var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, values, out object[] queryParameters); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?)", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, values, out queryParameters, true); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?) IF NOT EXISTS", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); }
public void ColumnsDoesntContainPropertyDefinedInSuperType() { var pocoData = new PocoDataFactory(new MapperCollection()).ForType(typeof(SuperUser)); Assert.False(pocoData.Columns.ContainsKey("ExtraProp")); }
public void GenerateInsert_CaseSensitive_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(true, new object[0], out queryParameters); Assert.AreEqual(@"INSERT INTO ""USERS"" (""UserId"", ""Name"", ""UserAge"") VALUES (?, ?, ?)", cql); }
public void GenerateInsert_Without_Nulls_Should_Throw_When_Value_Length_Dont_Match_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; Assert.Throws<ArgumentException>(() => cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, new object[] { Guid.NewGuid()}, out queryParameters)); }
public void GenerateInsert_Without_Nulls_First_Value_Null_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var values = new object[] { null, "name", 100 }; object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, values, out queryParameters); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?)", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, values, out queryParameters, true); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?) IF NOT EXISTS", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); }
public CqlGenerator(PocoDataFactory pocoDataFactory) { _pocoDataFactory = pocoDataFactory ?? throw new ArgumentNullException(nameof(pocoDataFactory)); }
public void AddSelect_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"WHERE ""UserId"" = ?", Guid.Empty); cqlGenerator.AddSelect<ExplicitColumnsUser>(cql); Assert.AreEqual(@"SELECT ""UserId"", ""Name"", ""AGE"" FROM ""users"" WHERE ""UserId"" = ?", cql.Statement); }
public void GenerateDelete_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("USERS").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete<ExplicitColumnsUser>(); Assert.AreEqual("DELETE FROM USERS WHERE UserId = ?", cql); }
public void GenerateDelete_CaseSensitive_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete<ExplicitColumnsUser>(); Assert.AreEqual(@"DELETE FROM ""USERS"" WHERE ""ID"" = ?", cql); }
public void GenerateInsert_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(true, new object[0], out queryParameters); Assert.AreEqual(@"INSERT INTO USERS (ID, Name, UserAge) VALUES (?, ?, ?)", cql); }