Ejemplo n.º 1
0
        public void SelectAllProductsDto()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var product1 = new ProductDto {
                    Name = "Product #1"
                };
                dbConnection.Execute(new InsertProduct().Query(product1));

                var product2 = new ProductDto {
                    Name = "Product #2"
                };
                dbConnection.Execute(new InsertProduct().Query(product2));

                var product3 = new ProductDto {
                    Name = "Product #3"
                };
                dbConnection.Execute(new InsertProduct().Query(product3));

                QueryObject all = new SelectProduct().All();

                IEnumerable <ProductDto> productDtos = dbConnection.Query <ProductDto>(all);

                Assert.AreEqual(3, productDtos.Count());
            }
        }
Ejemplo n.º 2
0
        public void UpdateProductName()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var insertProduct = new InsertProduct();
                var product = new ProductDto {Name = "Product Name"};
                product.Id = (int) dbConnection.Query<Int64>(insertProduct.Query(product)).Single();

                var updateProduct = new UpdateProduct();
                dbConnection.Execute(updateProduct.NameForAllProducts("new name"));

                var selectProduct = new SelectProduct();
                ProductDto result = dbConnection.Query<ProductDto>(selectProduct.ById(product.Id)).Single();

                StringAssert.AreEqualIgnoringCase("new name", result.Name);
            }
        }
Ejemplo n.º 3
0
        public void SelectAllProductsDto()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq<ProductDto>();

                Assert.AreEqual(3, dbConnection.Query(query).Count());
            }
        }
Ejemplo n.º 4
0
        public void SelectAllProductsDto()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq <ProductDto>();

                Assert.AreEqual(3, dbConnection.Query(query).Count());
            }
        }
Ejemplo n.º 5
0
        public void SelectWithEndsWith()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq<ProductDto>()
                    .Where(x => x.Name.EndsWith(ThirdProductName));

                Assert.AreEqual(1, dbConnection.Query(query).Count());
            }
        }
Ejemplo n.º 6
0
        public void SelectWithEndsWith()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq <ProductDto>()
                            .Where(x => x.Name.EndsWith(ThirdProductName));

                Assert.AreEqual(1, dbConnection.Query(query).Count());
            }
        }
Ejemplo n.º 7
0
        public void UpdateProductName()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var insertProduct = new InsertProduct();
                var product       = new ProductDto {
                    Name = "Product Name"
                };
                product.Id = (int)dbConnection.Query <Int64>(insertProduct.Query(product)).Single();

                var updateProduct = new UpdateProduct();
                dbConnection.Execute(updateProduct.NameForAllProducts("new name"));

                var        selectProduct = new SelectProduct();
                ProductDto result        = dbConnection.Query <ProductDto>(selectProduct.ById(product.Id)).Single();

                StringAssert.AreEqualIgnoringCase("new name", result.Name);
            }
        }
Ejemplo n.º 8
0
        public void SelectProductDtoById()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq<ProductDto>()
                    .Where(x => x.Product_Id == 1);

                var firstProduct = dbConnection.Query(query).First();

                Assert.AreEqual(FirstProductName, firstProduct.Name);
            }
        }
Ejemplo n.º 9
0
        public void SelectProductDtoById()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var query = new SQLinq <ProductDto>()
                            .Where(x => x.Product_Id == 1);

                var firstProduct = dbConnection.Query(query).First();

                Assert.AreEqual(FirstProductName, firstProduct.Name);
            }
        }
Ejemplo n.º 10
0
        public void InsertAndFetchNewId()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var insertProduct = new InsertProduct();
                var product = new ProductDto {Name = "New Product"};

                product.Id = (int) dbConnection.Query<Int64>(insertProduct.Query(product)).Single();

                Assert.AreNotEqual(0, product.Id);
            }
        }
Ejemplo n.º 11
0
        public void SelectProductDtoById()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var product1 = new ProductDto {Name = "Product #1"};
                dbConnection.Execute(new InsertProduct().Query(product1));

                QueryObject byId = new SelectProduct().ById(1);
                ProductDto productDto = dbConnection.Query<ProductDto>(byId).SingleOrDefault();

                Assert.AreEqual(1, productDto.Id);
                Assert.AreEqual("Product #1", productDto.Name);
            }
        }
Ejemplo n.º 12
0
        public void InsertAndFetchNewId()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var insertProduct = new InsertProduct();
                var product       = new ProductDto {
                    Name = "New Product"
                };

                product.Id = (int)dbConnection.Query <Int64>(insertProduct.Query(product)).Single();

                Assert.AreNotEqual(0, product.Id);
            }
        }
Ejemplo n.º 13
0
        public void SelectProductDtoById()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var product1 = new ProductDto {
                    Name = "Product #1"
                };
                dbConnection.Execute(new InsertProduct().Query(product1));

                QueryObject byId       = new SelectProduct().ById(1);
                ProductDto  productDto = dbConnection.Query <ProductDto>(byId).SingleOrDefault();

                Assert.AreEqual(1, productDto.Id);
                Assert.AreEqual("Product #1", productDto.Name);
            }
        }
Ejemplo n.º 14
0
        public void SelectAllProductsDto()
        {
            using (IDbConnection dbConnection = new SqliteConnectionFactory().Create())
            {
                var product1 = new ProductDto {Name = "Product #1"};
                dbConnection.Execute(new InsertProduct().Query(product1));

                var product2 = new ProductDto {Name = "Product #2"};
                dbConnection.Execute(new InsertProduct().Query(product2));

                var product3 = new ProductDto {Name = "Product #3"};
                dbConnection.Execute(new InsertProduct().Query(product3));

                QueryObject all = new SelectProduct().All();

                IEnumerable<ProductDto> productDtos = dbConnection.Query<ProductDto>(all);

                Assert.AreEqual(3, productDtos.Count());
            }
        }