예제 #1
0
        public void TestDatatypeComputer_DateTime_DodgyFormats(string input, Type expectedOutput)
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(input);
            Assert.AreEqual(expectedOutput, t.CurrentEstimate);
        }
예제 #2
0
        public void TestDatatypeComputer_ValidDateStrings(string wierdDateString)
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(wierdDateString);
            Assert.AreEqual(typeof(DateTime), t.CurrentEstimate);
        }
예제 #3
0
        public void TestDatatypeComputer_RandomCrud(string randomCrud)
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(randomCrud);
            Assert.AreEqual(typeof(string), t.CurrentEstimate);
        }
예제 #4
0
        public void TestDatatypeComputer_Bool(bool sendStringEquiv)
        {
            DataTypeComputer t = new DataTypeComputer();

            if (sendStringEquiv)
            {
                t.AdjustToCompensateForValue("True");
            }
            else
            {
                t.AdjustToCompensateForValue(true);
            }

            if (sendStringEquiv)
            {
                t.AdjustToCompensateForValue("False");
            }
            else
            {
                t.AdjustToCompensateForValue(false);
            }

            Assert.AreEqual(typeof(bool), t.CurrentEstimate);

            t.AdjustToCompensateForValue(null);

            Assert.AreEqual(typeof(bool), t.CurrentEstimate);

            Assert.AreEqual(null, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(null, t.DecimalSize.NumbersBeforeDecimalPlace);
        }
예제 #5
0
        private void StronglyTypeWorkingTable()
        {
            DataTable dtCloned = _workingTable.Clone();

            bool typeChangeNeeded = false;

            foreach (DataColumn col in _workingTable.Columns)
            {
                //if we have already handled it
                if (ExplicitlyTypedColumns != null && ExplicitlyTypedColumns.ExplicitTypesCSharp.ContainsKey(col.ColumnName))
                {
                    continue;
                }

                //let's make a decision about the data type to use based on the contents
                var computedType = new DataTypeComputer(col);

                //Type based on the contents of the column
                if (computedType.ShouldDowngradeColumnTypeToMatchCurrentEstimate(col))
                {
                    dtCloned.Columns[col.ColumnName].DataType = computedType.CurrentEstimate;
                    typeChangeNeeded = true;
                }
            }

            if (typeChangeNeeded)
            {
                foreach (DataRow row in _workingTable.Rows)
                {
                    dtCloned.ImportRow(row);
                }

                _workingTable = dtCloned;
            }
        }
예제 #6
0
        public void TestDatatypeComputer_PreeceedingZeroes(string input, int expectedLength)
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(input);
            Assert.AreEqual(typeof(string), t.CurrentEstimate);
            Assert.AreEqual(expectedLength, t.Length);
        }
예제 #7
0
        public void TestDatatypeComputer_IntToDateTime()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("2013");
            t.AdjustToCompensateForValue("01/01/2001");
            Assert.AreEqual(typeof(string), t.CurrentEstimate);
        }
예제 #8
0
        public void TestDatatypeComputer_Whitespace(string input, Type expectedType)
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(input);

            Assert.AreEqual(expectedType, t.CurrentEstimate);
            Assert.AreEqual(input.Length, t.Length);
        }
예제 #9
0
        public void TestDatatypeComputer_MixedIntTypes()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue((Int16)5);
            var ex = Assert.Throws <DataTypeComputerException>(() => t.AdjustToCompensateForValue((Int32)1000));

            Assert.IsTrue(ex.Message.Contains("We were adjusting to compensate for object 1000 which is of Type System.Int32 , we were previously passed a System.Int16 type, is your column of mixed type? this is unacceptable"));
        }
예제 #10
0
        public void TestDatatypeComputer_Midnight()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("00:00");

            Assert.AreEqual(typeof(TimeSpan), t.CurrentEstimate);
            Assert.AreEqual("time", t.GetSqlDBType(_translater));
        }
예제 #11
0
        public void TestDatatypeComputer_TimeObject()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(new TimeSpan(10, 1, 1));

            Assert.AreEqual(typeof(TimeSpan), t.CurrentEstimate);
            Assert.AreEqual("time", t.GetSqlDBType(_translater));
        }
예제 #12
0
        public void TestDatatypeComputer_DateTime_EnglishWithTimeAndAM()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(GetCultureSpecificDate() + " 11:10AM");
            t.AdjustToCompensateForValue(null);

            Assert.AreEqual(t.CurrentEstimate, typeof(DateTime));
            Assert.AreEqual("datetime2", t.GetSqlDBType(_translater));
        }
예제 #13
0
        public void TestDatatypeComputer_DateTime()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("01/01/2001");
            t.AdjustToCompensateForValue(null);

            Assert.AreEqual(t.CurrentEstimate, typeof(DateTime));
            Assert.AreEqual("datetime2", t.GetSqlDBType(_translater));
        }
예제 #14
0
        public void TestDatatypeComputer_Negatives()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("-1");
            t.AdjustToCompensateForValue("-99.99");

            Assert.AreEqual(t.CurrentEstimate, typeof(decimal));
            Assert.AreEqual("decimal(4,2)", t.GetSqlDBType(_translater));
        }
예제 #15
0
        public void TestDatatypeComputer_FallbackOntoVarcharFromFloat()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("15.5");
            t.AdjustToCompensateForValue("F");

            Assert.AreEqual(typeof(string), t.CurrentEstimate);
            Assert.AreEqual("varchar(4)", t.GetSqlDBType(_translater));
        }
예제 #16
0
        public void TestDatatypeComputer_NumberOfDecimalPlaces()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("111111111.11111111111115");

            Assert.AreEqual(typeof(decimal), t.CurrentEstimate);
            Assert.AreEqual(9, t.DecimalSize.NumbersBeforeDecimalPlace);
            Assert.AreEqual(14, t.DecimalSize.NumbersAfterDecimalPlace);
        }
예제 #17
0
        public void TestDatatypeComputer_MixedDateAndTime_FallbackToString()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("09:01");
            Assert.AreEqual(typeof(TimeSpan), t.CurrentEstimate);

            t.AdjustToCompensateForValue("2001-12-29 23:01");
            Assert.AreEqual(typeof(string), t.CurrentEstimate);
            Assert.AreEqual("varchar(16)", t.GetSqlDBType(_translater));
        }
예제 #18
0
        public void TestDatatypeComputer_PreeceedingZeroesAfterFloat()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("1.5");
            t.AdjustToCompensateForValue("00299.99");
            t.AdjustToCompensateForValue(null);
            t.AdjustToCompensateForValue(DBNull.Value);

            Assert.AreEqual(typeof(string), t.CurrentEstimate);
        }
예제 #19
0
        public void TestDatatypeComputer_decimal()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("1.5");
            t.AdjustToCompensateForValue("299.99");
            t.AdjustToCompensateForValue(null);
            t.AdjustToCompensateForValue(DBNull.Value);

            Assert.AreEqual(typeof(decimal), t.CurrentEstimate);
        }
예제 #20
0
        public void TestDataTypeComputer_FallbackCompatible(string input1, Type expectedTypeAfterFirstInput, string input2, Type expectedTypeAfterSecondInput)
        {
            var t = new DataTypeComputer();

            t.AdjustToCompensateForValue(input1);

            Assert.AreEqual(expectedTypeAfterFirstInput, t.CurrentEstimate);

            t.AdjustToCompensateForValue(input2);
            Assert.AreEqual(expectedTypeAfterSecondInput, t.CurrentEstimate);
        }
예제 #21
0
        public void TestDatatypeComputer_Doubles()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(299.99);

            Assert.AreEqual(typeof(double), t.CurrentEstimate);

            Assert.AreEqual(2, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(3, t.DecimalSize.NumbersBeforeDecimalPlace);
        }
예제 #22
0
        public void TestDatatypeComputer_Byte()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(new byte[5]);

            Assert.AreEqual(typeof(byte[]), t.CurrentEstimate);

            Assert.AreEqual(null, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(null, t.DecimalSize.NumbersBeforeDecimalPlace);
            Assert.IsTrue(t.DecimalSize.IsEmpty);
        }
예제 #23
0
        public void TestDatatypeComputer_HardTypeFloats()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(1.1f);
            t.AdjustToCompensateForValue(100.01f);
            t.AdjustToCompensateForValue(10000f);

            Assert.AreEqual(typeof(float), t.CurrentEstimate);
            Assert.AreEqual(2, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(5, t.DecimalSize.NumbersBeforeDecimalPlace);
        }
예제 #24
0
        public void TestDatatypeComputer_MixingTypes_ThrowsException(object o1, object o2)
        {
            //if we pass an hard type...
            //...then we don't accept strings anymore

            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(o1);

            var ex = Assert.Throws <DataTypeComputerException>(() => t.AdjustToCompensateForValue(o2));

            Assert.IsTrue(ex.Message.Contains("mixed type"));
        }
예제 #25
0
        public void TestDatatypeComputer_DateTime_EnglishWithTime()
        {
            DataTypeComputer t = new DataTypeComputer();

            Console.WriteLine(CultureInfo.CurrentCulture.EnglishName);
            Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern);

            t.AdjustToCompensateForValue(GetCultureSpecificDate() + " 11:10");
            t.AdjustToCompensateForValue(null);

            Assert.AreEqual(t.CurrentEstimate, typeof(DateTime));
            Assert.AreEqual("datetime2", t.GetSqlDBType(_translater));
        }
예제 #26
0
        public void TestDatatypeComputer_IntAnddecimal_MustUsedecimalThenString()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue("15");
            t.AdjustToCompensateForValue("29.9");
            t.AdjustToCompensateForValue("200");
            t.AdjustToCompensateForValue(null);
            t.AdjustToCompensateForValue(DBNull.Value);

            Assert.AreEqual("decimal(4,1)", t.GetSqlDBType(_translater));
            t.AdjustToCompensateForValue("D");
            Assert.AreEqual("varchar(5)", t.GetSqlDBType(_translater));
        }
예제 #27
0
        public void TestDatatypeComputer_HardTypeInts()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(1);
            t.AdjustToCompensateForValue(100);
            t.AdjustToCompensateForValue(null);
            t.AdjustToCompensateForValue(10000);
            t.AdjustToCompensateForValue(DBNull.Value);

            Assert.AreEqual(typeof(int), t.CurrentEstimate);
            Assert.AreEqual(null, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(5, t.DecimalSize.NumbersBeforeDecimalPlace);
        }
예제 #28
0
        public void Test_NonAscii_CharacterLength(string word)
        {
            var t = new DataTypeComputer();

            t.AdjustToCompensateForValue(word);

            //in most DBMS
            Assert.AreEqual(t.Length, word.Length);

            //in the world of Oracle where you need varchar2(6) to store "It’s"
            t = new DataTypeComputer(0, 3);
            t.AdjustToCompensateForValue(word);

            Assert.AreEqual(word.Length + 3, t.Length);
        }
예제 #29
0
        public void TestDatatypeComputer_FallbackOntoStringLength(string legitType, Type expectedLegitType, string str, int expectedLength)
        {
            DataTypeComputer t = new DataTypeComputer();

            //give it the legit hard typed value e.g. a date
            t.AdjustToCompensateForValue(legitType);
            Assert.AreEqual(expectedLegitType, t.CurrentEstimate);

            //then give it a string
            t.AdjustToCompensateForValue(str);
            Assert.AreEqual(typeof(string), t.CurrentEstimate);

            //the length should be the max of the length of the legit string and the string str
            Assert.AreEqual(expectedLength, t.Length);
        }
예제 #30
0
        public void TestDatatypeComputer_HardTypeDoubles()
        {
            DataTypeComputer t = new DataTypeComputer();

            t.AdjustToCompensateForValue(1.1);
            t.AdjustToCompensateForValue(100.203);
            t.AdjustToCompensateForValue(100.20000);
            t.AdjustToCompensateForValue(null);
            t.AdjustToCompensateForValue(10000d);//<- d is required because Types must be homogenous
            t.AdjustToCompensateForValue(DBNull.Value);

            Assert.AreEqual(typeof(double), t.CurrentEstimate);
            Assert.AreEqual(3, t.DecimalSize.NumbersAfterDecimalPlace);
            Assert.AreEqual(5, t.DecimalSize.NumbersBeforeDecimalPlace);
        }