public void SelectWithContains() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product1 = new ProductDto { Name = "Product #1" }; dbConnection.Insert(product1); Assert.AreEqual(1, dbConnection.Select <ProductDto>(dto => dto.Name.Contains("odu")).Count); Assert.AreEqual(0, dbConnection.Select <ProductDto>(dto => dto.Name.Contains("odu ")).Count); } }
public void SelectWithLogicalExpression() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product1 = new ProductDto { Name = "Product #1" }; dbConnection.Insert(product1); Assert.AreEqual(0, dbConnection.Select <ProductDto>(dto => dto.Name == "Other name").Count); Assert.AreEqual(1, dbConnection.Select <ProductDto>(dto => dto.Name == "Product #1").Count); } }
public void DeleteProduct() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product = new ProductDto { Name = "New Product" }; dbConnection.Insert(product); dbConnection.Delete <ProductDto>(dto => dto.Id == dbConnection.LastInsertId()); Assert.IsNull(dbConnection.SingleById <ProductDto>(1)); } }
public void InsertAndFetchNewId() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product = new ProductDto { Name = "New Product" }; dbConnection.Insert(product); var result = dbConnection .Select <ProductDto>(p => p.Name == product.Name) .First(); Assert.AreNotEqual(0, result.Id); } }
public void UpdateProductByUpdateOnly() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product = new ProductDto { Name = "New Product" }; dbConnection.Insert(product); product.Name = "Changed name"; dbConnection.UpdateOnly(product, dto => new { dto.Name }, dto => dto.Id == 1); Assert.NotNull(dbConnection.Single <ProductDto>(dto => dto.Name == product.Name)); } }
public void SelectWithInExpression() { using (IDbConnection dbConnection = SqliteConnectionFactory.Create()) { var product1 = new ProductDto { Name = "Product #1" }; dbConnection.Insert(product1); var product2 = new ProductDto { Name = "Product #2" }; dbConnection.Insert(product2); var product3 = new ProductDto { Name = "Product #3" }; dbConnection.Insert(product3); Assert.AreEqual(3, dbConnection.Select <ProductDto>(dto => Sql.In(dto.Name, "Product #1", "Product #2", "Product #3", "Other")).Count); } }