Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        public void Matches_Bit_Success()
        {
            var actual = new DataTypeInfo() { Name = "bit" };

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

            var isConstraint = new IsConstraint("bit");

            //Method under test
            Assert.That(commandStub.Object, isConstraint);
        }
Esempio n. 3
0
        public void Matches_BitWithInt_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 DataTypeInfo() { Name = "bit" };

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

            var isConstraint = new IsConstraint("int");

            //Method under test
            Assert.Throws<AssertionException>(delegate { Assert.That(commandStub.Object, isConstraint); });
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
 /// <summary>
 /// Construct a ExistsConstraint
 /// </summary>
 public IsConstraint(string expected)
 {
     var factory = new DataTypeInfoFactory();
     this.expected = factory.Instantiate(expected);
 }
Esempio n. 6
0
        public void WriteTo_FailingAssertion_TextContainsColumnInfo()
        {
            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 DataTypeInfo() { Name = "bit" };

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

            var isConstraint = new IsConstraint("int");

            //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("ccc-name").And
                                            .StringContaining("table-name").And
                                            .StringContaining("perspective-name"));
        }
Esempio n. 7
0
        public void Matches_GivenCommand_ExecuteCalledOnce()
        {
            var actual = new DataTypeInfo();

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

            var isConstraint = new IsConstraint("varchar");

            //Method under test
            isConstraint.Matches(commandMock.Object);

            //Test conclusion
            commandMock.Verify(cmd => cmd.Execute(), Times.Once());
        }