public void SqliteInMemoryTest() { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <PersionContext>() .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new PersionContext(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new PersionContext(options)) { context.AddRange(CreatePersions()); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new PersionContext(options)) { var qe = new huypq.QueryBuilder.QueryExpression(); qe.AddOrderByOption(nameof(Persion.Name), false); qe.WhereOptions.Add(new huypq.QueryBuilder.WhereExpression.WhereOptionNullableBool("=", nameof(Persion.HasChildren), null)); qe.WhereOptions.Add(new huypq.QueryBuilder.WhereExpression.WhereOptionDate("=", nameof(Persion.DOB), new System.DateTime(2018, 02, 01))); qe.WhereOptions.Add(new huypq.QueryBuilder.WhereExpression.WhereOptionByteArray("=", nameof(Persion.Secret), new byte[] { 2, 1, 3, 4 })); var data = huypq.QueryBuilder.QueryExpression.AddQueryExpression(context.Persions, ref qe, out int pageCount); var sqlString = data.ToSql(); System.Console.WriteLine(sqlString); Assert.AreEqual(1, data.ToList().Count()); Assert.AreEqual(1, pageCount); } } finally { connection.Close(); } }
public void SqliteInMemory_WhereOptionStringList_Test() { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <PersionContext>() .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new PersionContext(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new PersionContext(options)) { context.AddRange(CreatePersions()); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new PersionContext(options)) { var qe = new huypq.QueryBuilder.QueryExpression(); qe.WhereOptions.Add(new huypq.QueryBuilder.WhereExpression.WhereOptionStringList(nameof(Persion.Name), new System.Collections.Generic.List <string> { "A", "C" })); var data = huypq.QueryBuilder.QueryExpression.AddQueryExpression(context.Persions, ref qe, out int pageCount); var sqlString = data.ToSql(); System.Console.WriteLine(sqlString); Assert.AreEqual(1, data.ToList().Count()); Assert.AreEqual(1, pageCount); } } finally { connection.Close(); } }