Beispiel #1
0
        public void ToSQL_001()
        {
            var data = new Person
            {
                FirstName = "Chris",
                LastName  = "Pietschmann"
            };
            var target = new SQLinqInsert <Person>(data);
            var actual = (SQLinqInsertResult)target.ToSQL();

            Assert.AreEqual("[Person]", actual.Table);

            Assert.AreEqual(7, actual.Fields.Count);
            Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]);
            Assert.AreEqual("@sqlinq_2", actual.Fields["FirstName"]);
            Assert.AreEqual("@sqlinq_3", actual.Fields["LastName"]);
            Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]);
            Assert.AreEqual("@sqlinq_5", actual.Fields["[Is_Employed]"]);
            Assert.AreEqual("@sqlinq_6", actual.Fields["ParentID"]);
            Assert.AreEqual("@sqlinq_7", actual.Fields["Column With Spaces"]);

            Assert.AreEqual(7, actual.Parameters.Count);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]);
            Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]);
            Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]);
            Assert.AreEqual(false, actual.Parameters["@sqlinq_5"]);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_6"]);
            Assert.AreEqual(null, actual.Parameters["@sqlinq_7"]);
        }
Beispiel #2
0
        public void Execute_004_IdentityInsert_Int()
        {
            var expected = new IdentityTest_Int
            {
                Name = "Wes"
            };

            using (var con = GetDBConnection())
            {
                con.Open();
                var trans = con.BeginTransaction();

                try
                {
                    var query = new SQLinqInsert <IdentityTest_Int>(expected);

                    var id = con.Execute <int>(query, trans);


                    var actual = con.Query(from p in new SQLinq <IdentityTest_Int>()
                                           where p.Id != default(int)
                                           select p, trans).FirstOrDefault();

                    Assert.IsNotNull(actual);
                    Assert.AreNotEqual(default(int), actual.Id);
                    Assert.AreEqual(id, actual.Id);
                }
                finally
                {
                    trans.Rollback();
                    con.Close();
                }
            }
        }
Beispiel #3
0
        public void ToSQL_004()
        {
            var data = new PersonInsert
            {
                FirstName = "Chris",
                LastName  = "Pietschmann"
            };
            var target = new SQLinqInsert <PersonInsert>(data);
            var actual = (SQLinqInsertResult)target.ToSQL(42, "foo");

            Assert.AreEqual("[PersonInsert]", actual.Table);

            Assert.AreEqual(6, actual.Fields.Count);
            Assert.AreEqual("@foo43", actual.Fields["FirstName"]);
            Assert.AreEqual("@foo44", actual.Fields["LastName"]);
            Assert.AreEqual("@foo45", actual.Fields["Age"]);
            Assert.AreEqual("@foo46", actual.Fields["IsEmployed"]);
            Assert.AreEqual("@foo47", actual.Fields["ParentID"]);
            Assert.AreEqual("@foo48", actual.Fields["Column With Spaces"]);

            Assert.AreEqual(6, actual.Parameters.Count);
            Assert.AreEqual("Chris", actual.Parameters["@foo43"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@foo44"]);
            Assert.AreEqual(0, actual.Parameters["@foo45"]);
            Assert.AreEqual(false, actual.Parameters["@foo46"]);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@foo47"]);
            Assert.AreEqual(null, actual.Parameters["@foo48"]);
        }
        public void ToSQL_001()
        {
            var data = new Person
            {
                FirstName = "Chris",
                LastName = "Pietschmann"
            };
            var target = new SQLinqInsert<Person>(data);
            var actual = (SQLinqInsertResult)target.ToSQL();

            Assert.AreEqual("[Person]", actual.Table);

            Assert.AreEqual(7, actual.Fields.Count);
            Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]);
            Assert.AreEqual("@sqlinq_2", actual.Fields["FirstName"]);
            Assert.AreEqual("@sqlinq_3", actual.Fields["LastName"]);
            Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]);
            Assert.AreEqual("@sqlinq_5", actual.Fields["[Is_Employed]"]);
            Assert.AreEqual("@sqlinq_6", actual.Fields["ParentID"]);
            Assert.AreEqual("@sqlinq_7", actual.Fields["Column With Spaces"]);

            Assert.AreEqual(7, actual.Parameters.Count);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]);
            Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]);
            Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]);
            Assert.AreEqual(false, actual.Parameters["@sqlinq_5"]);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_6"]);
            Assert.AreEqual(null, actual.Parameters["@sqlinq_7"]);
        }
        public void ToQuery_001()
        {
            var data = new Person
            {
                FirstName = "Chris",
                LastName = "Pietschmann"
            };
            var target = new SQLinqInsert<Person>(data);
            var result = target.ToSQL();
            var actual = result.ToQuery();

            Assert.AreEqual("INSERT [Person] ([ID], [FirstName], [LastName], [Age], [Is_Employed], [ParentID], [Column With Spaces]) VALUES (@sqlinq_1, @sqlinq_2, @sqlinq_3, @sqlinq_4, @sqlinq_5, @sqlinq_6, @sqlinq_7)", actual);
        }
Beispiel #6
0
        public void ToQuery_001()
        {
            var data = new Person
            {
                FirstName = "Chris",
                LastName  = "Pietschmann"
            };
            var target = new SQLinqInsert <Person>(data);
            var result = target.ToSQL();
            var actual = result.ToQuery();

            Assert.AreEqual("INSERT [Person] ([ID], [FirstName], [LastName], [Age], [Is_Employed], [ParentID], [Column With Spaces]) VALUES (@sqlinq_1, @sqlinq_2, @sqlinq_3, @sqlinq_4, @sqlinq_5, @sqlinq_6, @sqlinq_7)", actual);
        }
Beispiel #7
0
        public void Incluir(Solicitacao_DepositoDO dtoDeposito, Erro objErro, ref TransactionManager objTransaction)
        {
            try
            {
                this.Validar_Incluir(dtoDeposito, objErro, ref objTransaction);

                if (objErro.TemErro())
                {
                    return;
                }

                var insert = new SQLinqInsert <Solicitacao_DepositoDO>(dtoDeposito);

                SqlHelper.ExecuteScalar(objTransaction.ObjetoDeAcessoDados, insert).DefaultInteger();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void Execute_001()
        {
            var expected = new Person
            {
                ID        = Guid.NewGuid(),
                FirstName = "Steven",
                LastName  = "Johnston",
                Age       = 1065
            };

            using (var con = GetDBConnection())
            {
                con.Open();
                var trans = con.BeginTransaction();

                try
                {
                    var query = new SQLinqInsert <Person>(expected);

                    con.Execute(query, trans);


                    var actual = con.Query(from p in new SQLinq <Person>()
                                           where p.ID == expected.ID
                                           select p, trans).FirstOrDefault();

                    Assert.IsNotNull(actual);
                    Assert.AreEqual(expected.ID, actual.ID);
                    Assert.AreEqual(expected.FirstName, actual.FirstName);
                    Assert.AreEqual(expected.LastName, actual.LastName);
                    Assert.AreEqual(expected.Age, actual.Age);
                }
                finally
                {
                    trans.Rollback();
                    con.Close();
                }
            }
        }
        public void Execute_001()
        {
            var expected = new Person
            {
                ID = Guid.NewGuid(),
                FirstName = "Steven",
                LastName = "Johnston",
                Age = 1065
            };

            using (var con = GetDBConnection())
            {
                con.Open();
                var trans = con.BeginTransaction();

                try
                {
                    var query = new SQLinqInsert<Person>(expected);

                    con.Execute(query, trans);

                    var actual = con.Query(from p in new SQLinq<Person>()
                                           where p.ID == expected.ID
                                           select p, trans).FirstOrDefault();

                    Assert.IsNotNull(actual);
                    Assert.AreEqual(expected.ID, actual.ID);
                    Assert.AreEqual(expected.FirstName, actual.FirstName);
                    Assert.AreEqual(expected.LastName, actual.LastName);
                    Assert.AreEqual(expected.Age, actual.Age);
                }
                finally
                {
                    trans.Rollback();
                    con.Close();
                }
            }
        }
Beispiel #10
0
        public void ToSQL_002()
        {
            var data = new PersonView
            {
                FirstName = "Chris",
                LastName  = "Pietschmann"
            };
            var target = new SQLinqInsert <PersonView>(data);
            var actual = (SQLinqInsertResult)target.ToSQL();

            Assert.AreEqual("[vw_Person]", actual.Table);

            Assert.AreEqual(4, actual.Fields.Count);
            Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]);
            Assert.AreEqual("@sqlinq_2", actual.Fields["First_Name"]);
            Assert.AreEqual("@sqlinq_3", actual.Fields["Last_Name"]);
            Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]);

            Assert.AreEqual(4, actual.Parameters.Count);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]);
            Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]);
            Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]);
        }
Beispiel #11
0
        public void ToSQL_002()
        {
            var data = new PersonView
            {
                FirstName = "Chris",
                LastName = "Pietschmann"
            };
            var target = new SQLinqInsert<PersonView>(data);
            var actual = (SQLinqInsertResult)target.ToSQL();

            Assert.AreEqual("[vw_Person]", actual.Table);

            Assert.AreEqual(4, actual.Fields.Count);
            Assert.AreEqual("@sqlinq_1", actual.Fields["ID"]);
            Assert.AreEqual("@sqlinq_2", actual.Fields["First_Name"]);
            Assert.AreEqual("@sqlinq_3", actual.Fields["Last_Name"]);
            Assert.AreEqual("@sqlinq_4", actual.Fields["Age"]);

            Assert.AreEqual(4, actual.Parameters.Count);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@sqlinq_1"]);
            Assert.AreEqual("Chris", actual.Parameters["@sqlinq_2"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@sqlinq_3"]);
            Assert.AreEqual(0, actual.Parameters["@sqlinq_4"]);
        }
Beispiel #12
0
        public void ToSQL_004()
        {
            var data = new PersonInsert
            {
                FirstName = "Chris",
                LastName = "Pietschmann"
            };
            var target = new SQLinqInsert<PersonInsert>(data);
            var actual = (SQLinqInsertResult)target.ToSQL(42, "foo");

            Assert.AreEqual("[PersonInsert]", actual.Table);

            Assert.AreEqual(6, actual.Fields.Count);
            Assert.AreEqual("@foo43", actual.Fields["FirstName"]);
            Assert.AreEqual("@foo44", actual.Fields["LastName"]);
            Assert.AreEqual("@foo45", actual.Fields["Age"]);
            Assert.AreEqual("@foo46", actual.Fields["IsEmployed"]);
            Assert.AreEqual("@foo47", actual.Fields["ParentID"]);
            Assert.AreEqual("@foo48", actual.Fields["Column With Spaces"]);

            Assert.AreEqual(6, actual.Parameters.Count);
            Assert.AreEqual("Chris", actual.Parameters["@foo43"]);
            Assert.AreEqual("Pietschmann", actual.Parameters["@foo44"]);
            Assert.AreEqual(0, actual.Parameters["@foo45"]);
            Assert.AreEqual(false, actual.Parameters["@foo46"]);
            Assert.AreEqual(Guid.Empty, actual.Parameters["@foo47"]);
            Assert.AreEqual(null, actual.Parameters["@foo48"]);
        }
        public void Execute_004_IdentityInsert_Int()
        {
            var expected = new IdentityTest_Int
            {
                Name = "Wes"
            };

            using (var con = GetDBConnection())
            {
                con.Open();
                var trans = con.BeginTransaction();

                try
                {
                    var query = new SQLinqInsert<IdentityTest_Int>(expected);

                    var id = con.Execute<int>(query, trans);


                    var actual = con.Query(from p in new SQLinq<IdentityTest_Int>()
                                           where p.Id != default(int)
                                           select p, trans).FirstOrDefault();

                    Assert.IsNotNull(actual);
                    Assert.AreNotEqual(default(int), actual.Id);
                    Assert.AreEqual(id, actual.Id);
                }
                finally
                {
                    trans.Rollback();
                    con.Close();
                }
            }
        }