示例#1
0
        public async Task SelectAsyncContains(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var products = await con.SelectAsync <Product>(p => p.Name.Contains("Anton"));

                Assert.Equal(4, products.Count());
            }
        }
示例#2
0
 public void Get(DatabaseDriver database)
 {
     using (var con = database.GetConnection())
     {
         var product = con.Get <Product>(1);
         Assert.NotNull(product);
         Assert.NotEmpty(product.Name);
     }
 }
示例#3
0
        public async Task SelectAsyncEqual(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var products = await con.SelectAsync <Product>(p => p.CategoryId == 1);

                Assert.Equal(10, products.Count());
            }
        }
示例#4
0
 public void Project(DatabaseDriver database)
 {
     using (var con = database.GetConnection())
     {
         var p = con.Project <ProductSmall>(1);
         Assert.NotEqual(0, p.Id);
         Assert.NotNull(p.Name);
     }
 }
示例#5
0
        public async Task SelectAndStatementAsync(DatabaseDriver database)
        {
            using var con = database.GetConnection();
            var id = await InsertLeadAsync(con);

            var leads = await con.SelectAsync <Lead>(p => p.Data !.FirstName == "Foo" && p.Data.LastName == "Bar" && p.Email == "*****@*****.**");

            Assert.NotEmpty(leads);
        }
示例#6
0
        public void OrStatement(DatabaseDriver database)
        {
            using var con = database.GetConnection();
            var id = InsertLead(con);

            Assert.True(con.DeleteMultiple <Lead>(p => p.Data !.FirstName == "Foo" && p.Data.LastName == "Bar" || p.Email == "*****@*****.**"));
            var leads = con.Select <Lead>(p => p.Data !.FirstName == "Foo" && p.Data.LastName == "Bar" || p.Email == "*****@*****.**");

            Assert.Empty(leads);
        }
示例#7
0
        public async Task SingleStatementAsync(DatabaseDriver database)
        {
            using var con = database.GetConnection();
            var id = await InsertLeadAsync(con);

            Assert.True(await con.DeleteMultipleAsync <Lead>(p => p.Data !.Email == "*****@*****.**"));
            var leads = await con.SelectAsync <Lead>(p => p.Data !.Email == "*****@*****.**");

            Assert.Empty(leads);
        }
示例#8
0
        public void SingleStatement(DatabaseDriver database)
        {
            using var con = database.GetConnection();
            var id = InsertLead(con);

            Assert.True(con.DeleteMultiple <Lead>(p => p.Data !.Email == "*****@*****.**"));
            var leads = con.Select <Lead>(p => p.Data !.Email == "*****@*****.**");

            Assert.Empty(leads);
        }
示例#9
0
        public void SelectAsyncContainsVariable(DatabaseDriver database)
        {
            var productName = "Anton";

            using (var con = database.GetConnection())
            {
                Action action = () => con.SelectAsync <Product>(p => p.Name.Contains(productName));
                action.Should().Throw <InvalidCastException>();
            }
        }
示例#10
0
        public async Task GetAllAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var products = await con.GetAllAsync <Product>();

                Assert.NotEmpty(products);
                Assert.All(products, p => Assert.NotEmpty(p.Name));
            }
        }
示例#11
0
        public void SelectAsyncEndsWith(DatabaseDriver database)
        {
            var productName = "2";

            using (var con = database.GetConnection())
            {
                Action action = () => con.SelectAsync <Product>(p => p.Name.EndsWith(productName));
                action.Should().Throw <InvalidCastException>();
            }
        }
示例#12
0
        public async Task GetAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var product = await con.GetAsync <Product>(1);

                Assert.NotNull(product);
                Assert.NotEmpty(product.Name);
            }
        }
示例#13
0
        public async Task ProjectAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var p = await con.ProjectAsync <ProductSmall>(1);

                Assert.NotEqual(0, p.Id);
                Assert.NotNull(p.Name);
            }
        }
示例#14
0
 public void ProjectPagedAll(DatabaseDriver database)
 {
     using (var con = database.GetConnection())
     {
         var ps = con.ProjectPaged <ProductSmall>(pageNumber: 1, pageSize: 5);
         Assert.NotEmpty(ps);
         Assert.All(ps, p =>
         {
             Assert.NotEqual(0, p.Id);
             Assert.NotNull(p.Name);
         });
     }
 }
示例#15
0
        public async Task ProjectAllAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var ps = await con.ProjectAllAsync <ProductSmall>();

                Assert.NotEmpty(ps);
                Assert.All(ps, p =>
                {
                    Assert.NotEqual(0, p.Id);
                    Assert.NotNull(p.Name);
                });
            }
        }
示例#16
0
 public void Fetches_FirstPage(DatabaseDriver database)
 {
     using (var con = database.GetConnection())
     {
         var paged = con.GetPaged <Product>(1, 5).ToArray();
         Assert.Equal(5, paged.Length);
         Assert.Collection(paged,
                           p => Assert.Equal("Chai", p.Name),
                           p => Assert.Equal("Chang", p.Name),
                           p => Assert.Equal("Aniseed Syrup", p.Name),
                           p => Assert.Equal("Chef Anton's Cajun Seasoning", p.Name),
                           p => Assert.Equal("Chef Anton's Gumbo Mix", p.Name));
     }
 }
示例#17
0
        public void Update(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var product = con.Get <Product>(1);
                Assert.NotNull(product);

                product.Name = "Test";
                con.Update(product);

                var newProduct = con.Get <Product>(1);
                Assert.Equal("Test", newProduct.Name);
            }
        }
示例#18
0
        public void Insert(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var id = Convert.ToInt32(con.Insert(new Product {
                    Name = "blah"
                }));
                var product = con.Get <Product>(id);

                product.Should().NotBeNull();
                product.Name.Should().Be("blah");
                product.Id.Should().Be(id);
            }
        }
示例#19
0
        public async Task InsertAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var id = Convert.ToInt32(await con.InsertAsync(new Product {
                    Name = "blah"
                }));
                var product = await con.GetAsync <Product>(id);

                product.Should().NotBeNull();
                product.Name.Should().Be("blah");
                product.Id.Should().Be(id);
            }
        }
示例#20
0
        public void SelectSingleStatement(DatabaseDriver database)
        {
            using var con = database.GetConnection();
            // Arrange
            var lead = InsertLead(con);

            // Act
            lead.Data !.FirstName = "Bar";
            con.Update(lead);

            // Assert
            var updatedLead = con.Get <Lead>(lead.Id);

            Assert.Equal("Bar", updatedLead.Data?.FirstName);
        }
示例#21
0
        public void Delete(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var id = Convert.ToInt32(con.Insert(new Product {
                    Name = "blah"
                }));
                var product = con.Get <Product>(id);
                Assert.NotNull(product);
                Assert.Equal("blah", product.Name);
                Assert.Equal(id, product.Id);

                con.Delete(product);
                Assert.Null(con.Get <Product>(id));
            }
        }
示例#22
0
        public async Task UpdateAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var product = await con.GetAsync <Product>(1);

                Assert.NotNull(product);

                product.Name = "Test";
                con.Update(product);

                var newProduct = await con.GetAsync <Product>(1);

                Assert.Equal("Test", newProduct.Name);
            }
        }
示例#23
0
        public async Task GetAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var product = await con.GetAsync <Product, Category, Product>((p, c) =>
                {
                    p.Category = c;
                    return(p);
                }, 1);

                Assert.NotNull(product);
                Assert.NotEmpty(product.Name);
                Assert.NotNull(product.Category);
                Assert.NotNull(product.Category.Name);
            }
        }
示例#24
0
        public async Task SelectSingleStatementAsync(DatabaseDriver database)
        {
            using var con = database.GetConnection();

            // Arrange
            var lead = await InsertLeadAsync(con);

            // Act
            lead.Data !.FirstName = "Bar";
            con.Update(lead);

            // Assert
            var updatedLead = con.Get <Lead>(lead.Id);

            Assert.NotNull(updatedLead);
            Assert.Equal("Bar", updatedLead !.Data?.FirstName);
        }
示例#25
0
        public async Task DeleteAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var id = Convert.ToInt32(await con.InsertAsync(new Product {
                    Name = "blah"
                }));
                var product = await con.GetAsync <Product>(id);

                Assert.NotNull(product);
                Assert.Equal("blah", product.Name);
                Assert.Equal(id, product.Id);

                await con.DeleteAsync(product);

                Assert.Null(await con.GetAsync <Product>(id));
            }
        }
示例#26
0
        public void InsertAll(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var ps = new List <Foo>
                {
                    new Foo {
                        Name = "blah"
                    },
                    new Foo {
                        Name = "blah"
                    },
                    new Foo {
                        Name = "blah"
                    },
                };

                con.InsertAll(ps);

                var blahs = con.Select <Foo>(p => p.Name == "blah");
                blahs.Count().Should().Be(3);
            }
        }
示例#27
0
        public async Task DeleteMultipleAsyncLike(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var ps = new List <Product>
                {
                    new Product {
                        Name = "blah"
                    },
                    new Product {
                        Name = "blah"
                    },
                    new Product {
                        Name = "blah"
                    },
                };

                await con.InsertAllAsync(ps);

                Assert.Equal(3, (await con.SelectAsync <Product>(p => p.Name == "blah")).Count());

                con.DeleteMultiple <Product>(p => p.Name.Contains("bla"));
            }
        }
示例#28
0
        public async Task InsertAllAsync(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var ps = new List <Bar>
                {
                    new Bar {
                        Name = "blah"
                    },
                    new Bar {
                        Name = "blah"
                    },
                    new Bar {
                        Name = "blah"
                    },
                };

                await con.InsertAllAsync(ps);

                var blahs = await con.SelectAsync <Bar>(p => p.Name == "blah");

                blahs.Count().Should().Be(3);
            }
        }
示例#29
0
        public void DeleteMultiple(DatabaseDriver database)
        {
            using (var con = database.GetConnection())
            {
                var ps = new List <Product>
                {
                    new Product {
                        Name = "blah"
                    },
                    new Product {
                        Name = "blah"
                    },
                    new Product {
                        Name = "blah"
                    },
                };

                con.InsertAll(ps);

                Assert.Equal(3, con.Select <Product>(p => p.Name == "blah").Count());

                con.DeleteMultiple <Product>(p => p.Name == "blah");
            }
        }
示例#30
0
 public async Task SelectSingleStatementAsync(DatabaseDriver database)
 {
     using var con = database.GetConnection();
     var lead = await InsertLeadAsync(con);
 }