public TestAttribute(String name = null, String desciption = null, UInt32 order = 0, TestFormat format = TestFormat.Run)
 {
     Name = name;
     Description = description;
     Order = order;
     Format = format;
 }
Exemple #2
0
 public Board()
 {
     mDate     = new DateTime(1, 1, 1);
     mType     = TestType.IT_A;
     mFormat   = TestFormat.IT_2;
     vExaminee = new List <Examinee>();
 }
Exemple #3
0
        public void DeleteCostColumn()
        {
            TestPrice price;

            using (var scope = new TransactionScope(OnDispose.Rollback)) {
                price = CreateTestSupplierWithPrice();
                scope.VoteCommit();
            }
            var prices = FillPrices();
            var rows   = prices.Select(String.Format("PFirmCode = {0}", price.Supplier.Id));

            Assert.That(rows.Count(), Is.EqualTo(2));
            rows = prices.Select(String.Format("PFirmCode = {0} and PCostType = 1 and PIsParent = 0", price.Supplier.Id));
            Assert.That(rows.Count(), Is.EqualTo(1));
            rows[0].Delete();

            var changes = prices.GetChanges();

            With.Transaction((c, t) => {
                var mcmdDPrice = new MySqlCommand();
                var daPrice    = new MySqlDataAdapter();

                mcmdDPrice.CommandText = "usersettings.DeleteCost";
                mcmdDPrice.CommandType = CommandType.StoredProcedure;
                mcmdDPrice.Parameters.Clear();
                mcmdDPrice.Parameters.Add("?inCostCode", MySqlDbType.Int64, 0, "PCostCode");
                mcmdDPrice.Parameters["?inCostCode"].Direction = ParameterDirection.Input;

                mcmdDPrice.Connection = c;
                daPrice.DeleteCommand = mcmdDPrice;
                daPrice.TableMappings.Clear();
                daPrice.TableMappings.Add("Table", prices.TableName);

                daPrice.Update(changes);
                prices.AcceptChanges();
            });


            using (var scope = new TransactionScope(OnDispose.Rollback)) {
                var resprice = TestPrice.Find(price.Id);
                Assert.That(resprice.Costs.Count, Is.EqualTo(1));

                var cost = TestPriceCost.TryFind(costForDelete.Id);
                Assert.That(cost, Is.EqualTo(null));

                var item = TestPriceItem.TryFind(costForDelete.PriceItem.Id);
                Assert.That(item, Is.EqualTo(null));

                var source = TestPriceSource.TryFind(costForDelete.PriceItem.Source.Id);
                Assert.That(source, Is.EqualTo(null));

                var format = TestFormat.TryFind(costForDelete.PriceItem.Format.Id);
                Assert.That(format, Is.EqualTo(null));
            }
        }
Exemple #4
0
 public TestEncoder(TestFormat testFormat)
 => this.testFormat = testFormat;
        static void test(TestFormat test_format)
        {
            ArrayList dates = new ArrayList();
            dates.Add(new DTTest(@"Member since:  	10-Feb-2008", new DateTime(2008, 2, 10, 0, 0, 0)));
            dates.Add(new DTTest(@"Last Update: 18:16 11 Feb '08 ", new DateTime(2008, 2, 11, 18, 16, 0)));
            dates.Add(new DTTest(@"date	Tue, Feb 10, 2008 at 11:06 AM", new DateTime(2008, 2, 10, 11, 06, 0)));
            dates.Add(new DTTest(@"see at 12/31/2007 14:16:32", new DateTime(2007, 12, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"sack finish 14:16:32 November 15 2008, 1-144 app", new DateTime(2008, 11, 15, 14, 16, 32)));
            dates.Add(new DTTest(@"Genesis Message - Wed 04 Feb 08 - 19:40", new DateTime(2008, 2, 4, 19, 40, 0)));
            dates.Add(new DTTest(@"The day 07/31/07 14:16:32 is ", new DateTime(2007, 7, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"Shipping is on us until December 24, 2008 within the U.S. ", new DateTime(2008, 12, 24, 0, 0, 0)));
            dates.Add(new DTTest(@" 2008 within the U.S. at 14:16:32", new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 16, 32)));
            dates.Add(new DTTest(@"5th November, 1994, 8:15:30 pm", new DateTime(1994, 11, 5, 20, 15, 30)));
            dates.Add(new DTTest(@"7 boxes January 31 , 14:16:32.", new DateTime(DateTime.Now.Year, 1, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"the blue sky of Sept  30th  2008 14:16:32", new DateTime(2008, 9, 30, 14, 16, 32)));
            dates.Add(new DTTest(@" e.g. 1997-07-16T19:20:30+01:00", new DateTime(1997, 7, 16, 19, 20, 30)));
            dates.Add(new DTTest(@"Apr 1st, 2008 14:16:32 tufa 6767", new DateTime(2008, 4, 1, 14, 16, 32)));
            dates.Add(new DTTest(@"wait for 07/31/07 14:16:32", new DateTime(2007, 7, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"later 12.31.08 and before 1.01.09", new DateTime(2008, 12, 31, 0, 0, 0)));
            dates.Add(new DTTest(@"Expires: Sept  30th  2008 14:16:32", new DateTime(2008, 9, 30, 14, 16, 32)));
            dates.Add(new DTTest(@"Offer expires Apr 1st, 2007, 14:16:32", new DateTime(2007, 4, 1, 14, 16, 32)));
            dates.Add(new DTTest(@"Expires  14:16:32 January 31.", new DateTime(DateTime.Now.Year, 1, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"Expires  14:16:32 January 31-st.", new DateTime(DateTime.Now.Year, 1, 31, 14, 16, 32)));
            dates.Add(new DTTest(@"Expires 23rd January 2010.", new DateTime(2010, 1, 23, 0, 0, 0)));
            dates.Add(new DTTest(@"Expires January 22nd, 2010.", new DateTime(2010, 1, 22, 0, 0, 0)));
            dates.Add(new DTTest(@"Expires DEC 22, 2010.", new DateTime(2010, 12, 22, 0, 0, 0)));
            dates.Add(new DTTest(@"Version: 1.0.0.692 6/1/2010 2:28:04 AM ", new DateTime(2010, 6, 1, 2, 28, 4)));
            dates.Add(new DTTest(@"Version: 1.0.0.692 04/21/11 12:30am ", new DateTime(2011, 4, 21, 00, 30, 00)));
            dates.Add(new DTTest(@"Version: 1.0.0.692 04/21/11 12:30pm ", new DateTime(2011, 4, 21, 12, 30, 00)));

            int errors = 0;

            Console.WriteLine("\n\n##################################   " + test_format.ToString());
            DateTimeRoutines.ParsedDateTime t;
            foreach (DTTest test in dates)
            {
                string date = test.test;
                Console.WriteLine("");
                Console.WriteLine("* " + date);

                switch (test_format)
                {
                    case TestFormat.DATE:
                        if (date.TryParseDate(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                            if (t.DateTime.Year != test.answer.Year || t.DateTime.Month != test.answer.Month || t.DateTime.Day != test.answer.Day)
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.ToString() + " <> " + test.answer.ToString());
                                errors++;
                            }
                            else
                                Console.WriteLine(t.DateTime.ToShortDateString());
                        else
                        {
                            if (DateTime.Now.Year != test.answer.Year || DateTime.Now.Month != test.answer.Month || DateTime.Now.Day != test.answer.Day)
                            {
                                Console.WriteLine(">>>>>> ERROR: not found");
                                errors++;
                            }
                            else
                                Console.WriteLine("-----");
                        }
                        break;
                    case TestFormat.DATE_TIME:
                        if (date.TryParseDateOrTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                            if (t.DateTime != test.answer)
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.ToString() + " <> " + test.answer.ToString());
                                errors++;
                            }
                            else
                                Console.WriteLine(t.DateTime.ToString());
                        else
                        {
                            Console.WriteLine(">>>>>> ERROR: not found");
                            errors++;
                        }
                        break;
                    case TestFormat.TIME:
                        if (date.TryParseTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t, null))
                            if (t.DateTime.Hour != test.answer.Hour || t.DateTime.Minute != test.answer.Minute || t.DateTime.Second != test.answer.Second)
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.ToString() + " <> " + test.answer.ToString());
                                errors++;
                            }
                            else
                                Console.WriteLine(t.DateTime.ToLongTimeString());
                        else
                        {
                            if (0 != test.answer.Hour || 0 != test.answer.Minute || 0 != test.answer.Second)
                            {
                                Console.WriteLine(">>>>>> ERROR: not found");
                                errors++;
                            }
                            else
                                Console.WriteLine("-----");
                        }
                        break;
                }
            }

            Console.WriteLine("\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@ ERRORS: " + errors.ToString() + "\n\n");
            total_errors += errors;
        }
        static void test(List<DTTest> dates, TestFormat test_format)
        {
            int errors = 0;

            Console.WriteLine("\n\n##################################   " + test_format.ToString());
            DateTimeRoutines.ParsedDateTime t;
            foreach (DTTest test in dates)
            {
                string date = test.test;
                Console.WriteLine("");
                Console.WriteLine("* " + date);

                switch (test_format)
                {
                    case TestFormat.DATE:
                        if (date.TryParseDate(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                            if (t.DateTime.Date == test.answer.Date)
                                Console.WriteLine(t.DateTime.ToString());
                            else
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.Date.ToString() + " <> " + test.answer.Date.ToString());
                                errors++;
                            }
                        else
                        {
                            if (DateTime.Now.Year != test.answer.Year || DateTime.Now.Month != test.answer.Month || DateTime.Now.Day != test.answer.Day)
                            {
                                Console.WriteLine(">>>>>> ERROR: not found");
                                errors++;
                            }
                            else
                                Console.WriteLine("-----");
                        }
                        break;
                    case TestFormat.DATE_TIME:
                        if (date.TryParseDateOrTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                            if (t.IsUtcOffsetFound && test.answer.Kind == DateTimeKind.Utc && t.UtcDateTime == test.answer || !t.IsUtcOffsetFound && t.DateTime == test.answer)
                                Console.WriteLine(t.DateTime.ToString());
                            else
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.ToString() + " <> " + test.answer.ToString() + " and " + t.UtcDateTime.ToString() + " <> " + test.answer.ToString());
                                errors++;
                            }
                        else
                        {
                            Console.WriteLine(">>>>>> ERROR: not found");
                            errors++;
                        }
                        break;
                    case TestFormat.TIME:
                        if (date.TryParseTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t, null))
                            if (t.IsUtcOffsetFound && test.answer.Kind == DateTimeKind.Utc && t.UtcDateTime.TimeOfDay == test.answer.TimeOfDay || !t.IsUtcOffsetFound && t.DateTime.TimeOfDay == test.answer.TimeOfDay)
                                Console.WriteLine(t.DateTime.ToLongTimeString());
                            else
                            {
                                Console.WriteLine(">>>>>> ERROR: " + t.DateTime.TimeOfDay.ToString() + " <> " + test.answer.TimeOfDay.ToString() + " and " + t.UtcDateTime.TimeOfDay.ToString() + " <> " + test.answer.TimeOfDay.ToString());
                                errors++;
                            }
                        else
                        {
                            if (0 != test.answer.Hour || 0 != test.answer.Minute || 0 != test.answer.Second)
                            {
                                Console.WriteLine(">>>>>> ERROR: not found");
                                errors++;
                            }
                            else
                                Console.WriteLine("-----");
                        }
                        break;
                }
            }

            Console.WriteLine("\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@ ERRORS: " + errors.ToString() + "\n\n");
            total_errors += errors;
        }
Exemple #7
0
        public string Load(string filepath)
        {
            vExaminee.Clear();

            string fn = Path.GetFileNameWithoutExtension(filepath);

            //todo check fn for length

            if (DT.To_(fn.Substring(0, 10), DT._, out mDate))
            {
                return("File name must represent test date in format yyyy-MM-dd.");
            }
            if ((int)TestFormat.IT_1 < mDate.Year)
            {
                mFormat = TestFormat.IT_2;
            }
            else
            {
                mFormat = TestFormat.IT_1;
            }

            string msg = "ok";

            // Open the spreadsheet document for read-only access.
            using (SpreadsheetDocument document =
                       SpreadsheetDocument.Open(filepath, false))
            {
                // Retrieve a reference to the workbook part.
                WorkbookPart wbPart = document.WorkbookPart;

                // Find the sheet with the supplied name, and then use that
                // Sheet object to retrieve a reference to the first worksheet.
                Sheet theSheet = wbPart.Workbook.Descendants <Sheet>().FirstOrDefault();

                // Throw an exception if there is no sheet.
                if (theSheet == null)
                {
                    return("No sheet");
                }

                if (!TestType.TryParse(theSheet.Name.ToString().Substring(0, 4), out mType))
                {
                    return("Sheet name must represent test type.");
                }

                // Retrieve a reference to the worksheet part.
                WorksheetPart wsPart =
                    (WorksheetPart)(wbPart.GetPartById(theSheet.Id));

                // Use its Worksheet property to get a reference to the cell
                // whose address matches the address you supplied.
                IEnumerable <Row> vRow = wsPart.Worksheet.Descendants <Row>();

                if (vRow.Count() < 1)
                {
                    return("No row.");
                }

                //birthdate or given name
                bool   bName = true;
                string v     = LoadExamineeAttr(vRow.First().ChildElements.ElementAt(2) as Cell, wbPart);
                foreach (char c in v.ToCharArray())
                {
                    if ('0' <= c && c <= '9')
                    {
                        bName = false;
                        break;
                    }
                }

                //determine the number of cells of each row
                int nCellOfRow = 5;
                if (bName)
                {
                    ++nCellOfRow;
                }
                if (mType < TestType.IT_A)
                {
                    nCellOfRow += 2;
                }
                else if (mFormat == TestFormat.IT_2)
                {
                    ++nCellOfRow;
                }

                int li = -1;
                foreach (Row r in vRow)
                {
                    ++li;
                    IEnumerable <Cell> cells = r.ChildElements.OfType <Cell>();
                    List <Cell>        vCell = cells.ToList();
                    if (vCell.Count < nCellOfRow)
                    {
                        msg = "Line " + li + ": The number of columns is " + vCell.Count + " < " + nCellOfRow;
                        break;
                    }

                    Examinee nee = new Examinee();
                    int      i   = -1;
                    //index
                    string value = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                    if (!nee.TryParseIdx(value))
                    {
                        msg = "Line " + li + ": Attr " + i + " is error";
                        break;
                    }

                    //name
                    nee.mName = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);

                    //given name
                    if (bName)
                    {
                        nee.mName += LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                    }

                    //birthdate
                    value = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                    int val;
                    if (int.TryParse(value, out val)) //birthdate is stored as number
                    {
                        if (val < 2018)               //birthyear only
                        {
                            nee.mBirthdate = new DateTime(val, 1, 1, 8, 8, 8);
                        }
                        else
                        {
                            nee.mBirthdate = DateTime.FromOADate(val);
                        }
                    }
                    else if (!nee.TryParseBirdate(value))//birthdate is stored as string
                    {
                        msg = "Line " + li + ": Attr " + i + " is error";
                        break;
                    }

                    //birthplace
                    nee.mBirthplace = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);

                    //grade 1
                    float grade;
                    value = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                    if (!float.TryParse(value, out grade))
                    {
                        if (value.ToLower().Trim() == "v")
                        {
                            grade = -1.0f;
                        }
                        else
                        {
                            msg = "Line " + li + ": Attr " + i + " is error";
                            break;
                        }
                    }
                    nee.mGrade1 = grade;

                    if (mType < TestType.IT_A || mFormat == TestFormat.IT_2)
                    {
                        //grade 2
                        value = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                        if (!float.TryParse(value, out grade))
                        {
                            if (value.ToLower().Trim() == "v")
                            {
                                grade = -1.0f;
                            }
                            else
                            {
                                msg = "Line " + li + ": Attr " + i + " is error";
                                break;
                            }
                        }
                        nee.mGrade2 = grade;
                    }

                    if (mType < TestType.IT_A)
                    {
                        //grade 3
                        value = LoadExamineeAttr(vCell.ElementAt(++i), wbPart);
                        if (!float.TryParse(value, out grade))
                        {
                            if (value.ToLower().Trim() == "v")
                            {
                                grade = -1.0f;
                            }
                            else
                            {
                                msg = "Line " + li + ": Attr " + i + " is error";
                                break;
                            }
                        }
                        nee.mGrade3 = grade;
                    }

                    vExaminee.Add(nee);
                }
            }
            return(msg);
        }
 public TestAttribute(String name = null, String desciption = null, TestFormat format = TestFormat.Run)
 {
     Name = name;
     Description = description;
     Format = format;
 }
 public TestAttribute(String name = null, TestFormat format = TestFormat.Run)
 {
     Name = name;
     Format = format;
 }
 public TestAttribute(UInt32 order = 0, TestFormat format = TestFormat.Run)
 {
     Order = order;
     Format = format;
 }
 public TestAttribute(TestFormat format = TestFormat.Run)
 {
     Format = format;
 }
Exemple #12
0
        static void test(List <DTTest> dates, TestFormat test_format)
        {
            int errors = 0;

            Console.WriteLine("\n\n##################################   " + test_format.ToString());
            DateTimeRoutines.ParsedDateTime t;
            foreach (DTTest test in dates)
            {
                string date = test.test;
                Console.WriteLine("");
                Console.WriteLine("* " + date);

                switch (test_format)
                {
                case TestFormat.DATE:
                    if (date.TryParseDate(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                    {
                        if (t.DateTime.Date == test.answer.Date)
                        {
                            Console.WriteLine(t.DateTime.ToString());
                        }
                        else
                        {
                            Console.WriteLine(">>>>>> ERROR: " + t.DateTime.Date.ToString() + " <> " + test.answer.Date.ToString());
                            errors++;
                        }
                    }
                    else
                    {
                        if (DateTime.Now.Year != test.answer.Year || DateTime.Now.Month != test.answer.Month || DateTime.Now.Day != test.answer.Day)
                        {
                            Console.WriteLine(">>>>>> ERROR: not found");
                            errors++;
                        }
                        else
                        {
                            Console.WriteLine("-----");
                        }
                    }
                    break;

                case TestFormat.DATE_TIME:
                    if (date.TryParseDateOrTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t))
                    {
                        if (t.IsUtcOffsetFound && test.answer.Kind == DateTimeKind.Utc && t.UtcDateTime == test.answer || !t.IsUtcOffsetFound && t.DateTime == test.answer)
                        {
                            Console.WriteLine(t.DateTime.ToString());
                        }
                        else
                        {
                            Console.WriteLine(">>>>>> ERROR: " + t.DateTime.ToString() + " <> " + test.answer.ToString() + " and " + t.UtcDateTime.ToString() + " <> " + test.answer.ToString());
                            errors++;
                        }
                    }
                    else
                    {
                        Console.WriteLine(">>>>>> ERROR: not found");
                        errors++;
                    }
                    break;

                case TestFormat.TIME:
                    if (date.TryParseTime(DateTimeRoutines.DateTimeFormat.USA_DATE, out t, null))
                    {
                        if (t.IsUtcOffsetFound && test.answer.Kind == DateTimeKind.Utc && t.UtcDateTime.TimeOfDay == test.answer.TimeOfDay || !t.IsUtcOffsetFound && t.DateTime.TimeOfDay == test.answer.TimeOfDay)
                        {
                            Console.WriteLine(t.DateTime.ToLongTimeString());
                        }
                        else
                        {
                            Console.WriteLine(">>>>>> ERROR: " + t.DateTime.TimeOfDay.ToString() + " <> " + test.answer.TimeOfDay.ToString() + " and " + t.UtcDateTime.TimeOfDay.ToString() + " <> " + test.answer.TimeOfDay.ToString());
                            errors++;
                        }
                    }
                    else
                    {
                        if (0 != test.answer.Hour || 0 != test.answer.Minute || 0 != test.answer.Second)
                        {
                            Console.WriteLine(">>>>>> ERROR: not found");
                            errors++;
                        }
                        else
                        {
                            Console.WriteLine("-----");
                        }
                    }
                    break;
                }
            }

            Console.WriteLine("\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@ ERRORS: " + errors.ToString() + "\n\n");
            total_errors += errors;
        }