public void CatalogueNull_SchemaNull_DifferentName_NotEqual_Test()
        {
            var tableAttribute1 = new TableAttribute(catalogueName: null, schema: null, name: "AA");
            var tableAttribute2 = new TableAttribute(catalogueName: null, schema: null, name: "BB");

            Assert.IsFalse(tableAttribute1.Equals(tableAttribute2));
        }
        public void CatalogueNull_SchemaNull_Equals_Test()
        {
            var tableAttribute1 = new TableAttribute(catalogueName: null, schema: null, name: "AA");
            var tableAttribute2 = new TableAttribute(catalogueName: null, schema: null, name: "AA");

            Assert.IsTrue(tableAttribute1.Equals(tableAttribute2));
        }
        public void DifferentCatalogue_SameSchema_Equals_Test()
        {
            const string catalogue1 = "catalogue1ABC";
            const string catalogue2 = "catalogue2ABC";
            const string schema = "schema1ABC";
            const string tableName = "primaryTableNameABC";

            var tableAttribute1 = new TableAttribute(catalogue1, schema, tableName);
            var table1 = new Table(tableAttribute1);

            var tableAttribute2 = new TableAttribute(catalogue2, schema, tableName);
            var table2 = new Table(tableAttribute2);

            Assert.IsTrue(table1.BasicFieldsEqual(table2));
        }
        public void WriteString_Test()
        {
            const string testString = "TestString";

            var tableAttribute = new TableAttribute("CatalogueName", "SchemaName", "TableName");

            PropertyInfo propertyInfo = typeof (PrimaryTable).GetProperty("Key");

            this.sqlWriterCommandTextMock.Setup(
                m => m.GetStringSelect(tableAttribute.CatalogueName, tableAttribute.Schema, tableAttribute.Name, "Key"))
                .Returns(testString);

            this.attributeDecoratorMock.Setup(m => m.GetCustomAttributes<TableAttribute>(typeof(PrimaryTable)))
                .Returns(new TableAttribute[] {tableAttribute});

            string result = this.textGenerator.WriteString(propertyInfo);

            Assert.AreEqual(testString, result);
        }
        public void Catalogue_Schema_TableName_Constructor_Test()
        {
            const string catalogue = "catalogueABC";
            const string schema = "schemaABC";
            const string tableName = "tableNameABC";

            var tableAttribute = new TableAttribute(catalogue, schema, tableName);

            Assert.AreEqual(catalogue, tableAttribute.CatalogueName);
            Assert.AreEqual(schema, tableAttribute.Schema);
            Assert.AreEqual(tableName, tableAttribute.Name);
            Assert.IsFalse(tableAttribute.IsDefaultSchema);

            Assert.AreEqual(catalogue.GetHashCode() ^ schema.GetHashCode() ^ tableName.GetHashCode(),
                tableAttribute.GetHashCode());
        }
        public void TableName_Constructor_Test()
        {
            const string tableName = "tableNameABC";

            var tableAttribute = new TableAttribute(tableName);

            Assert.IsNull(tableAttribute.CatalogueName);
            Assert.IsNull(tableAttribute.Schema);
            Assert.AreEqual(tableName, tableAttribute.Name);
            Assert.IsTrue(tableAttribute.IsDefaultSchema);

            Assert.AreEqual(tableName.GetHashCode(), tableAttribute.GetHashCode());
        }
        public void SameCatalogue_SameSchema_Equals_Test()
        {
            var tableAttribute1 = new TableAttribute(catalogueName: "CC", schema: "BB", name: "AA");
            var tableAttribute2 = new TableAttribute(catalogueName: "CC", schema: "BB", name: "AA");

            Assert.IsTrue(tableAttribute1.Equals(tableAttribute2));
        }
        public void NullSchema_GetHashCode_Test()
        {
            const string tableName = "tableNameABC";

            var tableAttribute = new TableAttribute(null, tableName);

            Assert.AreEqual(null, tableAttribute.Schema);

            Assert.AreEqual(tableName.GetHashCode(), tableAttribute.GetHashCode());
        }
        public void IsDefaultSchema_TrueFalse_Test()
        {
            // Arrange. Act.

            ICanHaveDefaultSchema tableAttributeWithName = new TableAttribute("tableName123");
            ICanHaveDefaultSchema tableAttributeWithSchema = new TableAttribute("schema123", "tableName123");
            ICanHaveDefaultSchema tableAttributeWithCatalogue = new TableAttribute("catalogueName123", "schema123", "tableName123");

            // Assert

            Assert.IsTrue(tableAttributeWithName.IsDefaultSchema);
            Assert.IsFalse(tableAttributeWithSchema.IsDefaultSchema);
            Assert.IsFalse(tableAttributeWithCatalogue.IsDefaultSchema);
        }
        public void GetAttributeUsingDefaultSchema_Test()
        {
            // Arrange.

            var concreteOriginalAttribute = new TableAttribute("tableName123");
            ICanHaveDefaultSchema originalTableAttribute = concreteOriginalAttribute;

            // Act.

            const string defaultSchema = "defaultSchema123";
            Attribute newAttribute = originalTableAttribute.GetAttributeUsingDefaultSchema(defaultSchema);
            var newTableAttribute = newAttribute as TableAttribute;

            // Assert

            Assert.IsNotNull(newTableAttribute);
            Assert.IsFalse(newTableAttribute.IsDefaultSchema);
            Assert.AreEqual(defaultSchema, newTableAttribute.Schema);
            Assert.AreEqual(concreteOriginalAttribute.CatalogueName, newTableAttribute.CatalogueName);
            Assert.AreEqual(concreteOriginalAttribute.Name, newTableAttribute.Name);
        }
        public void DifferentCatalogue_SameSchema_SameName_NotEqual_Test()
        {
            var tableAttribute1 = new TableAttribute(catalogueName: "KK", schema: "BB", name: "AA");
            var tableAttribute2 = new TableAttribute(catalogueName: "LL", schema: "BB", name: "AA");

            Assert.IsFalse(tableAttribute1.Equals(tableAttribute2));
        }
        public void TableAttribute_Constructor_Test()
        {
            // Arrange

            const string catalogueName = "catalogueABC";
            const string schema = "schemaABC";
            const string tableName = "tableNameABC";

            var tableAttribute = new TableAttribute(catalogueName, schema, tableName);

            // Act

            var table = new Table(tableAttribute);

            // Assert

            Assert.IsTrue(table.HasTableAttribute);
            Assert.AreEqual(catalogueName, table.CatalogueName);
            Assert.AreEqual(schema, table.Schema);
            Assert.AreEqual(tableName, table.TableName);

            Assert.AreEqual(schema.GetHashCode() ^ tableName.GetHashCode(), table.GetHashCode());
        }
        public void SameCatalogue_SameSchema_DifferentTable_DoesNotEqual_Test()
        {
            const string catalogue = "catalogue2ABC";
            const string schema = "schema1ABC";
            const string tableName1 = "primaryTableName1ABC";
            const string tableName2 = "primaryTableName2ABC";

            var tableAttribute1 = new TableAttribute(catalogue, schema, tableName1);
            var table1 = new Table(tableAttribute1);

            var tableAttribute2 = new TableAttribute(catalogue, schema, tableName2);
            var table2 = new Table(tableAttribute2);

            Assert.IsFalse(table1.BasicFieldsEqual(table2));
        }
        public void ForeignKeyAttribute_TableAttribute_Constructor_Test()
        {
            // Arrange

            const string schema = "schemaABC";
            const string primaryTableName = "primaryTableNameABC";
            const string primaryKeyName = "primaryKeyNameABC";

            var fkAttribute = new ForeignKeyAttribute(schema, primaryTableName, primaryKeyName);

            const string catalogueName = "catalogueNameABC";

            var tableAttribute = new TableAttribute(catalogueName, "fkTableSchemaABC", "fkTableName");

            // Act

            var table = new Table(fkAttribute, tableAttribute);

            // Assert

            Assert.IsTrue(table.HasTableAttribute);
            Assert.IsTrue(table.HasCatalogueName);
            Assert.AreEqual(catalogueName, table.CatalogueName);

            Assert.AreEqual(schema.GetHashCode() ^ primaryTableName.GetHashCode(), table.GetHashCode());
        }