Esempio n. 1
0
        public void EnumTest1()
        {
            var g      = new DefaultSqlServerCommandGenerator();
            var method = typeof(IUserDao).GetMethod(nameof(IUserDao.SelectByState));
            var d      = g.Generate(method, new object[] { UserStates.Normal });

            Assert.AreEqual(1, d.Parameters["State"].Value);
        }
Esempio n. 2
0
        public void FillTest()
        {
            Type       type = typeof(IUserDao);
            MethodInfo mi   = type.GetMethod("SelectById");
            DefaultSqlServerCommandGenerator g = new DefaultSqlServerCommandGenerator();
            SqlCommandDescription            d = g.Generate(mi, new object[] { 1 });

            Console.WriteLine(d);
        }
Esempio n. 3
0
        public void GenCmd_DelByStr()
        {
            var        g          = new DefaultSqlServerCommandGenerator();
            Type       daoType    = typeof(IUserDao);
            MethodInfo methodInfo = daoType.GetMethod(nameof(IUserDao.DeleteByName));
            var        desc       = g.Generate(methodInfo, new object[] { "Shiori" });

            Console.WriteLine(desc);
            Assert.AreEqual("Shiori", desc.Parameters["Name"].Value);
        }
Esempio n. 4
0
        public void GenCmd_SelectById2()
        {
            var        g          = new DefaultSqlServerCommandGenerator();
            Type       daoType    = typeof(IUserDao);
            MethodInfo methodInfo = daoType.GetMethod(nameof(IUserDao.SelectById));
            var        desc       = g.Generate(methodInfo, new object[] { 1 });

            Console.WriteLine(desc);
            Assert.AreEqual(1, desc.Parameters["Id"].Value);
        }
Esempio n. 5
0
        public void DiyQueryByIdAndName()
        {
            var g      = new DefaultSqlServerCommandGenerator();
            var method = typeof(IUserDao).GetMethod(nameof(IUserDao.DiyQueryByIdAndName));
            var d      = g.Generate(method, new object[] { 1, "fc" });

            Assert.AreEqual(2, d.Parameters.Count);
            Assert.AreEqual(1, d.Parameters["id"].Value);
            Assert.AreEqual("fc", d.Parameters["name"].Value);
        }
Esempio n. 6
0
        public void GenCmd_IdInByArray()
        {
            var        g          = new DefaultSqlServerCommandGenerator();
            Type       daoType    = typeof(IUserDao);
            MethodInfo methodInfo = daoType.GetMethod(nameof(IUserDao.GetByIdIn));
            var        desc       = g.Generate(methodInfo, new object[] { new int[] { 1, 2, 3 } });

            Console.WriteLine(desc);
            Assert.AreEqual(1, desc.Parameters["Id0"].Value);
            Assert.AreEqual(2, desc.Parameters["Id1"].Value);
            Assert.AreEqual(3, desc.Parameters["Id2"].Value);
        }
Esempio n. 7
0
        public void UpdatePasswordEqualsNewpasswordByUseridAndPasswordIsOldpassword()
        {
            var        g      = new DefaultSqlServerCommandGenerator();
            StackFrame sf     = new StackFrame();
            Type       type   = typeof(IUserDao);
            var        method = type.GetMethod(sf.GetMethod().Name);
            var        d      = g.Generate(method, new object[] { "888888", "123", "123456" });

            Console.WriteLine(d);
            Assert.AreEqual("888888", d.Parameters["Newpassword"].Value);
            Assert.AreEqual("123", d.Parameters["Userid"].Value);
            Assert.AreEqual("123456", d.Parameters["Oldpassword"].Value);
        }
Esempio n. 8
0
        public void BetweenTest()
        {
            var g      = new DefaultSqlServerCommandGenerator();
            var method = typeof(IUserDao).GetMethod(nameof(IUserDao.GetByAgeBetween));
            var d      = g.Generate(method, new object[]
            {
                new BetweenParameter(1, 2)
            });

            Console.WriteLine(d);
            Assert.AreEqual(2, d.Parameters.Count);
            Assert.AreEqual(1, d.Parameters[string.Format("{0}{1}", "Age", Constant.PARAMETER_SUFFIX_BETWEEN_BEGIN)].Value);
            Assert.AreEqual(2, d.Parameters[string.Format("{0}{1}", "Age", Constant.PARAMETER_SUFFIX_BETWEEN_END)].Value);
        }
Esempio n. 9
0
        public void PagingSelectOrderbyId()
        {
            var        g          = new DefaultSqlServerCommandGenerator();
            Type       daoType    = typeof(IUserDao);
            MethodInfo methodInfo = daoType.GetMethod(nameof(IUserDao.PagingSelectOrderbyId));
            var        desc       = g.Generate(methodInfo, new object[] { new Paging()
                                                                          {
                                                                              PageSize = 10, PageIndex = 0
                                                                          } });

            Console.WriteLine(desc);
            Assert.AreEqual(0, desc.Parameters["BEGINRN"].Value);
            Assert.AreEqual(10, desc.Parameters["ENDRN"].Value);
        }
Esempio n. 10
0
        public void GenCmd_Insert()
        {
            var        g          = new DefaultSqlServerCommandGenerator();
            Type       daoType    = typeof(IUserDao);
            MethodInfo methodInfo = daoType.GetMethod(nameof(IUserDao.Insert));
            User       user       = new User()
            {
                CreateTime = DateTime.Now,
                Id         = 1,
                Name       = "Test",
                Password   = "******"
            };
            var desc = g.Generate(methodInfo, new object[] { user });

            Console.WriteLine(desc);
        }
Esempio n. 11
0
        public void GenerateCommand()
        {
            var  g       = new DefaultSqlServerCommandGenerator();
            Type daoType = typeof(IUserDao);

            MethodInfo[] infos = daoType.GetMethods();
            foreach (var info in infos)
            {
                System.ComponentModel.DescriptionAttribute desc = info.GetCustomAttribute <System.ComponentModel.DescriptionAttribute>();
                if (desc == null)
                {
                    continue;
                }
                var d = g.Generate(info, null);
                Console.WriteLine(d);
                Assert.AreEqual(desc.Description, d.SqlCommand.Trim(), info.Name);
            }
        }
Esempio n. 12
0
        public void UpdateWithoutCreatetimeById()
        {
            var        g      = new DefaultSqlServerCommandGenerator();
            StackFrame sf     = new StackFrame();
            Type       type   = typeof(IUserDao);
            var        method = type.GetMethod(sf.GetMethod().Name);
            var        d      = g.Generate(method, new object[] { new User()
                                                                  {
                                                                      Id       = 1,
                                                                      Name     = "NewName",
                                                                      Password = "******"
                                                                  } });

            Console.WriteLine(d);
            Assert.AreEqual(3, d.Parameters.Count);
            Assert.AreEqual(1, d.Parameters["Id"].Value);
            Assert.AreEqual("NewName", d.Parameters["Name"].Value);
            Assert.AreEqual("NewPassword", d.Parameters["Password"].Value);
        }