public void Constructor_PrimaryTableType_Test()
        {
            const string primaryKeyName = "primaryKeyName123";
            var foreignKeyAttribute = new ForeignKeyAttribute(typeof(string), primaryKeyName);

            Assert.AreEqual(typeof(string), foreignKeyAttribute.PrimaryTableType);
            Assert.AreEqual(primaryKeyName, foreignKeyAttribute.PrimaryKeyName);
            Assert.AreEqual(typeof(string).Name, foreignKeyAttribute.PrimaryTableName);
            Assert.IsFalse(foreignKeyAttribute.IsDefaultSchema);
        }
        public void Constructor_PrimaryTableName_Test()
        {
            const string primaryTableName = "primaryTableName123", primaryKeyName = "primaryKeyName123";
            var foreignKeyAttribute = new ForeignKeyAttribute(primaryTableName, primaryKeyName);

            Assert.IsNull(foreignKeyAttribute.Schema);
            Assert.IsNull(foreignKeyAttribute.PrimaryTableType);
            Assert.IsTrue(foreignKeyAttribute.IsDefaultSchema);
            Assert.AreEqual(primaryTableName, foreignKeyAttribute.PrimaryTableName);
            Assert.AreEqual(primaryKeyName, foreignKeyAttribute.PrimaryKeyName);
        }
        public void DifferentSchema_NoTableAttribute_DoesNotEqual_Test()
        {
            const string schema1 = "schema1ABC";
            const string schema2 = "schema2ABC";
            const string primaryTableName = "primaryTableNameABC";
            const string primaryKeyName = "primaryKeyNameABC";

            var fkAttribute1 = new ForeignKeyAttribute(schema1, primaryTableName, primaryKeyName);
            var table1 = new Table(fkAttribute1, null);

            var fkAttribute2 = new ForeignKeyAttribute(schema2, primaryTableName, primaryKeyName);
            var table2 = new Table(fkAttribute2, null);

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

            var concreteOriginalAttribute = new ForeignKeyAttribute("tableName123", "primaryKeyName123");
            ICanHaveDefaultSchema originalForeignKeyAttribute = concreteOriginalAttribute;

            // Act.

            const string defaultSchema = "defaultSchema123";
            Attribute newAttribute = originalForeignKeyAttribute.GetAttributeUsingDefaultSchema(defaultSchema);
            var newForeignKeyAttribute = newAttribute as ForeignKeyAttribute;

            // Assert

            Assert.IsNotNull(newForeignKeyAttribute);
            Assert.IsFalse(newForeignKeyAttribute.IsDefaultSchema);
            Assert.AreEqual(defaultSchema, newForeignKeyAttribute.Schema);
            Assert.AreEqual(concreteOriginalAttribute.PrimaryKeyName, newForeignKeyAttribute.PrimaryKeyName);
            Assert.AreEqual(concreteOriginalAttribute.PrimaryTableName, newForeignKeyAttribute.PrimaryTableName);
        }
        public void GetTableType_TableTypeCache_GetCachedTableType_Test()
        {
            // Arrange

            Type foreignType = typeof(ForeignClass);

            var foreignKeyAtribute = new ForeignKeyAttribute("PrimaryClass", null);

            Type expected = typeof(PrimaryClass);

            this.tableTypeCacheMock.Setup(m => m.GetCachedTableType(foreignKeyAtribute, foreignType, this.GetType().Assembly, this.attributeDecorator.GetSingleAttribute<TableAttribute>, true))
                .Returns(expected);

            // Act

            Type result = this.attributeDecorator.GetTableType(foreignKeyAtribute, foreignType);

            // Assert

            Assert.AreEqual(expected, result);
        }
        public void GetTableType_PrimaryTableType_Test()
        {
            // Arrange

            var foreignKeyAtribute = new ForeignKeyAttribute(typeof(TestModels.Simple.PrimaryClass), null);

            // Act

            Type result = this.attributeDecorator.GetTableType(foreignKeyAtribute, null);

            // Assert

            Assert.AreEqual(typeof(TestModels.Simple.PrimaryClass), result);
        }
        public void GetTableType_AssemblyCacheIsPopulated_Test()
        {
            // Arrange

            Type foreignType = typeof(ForeignClass);

            var foreignKeyAtribute = new ForeignKeyAttribute("PrimaryClass", null);

            Type returnedType = typeof(PrimaryClass);

            this.tableTypeCacheMock.Setup(m => m.IsAssemblyCachePopulated(foreignType.Assembly)).Returns(true);
            this.tableTypeCacheMock.Setup(m => m.GetCachedTableType(foreignKeyAtribute, foreignType, this.GetType().Assembly, this.attributeDecorator.GetSingleAttribute<TableAttribute>, true))
                .Returns(returnedType);

            // Act

            this.attributeDecorator.GetTableType(foreignKeyAtribute, foreignType);

            // Assert

            this.tableTypeCacheMock.Verify(m => m.PopulateAssemblyCache(foreignType.Assembly, this.attributeDecorator.GetSingleAttribute<TableAttribute>, null), Times.Never);
        }
        public void IsDefaultSchema_TrueFalse_Test()
        {
            // Arrange. Act.

            ICanHaveDefaultSchema foreignKeyAttributeWithPrimaryType = new ForeignKeyAttribute(typeof(string), "primaryKeyName123");
            ICanHaveDefaultSchema foreignKeyAttributeWithTableName = new ForeignKeyAttribute("primaryTableName123", "primaryKeyName123");
            ICanHaveDefaultSchema foreignKeyAttributeWithSchema = new ForeignKeyAttribute("schema123", "primaryTableName123", "primaryKeyName");

            // Assert

            Assert.IsFalse(foreignKeyAttributeWithPrimaryType.IsDefaultSchema);
            Assert.IsTrue(foreignKeyAttributeWithTableName.IsDefaultSchema);
            Assert.IsFalse(foreignKeyAttributeWithSchema.IsDefaultSchema);
        }
        public void ForeignKeyAttribute_Constructor_Test()
        {
            // Arrange

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

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

            // Act

            var table = new Table(fkAttribute, null);

            // Assert

            Assert.IsFalse(table.HasTableAttribute);
            Assert.IsFalse(table.HasCatalogueName);
            Assert.IsNull(table.CatalogueName);
            Assert.AreEqual(schema, table.Schema);
            Assert.AreEqual(primaryTableName, table.TableName);

            Assert.AreEqual(schema.GetHashCode() ^ primaryTableName.GetHashCode(), table.GetHashCode());
        }
        public void InputForTryGet_NoTableAttribute_Equals_Test()
        {
            const string schema = "schemaABC";
            const string primaryTableName = "primaryTableNameABC";
            const string primaryKeyName = "primaryKeyNameABC";

            var fkAttribute1 = new ForeignKeyAttribute(schema, primaryTableName, primaryKeyName);
            var table1 = new Table(fkAttribute1, null);

            var fkAttribute2 = new ForeignKeyAttribute(schema, primaryTableName, primaryKeyName);
            var table2 = new Table(fkAttribute2, null);

            Assert.IsTrue(table1.BasicFieldsEqual(table2));
        }