示例#1
0
        private void AddColumnsToTable(Table table)
        {
            Column cl;

            // query columns
            var FieldsQuery = (from column in _providertables.AsEnumerable()
                               where column.Field<string>("TableName") == table.Name
                               select new
                               {
                                   ColumnName = column.Field<string>("ColumnName")
                                   ,
                                   DataType = column.Field<string>("DataType")
                                   ,
                                   Length = column.Field<Int16>("Length")
                                   ,
                                   IsNullable = column.Field<int>("IsNullable")
                               }).Distinct();

            // add columns
            foreach (var fn in FieldsQuery)
            {
                cl = Column.CreateWithTable(fn.ColumnName, table);
                cl.OfType(fn.DataType, fn.Length);
                if (Convert.ToBoolean(fn.IsNullable)) cl.Nullable();
            }
        }
        protected void AddTable(Table table)
        {
            // guard clause: Duplicated table not allowed, It could overwrite an specification by mistake
            if (_tableList.Exists(x => table.Name.EqualsIgnoreCase(x.Name)))
                throw new ApplicationException(string.Format("Table {0} already in specification", table.Name));

            _tableList.Add(table);
        }
示例#3
0
            public void When_twice_the_same_column_name_with_different_case_then_WithColumn_should_throw_ApplicationException()
            {
                // Arrange
                Table table = new Table("table1");

                // Act & Assert
                Assert.Throws<ApplicationException>(() => table.WithColumn("c1")
                                                              .WithColumn("C1"));
            }
示例#4
0
            public void Then_Done_will_end_the_fluent_sequence_for_columns()
            {
                // Arrange
                Table table = new Table("Table1")
                    .WithColumn("column1")
                    .Done();

                // Assert
                Assert.That( table, Is.InstanceOf(typeof(Table)));
            }
示例#5
0
            public void Then_WithColumn_should_create_a_new_column()
            {
                // Arrange
                Table table = new Table("table1");

                // Act
                Column column = table.WithColumn("Column1");

                // Assert
                Assert.That(column.Name, Is.EqualTo("Column1"));
            }
示例#6
0
            public void Then_WithColumn_should_be_used_to_add_columns_to_a_table()
            {
                // Arrange
                Table table = new Table("table1");

                // Act
                table.WithColumn("c1")
                     .WithColumn("c2")
                     .WithColumn("c3");

                // Assert
                Assert.That(table.Columns.Count, Is.EqualTo(3));
            }
        public void ToString_should_return_string_representation_for_conflict_columns()
        {
            // Arrange
            Table t1 = new Table("t1").WithColumn("column1").OfType("int", 4).Done();
            Table t2 = new Table("t1").WithColumn("column1").OfType("varchar", 4).Done();

            CompareResult compareResult = t1.Compare(t2);

            string expected = "Conflict Column(s)\n" +
                              "----------------\n" +
                              "Expected: column1 : int(4)\n" +
                              "But was:  column1 : varchar(4)\n\n";

            // Act
            string result = compareResult.ToString();

            // Assert
            Assert.That(result, Is.EqualTo(expected));
        }
示例#8
0
        public CompareResult Compare(Table otherTable)
        {
            // guard clause: Different table names are not comparables
            if (!Name.EqualsIgnoreCase(otherTable.Name))
                throw new InvalidOperationException("Tables are not comparables. In order to compare two tables they must have the same name.");

            CompareResult result = new CompareResult();
            foreach (Column eachColumn in _columnList)
            {
                Column otherColumn = otherTable.FindColumnByName(eachColumn.Name);
                if (otherColumn == null)
                    result.AddMissing(eachColumn);
                else
                    if (!eachColumn.Equals(otherColumn))
                    {
                        var conflict = new TableConflict(new Pair<Column>(eachColumn, otherColumn));
                        result.AddConflict(conflict);
                    }
            }
            return result;
        }
        public void ToString_should_return_string_representation_for_missing_columns()
        {
            // Arrange
            Table t1 = new Table("t1").WithColumn("Id").OfType("int", 4)
                                      .WithColumn("Desc").OfType("varchar", 100).Nullable()
                                      .Done();
            Table t2 = new Table("t1");

            CompareResult compareResult = t1.Compare(t2);

            string expected = "Missing Column(s)\n" +
                              "----------------\n" +
                              "Id : int(4)\n" +
                              "Desc : varchar(100) NULLABLE\n";

            // Act
            string result = compareResult.ToString();

            // Assert
            Assert.That(result, Is.EqualTo(expected));
        }
示例#10
0
            public void Given_a_table_with_extra_columns_then_the_extra_columns_should_be_ignored()
            {
                // Arrange
                Table t1 = new Table("t1");
                t1.WithColumn("c1");

                Table t2 = new Table("t1");
                t2.WithColumn("c1");
                t2.WithColumn("c2");

                // Act
                CompareResult result = t1.Compare(t2);

                // Assert
                Assert.That(result.HaveValues, Is.False);
            }
示例#11
0
            public void Given_a_table_with_the_columns_then_ToString_should_return_string_representation()
            {
                // Arrange
                Table table = new Table("Person")
                    .WithColumn("Id").OfType("int", 4)
                    .WithColumn("Name").OfType("varchar", 255).Nullable()
                    .WithColumn("Salary").OfType("double", 2)
                    .Done();
                string expected = "[Person]\n" +
                                  "   Id : int(4)\n" +
                                  "   Name : varchar(255) NULLABLE\n" +
                                  "   Salary : double(2)\n";

                // Act
                string result = table.ToString();

                // Assert
                Assert.That(result, Is.EqualTo(expected));
            }
示例#12
0
        private DbSpecification AddTablesAndTheirFieldsToSpecification()
        {
            List<Table> tables = new List<Table>();

            // query tables
            var DistintTableQuery = (from table in _providertables.AsEnumerable()
                                     select new { TableName = table.Field<string>("TableName") }).Distinct();

            // add tables and their fields
            foreach (var tn in DistintTableQuery)
            {
                // add table
                Table tb = new Table(tn.TableName);

                // add columns
                AddColumnsToTable(tb);
                tables.Add(tb);
            }

            return new DbSpecification(tables);
        }
示例#13
0
            public void Then_table_names_should_be_case_insensitive()
            {
                // Arrange
                Table t1 = new Table("T1");
                Table t2 = new Table("t1");

                // Act
                CompareResult result = t1.Compare(t2);

                // Assert
                Assert.That(result, Is.Not.Null);
            }
示例#14
0
            public void Should_have_same_table_names_to_be_a_valid_operation()
            {
                // Arrange
                Table t1 = new Table("t1");
                Table t2 = new Table("t1");

                // Act
                CompareResult result = t1.Compare(t2);

                // Assert
                Assert.That(result, Is.Not.Null);
            }
示例#15
0
            public void Given_two_tables_with_different_names_then_should_throw_InvalidOperationException()
            {
                // Arrange
                Table t1 = new Table("t1");
                Table t2 = new Table("t2");

                // Act & Assert
                Assert.Throws<InvalidOperationException>(() => t1.Compare(t2));
            }
 protected Table AddTable(string tableName)
 {
     Table table = new Table(tableName);
     AddTable(table);
     return table;
 }
示例#17
0
 private string GetColumns(string indent, Table table)
 {
     string result = "";
     foreach (var eachColumn in table.Columns)
     {
         result += string.Format("\n{0}.WithColumn(\"{1}\").OfType(\"{2}\", {3})", indent, eachColumn.Name, eachColumn.ColumnType, eachColumn.ColumnLength);
         if (eachColumn.IsNullable) result += ".Nullable()";
     }
     return result;
 }
示例#18
0
            public void Given_a_table_with_a_missing_column_then_the_missing_column_should_be_detected()
            {
                // Arrange
                Table t1 = new Table("t1");
                t1.WithColumn("c1");

                Table t2 = new Table("t1");

                // Act
                CompareResult result = t1.Compare(t2);

                // Assert
                Assert.That(result.MissingList.Count, Is.EqualTo(1));
                Assert.That(result.MissingList[0].Name, Is.EqualTo("c1"));
            }
示例#19
0
            public void Given_two_tables_with_different_columnType_then_conflict_should_be_detected()
            {
                // Arrange
                Table t1 = new Table("t1");
                Column expectedFirst = t1.WithColumn("c1").OfType("int", 4);
                t1.WithColumn("irrelevant").OfType("varchar", 3);

                Table t2 = new Table("t1");
                Column expectedSecond = t2.WithColumn("c1").OfType("varchar", 4);
                t2.WithColumn("irrelevant").OfType("varchar", 3);

                // Act
                CompareResult result = t1.Compare(t2);

                // Assert
                Assert.That(result.ConflictList.Count, Is.EqualTo(1));
                Assert.That(result.ConflictList[0].First, Is.SameAs(expectedFirst));
                Assert.That(result.ConflictList[0].Second, Is.SameAs(expectedSecond));
            }