Exemplo n.º 1
0
        // FIXME : この処理は本当は DataTableValidator でやるべき
        private DataRow SelectResultRow(DataTable result, DataRow keyRow, Table tableInfo, Row rowInfo, List <string> keyColumns)
        {
            int rowCount = result.Rows.Count;

            if (rowInfo.Deleted)
            {
                if (rowCount == 0)
                {
                    return(null);
                }
                else
                {
                    Assertie.Fail("M_Fixture_Temp_DatabaseValidator_UnexpectedData", result.TableName, tableInfo, rowInfo, ToString(keyColumns, keyRow));
                }
            }

            if (rowCount == 0)
            {
                string message = (keyColumns.Count == result.Columns.Count) ?
                                 "M_Fixture_Temp_DatabaseValidator_NotFound_With_Comment" :
                                 "M_Fixture_Temp_DatabaseValidator_NotFound";
                Assertie.Fail(message, result.TableName, tableInfo, rowInfo, ToString(keyColumns, keyRow));
            }

            if (rowCount > 1)
            {
                Assertie.Fail("M_Fixture_Temp_DatabaseValidator_OneMoreData", result.TableName, tableInfo, rowInfo, ToString(keyColumns, keyRow));
            }

            return(result.Rows[0]);
        }
Exemplo n.º 2
0
        public void Validate <TException>(Action action, string typeName) where TException : Exception
        {
            bool isNormalEnd = false;

            try
            {
                action();
                isNormalEnd = true;
            }
            catch (TException e)
            {
                Loggi.Debug(e);
                object   obj    = e;
                Delegate editor = GetExceptionEditor(e.GetType());
                if (editor != null)
                {
                    obj = editor.DynamicInvoke(e);
                }
                Validate(obj, typeName);
            }

            if (isNormalEnd)
            {
                Assertie.Fail("M_Fixture_Temp_ObjectValidator_Exception", typeof(TException).Name);
            }
        }
Exemplo n.º 3
0
        private void AreEqual(Table table, Row row, string columnName, string expected, byte[] actualBytes)
        {
            string actualAsText = ToStringFromByteArray(actualBytes, expected);

            Assertie.AreEqual(expected, actualAsText,
                              "M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, expected, actualAsText, GetType(actualBytes));
        }
Exemplo n.º 4
0
        protected virtual bool AssertEmpty(Table table, Row row, string columnName,
                                           string expected, object actual)
        {
            if (Strings.IsEmpty(expected))
            {
                if (actual == null)
                {
                    return(true);
                }
                if (actual is string && Strings.IsEmpty((string)actual))
                {
                    return(true);
                }
                Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, "", actual, GetType(actual));
            }

            if (NULL.Equals(expected))
            {
                if (actual != null)
                {
                    Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, NULL, actual, GetType(actual));
                }
                return(true);
            }

            if (EMPTY.Equals(expected))
            {
                if (actual == null || !(actual is string) || ((string)actual).Length > 0)
                {
                    Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, EMPTY, ToStringInternal(actual), GetType(actual));
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        protected virtual bool AssertEqualsAsDate(Table table, Row row, string columnName,
                                                  string expected, object actual)
        {
            if (expected.IndexOf(TODAY) > -1 && actual is string)
            {
                actual = ToDate((string)actual);
            }

            if (expected.IndexOf(TODAY) > -1 && (actual is DateTime || actual is DateTimeOffset))
            {
                String today = Formi.Format(DateTime.Today, "yyyy-MM-dd");
                expected = expected.Replace(TODAY, today);
                if (AssertEqualsStrictly(table, row, columnName, expected, DateTimeToString((IFormattable)actual, today)))
                {
                    return(true);
                }
                Assertie.AreEqual(expected, actual,
                                  "M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, expected, actual, GetType(actual));
            }
            if (actual is DateTime || actual is DateTimeOffset)
            {
                string actualAsText = DateTimeToString((IFormattable)actual, expected);
                if (AssertEqualsStrictly(table, row, columnName, expected, actualAsText))
                {
                    return(true);
                }
                Assertie.AreEqual(expected, actualAsText,
                                  "M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, expected, actualAsText, GetType(actual));
            }
            return(false);
        }
Exemplo n.º 6
0
 protected virtual void AssertLineNumber(Table table, int expected, int actual)
 {
     if (expected != actual)
     {
         Assertie.AreEqual(expected, actual, "M_Fixture_Temp_ObjectValidator_AssertLineNumber", table, table.Name, expected, actual);
     }
 }
Exemplo n.º 7
0
 protected virtual void AssertNull(string typeName)
 {
     if (Section.HasTable(typeName) && !IsNull(Section.GetTable(typeName)))
     {
         Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertNull", typeName, Section.GetTable(typeName));
     }
 }
Exemplo n.º 8
0
        private string[] GetTableNamesFrom(DataSet dataSet)
        {
            List <string> tableNames = new List <string>();

            if (ValidateTableNames(dataSet))
            {
                foreach (DataTable table in dataSet.Tables)
                {
                    tableNames.Add(table.TableName);
                }
            }
            else if (dataSet.Tables.Count > Section.TableNames.Count)
            {
                Assertie.Fail(
                    "M_Fixture_Temp_ObjectValidator_AssertTableNumberImp",
                    Section.TableNames.Count, dataSet.Tables.Count, Section);
            }
            else
            {
                string messageFormat = Resi.Get("M_Fixture_Temp_ObjectValidator_UseTableOrder");
                Loggi.Warn(String.Format(messageFormat, Section));
                for (int i = 0; i < dataSet.Tables.Count; i++)
                {
                    Loggi.Warn("DataSet.Table[" + i + "] = " + Section.TableNames[i]);
                    tableNames.Add(Section.TableNames[i]);
                }
            }
            return(tableNames.ToArray());
        }
Exemplo n.º 9
0
        public override void Validate(object obj, params string[] typeName)
        {
            DataSet dataSet = (DataSet)obj;

            if (typeName == null || typeName.Length == 0)
            {
                typeName = GetTableNamesFrom(dataSet);
                if (dataSet.Tables.Count != Section.TableNames.Count)
                {
                    Assertie.Fail(
                        "M_Fixture_Temp_ObjectValidator_AssertTableNumberEquals",
                        Section.TableNames.Count, dataSet.Tables.Count, Section);
                }
            }

            if (dataSet.Tables.Count < typeName.Length)
            {
                Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertTableNumberExp",
                              ToStringInternal(typeName), ToStringInternal(dataSet.Tables), Section);
            }

            List <DataTable> dataTables = CreateDataTableList(dataSet.Tables);

            for (int i = 0; i < typeName.Length; i++)
            {
                DataTable dataTable = GetDataTable(typeName[i], dataTables);
                Validate(dataTable, typeName[i]);
            }
        }
Exemplo n.º 10
0
        protected virtual void AssertEquals(Table table, Row row, string columnName,
                                            string expected, object actual)
        {
            if (AssertEmpty(table, row, columnName, expected, actual))
            {
                return;
            }
            if (AssertNotEmpty(table, row, columnName, expected, actual))
            {
                return;
            }
            String actualAsText = ToString(expected, actual);

            if (AssertEqualsStrictly(table, row, columnName, expected, actualAsText))
            {
                return;
            }
            if (AssertNestedObject(table, row, columnName, expected, actual))
            {
                return;
            }
            if (AssertPartialEquality(table, row, columnName, expected, actualAsText))
            {
                return;
            }
            if (AssertEqualsAsDate(table, row, columnName, expected, actual))
            {
                return;
            }
            if (AssertEqualsAsBool(table, row, columnName, expected, actual))
            {
                return;
            }
            if (AssertEqualsAsByteArray(table, row, columnName, expected, actual))
            {
                return;
            }
            if (AssertEqualsByRegex(table, row, columnName, expected, actualAsText))
            {
                return;
            }
            Assertie.AreEqual(expected, actualAsText,
                              "M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, expected, actualAsText, GetType(actual));
        }
Exemplo n.º 11
0
        public override void Validate <TException>(Action action, string typeName)
        {
            bool isNormalEnd = false;

            try
            {
                action();
                isNormalEnd = true;
            }
            catch (TException e)
            {
                Loggi.Debug(e);
                Validate(e, typeName);
            }

            if (isNormalEnd)
            {
                Assertie.Fail("M_Fixture_Temp_ObjectValidator_Exception", typeof(TException).Name);
            }
        }
Exemplo n.º 12
0
 protected virtual bool AssertNotEmpty(Table table, Row row, string columnName,
                                       string expected, object actual)
 {
     if ("*".Equals(expected))
     {
         if (actual != null)
         {
             if (!(actual is string))
             {
                 return(true);
             }
             if (!Strings.IsEmpty((string)actual))
             {
                 return(true);
             }
         }
         Assertie.Fail("M_Fixture_Temp_ObjectValidator_AssertEquals", table, row, columnName, "*", ToStringInternal(actual), GetType(actual));
     }
     return(false);
 }