public void ThrowExceptionIfSelectIsNull()
        {
            var sut = new SqlQueryGenerator(null, null, null, null);
            var argumentException = Assert.Throws <ArgumentException>(() => sut.ToString());

            Assert.Equal("Query Must Have a Select Part", argumentException.Message);
        }
Beispiel #2
0
 public List <Product> GetAll()
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Product>())
     {
         return((List <Product>)dapperService.GetAll <Product>(sqlquerygenerator.GetSelectAll()));
     }
 }
Beispiel #3
0
 public Int32 Insert(Supplier supplier)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Supplier>())
     {
         return(dapperService.Insert <Supplier>(sqlquerygenerator.GetInsert(), supplier));
     }
 }
Beispiel #4
0
 public Int32 Insert(Product product)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Product>())
     {
         return(dapperService.Insert <Product>(sqlquerygenerator.GetInsert(), product));
     }
 }
Beispiel #5
0
 public Product Get(Int32 Id)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Product>())
     {
         return(dapperService.Get <Product>(sqlquerygenerator.GetSelect(new { Id }), Id));
     }
 }
 public Int32 Insert(Customer customer)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Customer>())
     {
         return(dapperService.Insert <Customer>(sqlquerygenerator.GetInsert(), customer));
     }
 }
 public Int32 Update(Customer customer)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Customer>())
     {
         return(dapperService.Update <Customer>(sqlquerygenerator.GetUpdate(), customer));
     }
 }
 public Int32 Insert(Tax tax)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Tax>())
     {
         return(dapperService.Insert <Tax>(sqlquerygenerator.GetInsert(), tax));
     }
 }
 public Int32 Update(Tax product)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Tax>())
     {
         return(dapperService.Update <Tax>(sqlquerygenerator.GetUpdate(), product));
     }
 }
 public Category Get(Int32 Id)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Category>())
     {
         return(dapperService.Get <Category>(sqlquerygenerator.GetSelect(new { Id }), Id));
     }
 }
 public List <Category> GetAll()
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Category>())
     {
         return((List <Category>)dapperService.GetAll <Category>(sqlquerygenerator.GetSelectAll()));
     }
 }
 public Int32 Update(Category category)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Category>())
     {
         return(dapperService.Update <Category>(sqlquerygenerator.GetUpdate(), category));
     }
 }
 public Int32 Insert(Category category)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Category>())
     {
         return(dapperService.Insert <Category>(sqlquerygenerator.GetInsert(), category));
     }
 }
        public async Task <T> GetByIdAsync(int id)
        {
            (string query, QueryParameter[] parameters) = SqlQueryGenerator.GenerateSelectQuery(id);

            return(await template.QuerySingleObjectAsync(query, RowMapper, parameters)
                   .ConfigureAwait(false));
        }
        public void GenerateGetLastIndentyQueryTest()
        {
            string expected = "SELECT IDENT_CURRENT('[Hurace].[Skier]')";
            string actual   = new SqlQueryGenerator <Entities.Skier>().GenerateGetLastIdentityQuery();

            Assert.Equal(expected, actual);
        }
Beispiel #16
0
 public Int32 Update(Supplier supplier)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Supplier>())
     {
         return(dapperService.Update <Supplier>(sqlquerygenerator.GetUpdate(), supplier));
     }
 }
        public void GenerateDeleteWithConditionsParameterTest()
        {
            var condition = new QueryConditionBuilder()
                            .DeclareConditionNode(
                QueryConditionNodeType.And,
                () => new QueryConditionBuilder().DeclareCondition("FirstName", QueryConditionType.NotEquals, "Stevenie"),
                () => new QueryConditionBuilder()
                .DeclareConditionNode(
                    QueryConditionNodeType.Or,
                    () => new QueryConditionBuilder()
                    .DeclareCondition("LastName", QueryConditionType.NotEquals, "Zeitlhofinger"),
                    () => new QueryConditionBuilder()
                    .DeclareCondition("LastName", QueryConditionType.Like, "Halbmayr")))
                            .Build();

            string expectedQuery = "DELETE FROM [Hurace].[Skier] " +
                                   "WHERE ([FirstName] != @FirstName0 AND ([LastName] != @LastName0 OR [LastName] LIKE @LastName1))";

            var queryGenerator = new SqlQueryGenerator <Entities.Skier>();

            (var actualQuery, var actualQueryParameters) = queryGenerator.GenerateDeleteQuery(condition);

            Assert.Equal(expectedQuery, actualQuery);
            Assert.Equal(3, actualQueryParameters.Length);

            var firstNameParameter = actualQueryParameters.First(qp => qp.ParameterName == "FirstName0");
            var lastNameParameter1 = actualQueryParameters.First(qp => qp.ParameterName == "LastName0");
            var lastNameParameter2 = actualQueryParameters.First(qp => qp.ParameterName == "LastName1");

            Assert.Equal("Stevenie", firstNameParameter.Value);
            Assert.Equal("Zeitlhofinger", lastNameParameter1.Value);
            Assert.Equal("Halbmayr", lastNameParameter2.Value);
        }
Beispiel #18
0
 public Supplier Get(Int32 Id)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Supplier>())
     {
         return(dapperService.Get <Supplier>(sqlquerygenerator.GetSelect(new { Id }), Id));
     }
 }
Beispiel #19
0
        public IEnumerable <T> GetAll()
        {
            SqlQueryGenerator <T> queryGenerator = new SqlQueryGenerator <T>();

            string selectQuery = queryGenerator.GenerateSelectQuery(typeof(T));

            using (SqlCommand command = new SqlCommand(selectQuery, _Connection))
            {
                using (SqlDataReader rd = command.ExecuteReader())
                {
                    while (rd.Read())
                    {
                        object obj = Activator.CreateInstance(typeof(T));

                        PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

                        foreach (var property in propertyInfos)
                        {
                            property.SetValue(obj, rd[property.Name]);
                        }
                        yield return(obj as T);
                    }
                }
            }
        }
Beispiel #20
0
        public T Get(K itemKey)
        {
            //default acar sozu ile instance yarat
            //misal: eger T int tipinde olarsa ozaman       :  int item = new int() ,stringdirse  :   string item = new string()  olur
            T item = default(T);

            SqlQueryGenerator <T> queryGenerator = new SqlQueryGenerator <T>();

            string deleteQuery = queryGenerator.GenerateSelectByIdQuery <K>(itemKey);

            using (SqlCommand command = new SqlCommand(deleteQuery, _Connection))
            {
                using (SqlDataReader rd = command.ExecuteReader())
                {
                    while (rd.Read())
                    {
                        object obj = Activator.CreateInstance(typeof(T));

                        PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

                        foreach (var property in propertyInfos)
                        {
                            property.SetValue(obj, rd[property.Name]);
                        }
                        item = obj as T;
                    }
                }
            }
            return(item);
        }
 public Int32 UpdateInvoice(Invoice invoice)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Invoice>())
     {
         return(dapperService.Insert <Invoice>(sqlquerygenerator.GetUpdate(), invoice));
     }
 }
        public Invoice GetInvoice(Int32 Id)
        {
            Invoice invoice = null;

            using (var sqlquerygenerator = new SqlQueryGenerator <Invoice>())
            {
                SqlMapper.GridReader gridReader = dapperService.QueryMultiple("", new { Id });

                invoice = gridReader.Read <Invoice>().SingleOrDefault();

                if (invoice != null)
                {
                    invoice.InvoiceDetails = gridReader.Read <InvoiceDetails>().ToList();
                    invoice.Customer       = gridReader.Read <Customer>().SingleOrDefault();
                    invoice.Tax            = gridReader.Read <Tax>().SingleOrDefault();
                    List <Product>  products  = gridReader.Read <Product>().ToList();
                    List <Discount> discounts = gridReader.Read <Discount>().ToList();

                    foreach (InvoiceDetails invoiceDetails in invoice.InvoiceDetails)
                    {
                        invoiceDetails.Products = products.Where(a => a.Id == invoiceDetails.ProductId).SingleOrDefault();
                        invoiceDetails.Discount = discounts.Where(a => a.Id == invoiceDetails.DiscountId).SingleOrDefault();
                    }
                }
            }


            return(invoice);
        }
 public List <InvoiceDetails> GetAllInvDetail()
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <InvoiceDetails>())
     {
         return((List <InvoiceDetails>)dapperService.GetAll <Tax>(sqlquerygenerator.GetSelectAll()));
     }
 }
 public InvoiceDetails GetInvDetail(Int32 Id)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <InvoiceDetails>())
     {
         return(dapperService.Get <InvoiceDetails>(sqlquerygenerator.GetSelect(new { Id }), Id));
     }
 }
 public Int32 InsertInvDetail(InvoiceDetails invoiceDetails)
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <InvoiceDetails>())
     {
         return(dapperService.Insert <InvoiceDetails>(sqlquerygenerator.GetInsert(), invoiceDetails));
     }
 }
Beispiel #26
0
 public List <Supplier> GetAll()
 {
     using (var sqlquerygenerator = new SqlQueryGenerator <Supplier>())
     {
         return((List <Supplier>)dapperService.GetAll <Supplier>(sqlquerygenerator.GetSelectAll()));
     }
 }
Beispiel #27
0
        public void GenerateUpdateQuery_AllColumnsHasNoSetter_Throws()
        {
            // Arrange
            var generator = new SqlQueryGenerator <AllColumnsHasMissingSetterEntity>("dbo", "Users");

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery());
        }
Beispiel #28
0
        public void GenerateUpdateQuery_NoPrimaryKey_Throws()
        {
            // Arrange
            var generator = new SqlQueryGenerator <HeapEntity>("dbo", "Users");

            // Act && Assert
            Assert.Throws <InvalidOperationException>(() => generator.GenerateUpdateQuery());
        }
 public async Task <IEnumerable <T> > GetAllConditionalAsync(IQueryCondition condition = null)
 {
     (var query, var queryParameters) = SqlQueryGenerator.GenerateSelectQuery(condition);
     return(await template.QueryObjectSetAsync(
                query,
                RowMapper,
                queryParameters)
            .ConfigureAwait(false));
 }
        public async Task <bool> DeleteByIdAsync(int id)
        {
            (string query, QueryParameter[] parameters) = SqlQueryGenerator.GenerateDeleteQuery(id);

            int numberOfAffectedRows = await template.ExecuteAsync(query, parameters)
                                       .ConfigureAwait(false);

            return(numberOfAffectedRows == 1);
        }
        public void Generate_WithMockedDependencies_GeneratesCorrectSelectAndJoinSyntax()
        {
            var parsedLambdaFake = new Mock<IParsedLambda>();
            var lamdaParserFake = new Mock<ILambdaParser>();
            lamdaParserFake.Setup(x => x.Parse(It.IsAny<Expression<Func<MyClass, bool>>>())).Returns(parsedLambdaFake.Object);
            var sqlQueryFake = new Mock<ISqlQuery>();
            sqlQueryFake.Setup(x => x.Sql).Returns("1 = 1");
            sqlQueryFake.Setup(x => x.Parameters).Returns(new List<IQueryParameter>());
            var parsedLambdaProcessorFake = new Mock<IParsedLambdaProcessor<ISqlQuery>>();
            parsedLambdaProcessorFake.Setup(x => x.Process(It.IsAny<IParsedLambda>())).Returns(sqlQueryFake.Object);
            var schemaFake = new Mock<IStructureSchema>();
            schemaFake.Setup(x => x.Name).Returns("MyClass");

            var generator = new SqlQueryGenerator(lamdaParserFake.Object, parsedLambdaProcessorFake.Object);
            var sqlQuery = generator.Generate<MyClass>(m => m.Int1 == 42, schemaFake.Object);

            var expectedSql = "select s.Json from [dbo].[MyClassStructure] as s "
                + "inner join [dbo].[MyClassIndexes] as si on si.StructureId = s.Id where 1 = 1";
            Assert.AreEqual(expectedSql, sqlQuery.Sql);
        }