public void TestGenerateComplex() { SourceView sv = TestsSourceModel.TestsSourceModel.CreateComplexSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(); Assert.AreEqual(2, model.GetActiveEntities().Count()); Assert.AreEqual(4, model.GetActiveRelations().Count()); model.GetActiveRelations().First().Constraint = RelationConstraint.Unique; var msc = new ModelToSourceConnector(new SourceView(), model); var p = new MSSQLProvider(null, null); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Console.WriteLine(script); Assert.AreEqual(6, new Regex("CREATE TABLE ").Matches(script).Count); Assert.AreEqual(2, new Regex("PRIMARY KEY CLUSTERED").Matches(script).Count); Assert.AreEqual(8, new Regex("FOREIGN KEY").Matches(script).Count); Assert.AreEqual(1, new Regex("UNIQUE CLUSTERED").Matches(script).Count); }
public void TestGenerateScriptHierachy() { var p = new MSSQLProvider(GetTestDB(), null); var sv = p.GetSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(false, relation1to1.Hierarchy, true, true, false); Assert.AreEqual(28, model.GetActiveEntities().Count()); Assert.AreEqual(32, model.GetSourceFragments().Count()); var msc = new ModelToSourceConnector(new SourceView(), model); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Console.WriteLine(script); Assert.AreEqual(sv.GetSourceFragments().Count(), new Regex("CREATE TABLE ").Matches(script).Count); IEnumerable <SourceConstraint> pks = sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName)); Assert.AreEqual(pks.Count(), new Regex("PRIMARY KEY CLUSTERED").Matches(script).Count); Assert.AreEqual(2, new Regex("UNIQUE NONCLUSTERED").Matches(script).Count); Assert.AreEqual(1, new Regex("UNIQUE CLUSTERED").Matches(script).Count); Assert.AreEqual(sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.ForeignKeyConstraintTypeName)).Count(), new Regex("FOREIGN KEY").Matches(script).Count); msc = new ModelToSourceConnector(sv, model); script = msc.GenerateSourceScript(p, false); Assert.IsTrue(string.IsNullOrEmpty(script), script); RelationDefinitionBase r = model.GetActiveRelations().First(item => item.Constraint == RelationConstraint.PrimaryKey); r.Constraint = RelationConstraint.Unique; r.SourceFragment.Constraints.Single(item => item.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName).ConstraintType = SourceConstraint.UniqueConstraintTypeName; msc = new ModelToSourceConnector(sv, model); script = msc.GenerateSourceScript(p, false); Assert.IsTrue(string.IsNullOrEmpty(script), script); }