예제 #1
0
        public void MapTables_HasTables_ReturnsNonEmptyList()
        {
            // Arrange
            var table = new Table
            {
                TableId         = 1000,
                TableName       = "TableName",
                TableCreateDate = DateTime.Today - TimeSpan.FromDays(-30),
                TableModifyDate = DateTime.Today - TimeSpan.FromDays(-15),
                SchemaId        = 1
            };

            IDatabaseMappingDAO dbMappingDAOStub = Substitute.For <IDatabaseMappingDAO>();

            dbMappingDAOStub.GetDatabaseTables().Returns(new List <Table> {
                table
            });

            // Act
            IDatabaseMapper dbMapper = new DatabaseMapper(dbMappingDAOStub);

            dbMapper.MapTables();

            var dbMapping = dbMapper.DatabaseMapping;

            // Assert
            Assert.IsNotEmpty(dbMapping.Tables);
        }
예제 #2
0
        public void MapSchemaTableRelationships_NoMappedTables_ThrowsInvalidOperationException()
        {
            // Arrange
            Schema[] schemas = new Schema[]
            {
                new Schema {
                    SchemaId = 1, SchemaName = "Schema 1"
                },
                new Schema {
                    SchemaId = 2, SchemaName = "Schema 2"
                },
                new Schema {
                    SchemaId = 3, SchemaName = "Schema 3"
                },
            };

            IDatabaseMappingDAO dbMappingDAO = Substitute.For <IDatabaseMappingDAO>();

            dbMappingDAO.GetDatabaseSchemas().Returns(schemas);
            dbMappingDAO.GetDatabaseTables().Returns(new List <Table>());

            // Act
            IDatabaseMapper dbMapper = new DatabaseMapper(dbMappingDAO);

            dbMapper.MapSchemas();
            dbMapper.MapTables();

            // Assert
            Assert.Throws <InvalidOperationException>(() => { dbMapper.MapSchemaTableRelationships(); });
        }
예제 #3
0
        public void MapTables_HasNoTables_ReturnsEmptyList()
        {
            // Arrange
            IDatabaseMappingDAO dbMappingDAOStub = Substitute.For <IDatabaseMappingDAO>();

            dbMappingDAOStub.GetDatabaseTables().Returns(new List <Table>());

            // Act
            IDatabaseMapper dbMapper = new DatabaseMapper(dbMappingDAOStub);

            dbMapper.MapTables();

            var dbMapping = dbMapper.DatabaseMapping;

            // Assert
            Assert.IsEmpty(dbMapping.Tables);
        }
예제 #4
0
        public void MapSchemaTableRelationships_NoMappedSchemas_ThrowsInvalidOperationException()
        {
            // Arrange
            Table[] tables = new Table[]
            {
                new Table {
                    TableId = 1, TableName = "Table 1", TableCreateDate = DateTime.Now, TableModifyDate = DateTime.Now, SchemaId = 1
                },
                new Table {
                    TableId = 2, TableName = "Table 2", TableCreateDate = DateTime.Now, TableModifyDate = DateTime.Now, SchemaId = 1
                },
                new Table {
                    TableId = 3, TableName = "Table 3", TableCreateDate = DateTime.Now, TableModifyDate = DateTime.Now, SchemaId = 1
                },
                new Table {
                    TableId = 4, TableName = "Table 4", TableCreateDate = DateTime.Now, TableModifyDate = DateTime.Now, SchemaId = 1
                },
                new Table {
                    TableId = 5, TableName = "Table 5", TableCreateDate = DateTime.Now, TableModifyDate = DateTime.Now, SchemaId = 1
                },
            };

            IDatabaseMappingDAO dbMappingDAO = Substitute.For <IDatabaseMappingDAO>();

            dbMappingDAO.GetDatabaseSchemas().Returns(new List <Schema>());
            dbMappingDAO.GetDatabaseTables().Returns(tables);

            // Act
            IDatabaseMapper dbMapper = new DatabaseMapper(dbMappingDAO);

            dbMapper.MapSchemas();
            dbMapper.MapTables();

            // Assert
            Assert.Throws <InvalidOperationException>(() => { dbMapper.MapSchemaTableRelationships(); });
        }
예제 #5
0
        public void MapSchemaTableRelationships_HasMatchingRelationships_MapRelationshipsCorrecly()
        {
            // Arrange
            Schema[] schemas = new Schema[]
            {
                new Schema {
                    SchemaId = 1, SchemaName = "Schema 1"
                },
                new Schema {
                    SchemaId = 2, SchemaName = "Schema 2"
                },
                new Schema {
                    SchemaId = 3, SchemaName = "Schema 3"
                },
            };

            var tableCreateDate = DateTime.Now - TimeSpan.FromDays(-30);
            var tableModifyDate = DateTime.Now - TimeSpan.FromDays(-15);

            Table[] tables = new Table[]
            {
                new Table {
                    TableId = 1, TableName = "Table 1", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 1
                },
                new Table {
                    TableId = 2, TableName = "Table 2", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 1
                },
                new Table {
                    TableId = 3, TableName = "Table 3", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 2
                },
                new Table {
                    TableId = 4, TableName = "Table 4", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 2
                },
                new Table {
                    TableId = 5, TableName = "Table 5", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 3
                },
                new Table {
                    TableId = 6, TableName = "Table 6", TableCreateDate = tableCreateDate, TableModifyDate = tableModifyDate, SchemaId = 3
                }
            };

            IDatabaseMappingDAO dbMappingDAO = Substitute.For <IDatabaseMappingDAO>();

            dbMappingDAO.GetDatabaseSchemas().Returns(schemas);
            dbMappingDAO.GetDatabaseTables().Returns(tables);

            // Act
            IDatabaseMapper dbMapper = new DatabaseMapper(dbMappingDAO);

            dbMapper.MapSchemas();
            dbMapper.MapTables();

            dbMapper.MapSchemaTableRelationships();

            // Asserts

            #region .: Asserts for schema 1 :.

            var schema1 = schemas.Single(s => s.SchemaId == 1);
            var table1  = tables.Single(t => t.TableId == 1);
            var table2  = tables.Single(t => t.TableId == 2);

            // Asserts that tables 1 and 2 points to schema1
            Assert.AreSame(schema1, table1.Schema);
            Assert.AreSame(schema1, table2.Schema);

            // Asserts that schema1 contains tables 1 and 2

            Assert.Contains(table1, schema1.Tables as ICollection);
            Assert.Contains(table2, schema1.Tables as ICollection);

            #endregion .: Asserts for schema 1 :.

            #region .: Asserts for schema 2 :.

            var schema2 = schemas.Single(s => s.SchemaId == 2);
            var table3  = tables.Single(t => t.TableId == 3);
            var table4  = tables.Single(t => t.TableId == 4);

            // Asserts that tables 3 and 4 points to schema2
            Assert.AreSame(schema2, table3.Schema);
            Assert.AreSame(schema2, table4.Schema);

            // Asserts that schema2 contains tables 3 and 4
            Assert.Contains(table3, schema2.Tables as ICollection);
            Assert.Contains(table4, schema2.Tables as ICollection);

            #endregion .: Asserts for schema 2 :.

            #region .: Asserts for schema 3 :.

            var schema3 = schemas.Single(s => s.SchemaId == 3);
            var table5  = tables.Single(t => t.TableId == 5);
            var table6  = tables.Single(t => t.TableId == 6);

            // Asserts that tables 5 and 6 points to schema3
            Assert.AreSame(schema3, table5.Schema);
            Assert.AreSame(schema3, table6.Schema);

            // Asserts that schema3 contains tables 5 and 6
            Assert.Contains(table5, schema3.Tables as ICollection);
            Assert.Contains(table6, schema3.Tables as ICollection);

            #endregion .: Asserts for schema 3 :.
        }