public DataTypeInfo Instantiate(RelationalRow row)
        {
            DataTypeInfo dataTypeInfo = null;

            if (row.CharacterMaximumLength > 0)
            {
                dataTypeInfo = new TextInfo();
                ((TextInfo)dataTypeInfo).Length = row.CharacterMaximumLength;
                ((TextInfo)dataTypeInfo).CharSet = row.CharacterSetName;
                ((TextInfo)dataTypeInfo).Collation = row.CollationName;
                ((TextInfo)dataTypeInfo).Domain = row.DomainName;
            }
            else if (row.NumericScale > 0)
            {
                dataTypeInfo = new NumericInfo();
                ((NumericInfo)dataTypeInfo).Scale = row.NumericScale;
                ((NumericInfo)dataTypeInfo).Precision = row.NumericPrecision;
            }
            else if (row.DateTimePrecision > 0)
            {
                dataTypeInfo = new DateTimeInfo();
                ((DateTimeInfo)dataTypeInfo).Precision = row.DateTimePrecision;
            }
            else
            {
                dataTypeInfo = new DataTypeInfo();
            }

            dataTypeInfo.Name = row.DataType.ToLower();
            dataTypeInfo.Nullable = row.IsNullable.ToUpper() == "YES".ToUpper();
            return dataTypeInfo;
        }
        protected DataTypeInfo Decrypt(string type)
        {
            DataTypeInfo value = null;
            switch (type)
            {
                case "bit":
                    value = new DataTypeInfo();
                    break;
                case "ntext":
                case "nvarchar":
                case "varchar":
                case "nchar":
                case "text":
                case "char":
                    value = new TextInfo();
                    break;
                case "smalldatetime":
                case "datetime":
                    value = new DateTimeInfo();
                    break;
                case "bigint":
                case "money":
                case "smallmoney":
                case "decimal":
                case "float":
                case "int":
                case "real":
                case "smallint":
                case "tinyint":
                    value = new NumericInfo();
                    break;
                default:
                    value = new DataTypeInfo();
                    break;
            }

            value.Name = type;
            return value;
        }
        public void Matches_Varchar_Success()
        {
            var actual = new TextInfo() { Name = "varchar", Length = 10 };

            var commandStub = new Mock<IDataTypeDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actual);

            var isConstraint = new IsConstraint("varchar");

            //Method under test
            Assert.That(commandStub.Object, isConstraint);
        }
        public void WriteTo_FailingAssertionForComplexType_TextContainsTwoFullTypeNames()
        {
            var description = new CommandDescription(Target.Columns,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                                , new CaptionFilter(Target.Tables, "table-name")
                                , new CaptionFilter(Target.Columns, "ccc-name")
                        });

            var actual = new TextInfo() { Name = "varchar", Length = 10 };

            var commandStub = new Mock<IDataTypeDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actual);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var isConstraint = new IsConstraint("nvarchar(20)");

            //Method under test
            string assertionText = null;
            try
            {
                Assert.That(commandStub.Object, isConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Console.WriteLine(assertionText);
            Assert.That(assertionText, Is.StringContaining("varchar(10)").And
                                            .StringContaining("nvarchar(20)")
                                            );
        }
        public void Matches_Varchar10WithVarchar20_Failure()
        {
            var description = new CommandDescription(Target.Columns,
                        new CaptionFilter[]
                            {
                                new CaptionFilter(Target.Perspectives, "perspective-name")
                                , new CaptionFilter(Target.Tables, "table-name")
                                , new CaptionFilter(Target.Columns, "ccc-name")
                        });
            var actual = new TextInfo() { Name = "varchar", Length=10 };

            var commandStub = new Mock<IDataTypeDiscoveryCommand>();
            commandStub.Setup(cmd => cmd.Execute()).Returns(actual);
            commandStub.Setup(cmd => cmd.Description).Returns(description);

            var isConstraint = new IsConstraint("varchar(20)");

            //Method under test
            Assert.Throws<AssertionException>(delegate { Assert.That(commandStub.Object, isConstraint); });
        }