Пример #1
0
        public void CanGetCustomAttributes()
        {
            SqlDataService dbService = new SqlDataService("fake", null);

            var row     = new Log();
            var columns = (PropertyInfo[])PrivateMethod.InvokePrivateMethodWithReturnType(dbService, "GetColumns", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance, new Type[] { typeof(Log) }, new object[] { row });

            PrivateType dbTester = new PrivateType(typeof(SqlDataService));

            int customCount = 0;

            foreach (var col in columns)
            {
                var attributes = (object[])PrivateMethod.InvokePrivateMethodWithReturnType(dbService, "GetAttributes", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance, new Type[] { typeof(Log) }, new object[] { row, col });

                if ((bool)dbTester.InvokeStatic("IsPrimaryKey", new object[] { attributes }))
                {
                    customCount++;
                }
                var value = row.GetType().GetProperty(col.Name).GetValue(row);
                if ((bool)dbTester.InvokeStatic("IsNullDefaultKey", new object[] { attributes, value }))
                {
                    customCount++;
                }
            }
            Assert.AreEqual(customCount, 2);

            Assert.IsTrue(true);
        }
Пример #2
0
        public void CanCreateSqlStatementIgnoringOnlyCustomKeys()
        {
            var    row         = new Log();
            string returnedSql = "";

            using (SqlCommand cmd = new SqlCommand())
            {
                var    tableName  = row.GetType().Name + "s";
                Type[] types      = new Type[] { typeof(Log) };
                var    parameters = new object[] { row, tableName, cmd };
                returnedSql = PrivateMethod.InvokePrivateMethodWithReturnType(new SqlDataService("fake", null), "GetInsertableRows", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance, types, parameters).ToString();
            }
            string expectedSql = "INSERT INTO Logs (ApplicationId,Message,StackTrace,ExceptionAsJson,ExceptionMessage) OUTPUT INSERTED.LogId VALUES (@ApplicationId,@Message,@StackTrace,@ExceptionAsJson,@ExceptionMessage)";

            Assert.AreEqual(returnedSql, expectedSql);
        }