Пример #1
0
        public void It_Creates_A_Single_Relationship_With_The_Right_Keys()
        {
            var proc       = new MappingProcessor(new OneToOneEntityProcessor());
            var mappingSet = proc.CreateOneToOneMapping(entities);

            var table1 = mappingSet.Database.Tables[0];
            var table2 = mappingSet.Database.Tables[1];

            var foreignKey = table2.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign);
            var primaryKey = table1.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Primary);

            Assert.That(table1.Relationships, Has.Count(1), "The relationship was not created.");
            Assert.That(table2.Relationships, Has.Count(1), "The relationship was not created.");
            var relationship = table1.Relationships[0];

            Assert.That(relationship.PrimaryKey, Is.SameAs(primaryKey));
            Assert.That(relationship.ForeignKey, Is.SameAs(foreignKey));
        }
        public void TestExactCopy()
        {
            TextFileInformation tfi = new TextFileInformation();

            tfi.NewGenFile       = new TextFile("aklsdjflkjasdf");
            tfi.IntelliMerge     = IntelliMergeType.PlainText;
            tfi.RelativeFilePath = "text.txt";

            ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi);
            VisualDiffOutput   output      = diffUtility.ProcessMergeOutput();

            Assert.IsNotNull(output);
            Assert.That(output.DiffType, Is.EqualTo(TypeOfDiff.ExactCopy));
            Assert.That(output.RightLines, Has.Count(1));
            Assert.That(output.LeftLines, Has.Count(1));
            Assert.That(output.LeftLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents()));
            Assert.That(output.RightLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents()));
        }
        public void It_Is_Built_Correctly()
        {
            var             build  = new DiscriminatorBuilder();
            ExpressionValue val    = MockRepository.GenerateMock <ExpressionValue>();
            Operator        op     = Operator.Equal;
            IColumn         column = MockRepository.GenerateMock <IColumn>();;
            Discriminator   dis    = build.SingleConditionDiscriminator(column, op, val);

            Assert.That(dis.RootGrouping, Is.Not.Null);
            Assert.That(dis.RootGrouping.Groupings, Is.Empty);
            Assert.That(dis.RootGrouping.Conditions, Has.Count(1));

            Condition condition = dis.RootGrouping.Conditions[0];

            Assert.That(condition.Column, Is.SameAs(column));
            Assert.That(condition.Operator, Is.SameAs(op));
            Assert.That(condition.ExpressionValue, Is.SameAs(val));
        }
Пример #4
0
        public void UserAndTemplate_Two_Changes_In_Middle()
        {
            TextFileInformation tfi = new TextFileInformation();

            tfi.PrevGenFile      = new TextFile("line0\nline1\nline2\nline3");
            tfi.UserFile         = new TextFile("line0\nline11\nline12\nline2\nline3");
            tfi.NewGenFile       = new TextFile("line0\nline1\nline21\nline3");
            tfi.IntelliMerge     = IntelliMergeType.PlainText;
            tfi.RelativeFilePath = "text.txt";

            ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi);
            VisualDiffOutput   output      = diffUtility.ProcessMergeOutput();

            Assert.That(output.DiffType, Is.EqualTo(Slyce.IntelliMerge.TypeOfDiff.UserAndTemplateChange));
            Assert.IsNotNull(output);
            Assert.That(output.RightLines, Is.Not.Empty);
            Assert.That(output.LeftLines, Is.Not.Empty);
            Assert.That(output.LeftLines, Has.Count(5));
            Assert.That(output.RightLines, Has.Count(5));

            Assert.That(output.LeftLines[0].Text, Is.EqualTo("line0"));
            Assert.That(output.LeftLines[1].Text, Is.EqualTo("line1"));
            Assert.That(output.LeftLines[2].Text, Is.EqualTo(""));
            Assert.That(output.LeftLines[3].Text, Is.EqualTo("line2"));
            Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3"));

            Assert.That(output.RightLines[0].Text, Is.EqualTo("line0"));
            Assert.That(output.RightLines[1].Text, Is.EqualTo("line11"));
            Assert.That(output.RightLines[2].Text, Is.EqualTo("line12"));
            Assert.That(output.RightLines[3].Text, Is.EqualTo("line21"));
            Assert.That(output.RightLines[4].Text, Is.EqualTo("line3"));

            Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.None));
            Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.User));
            Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[2].IsVirtual, Is.EqualTo(true));
            Assert.That(output.LeftLines[3].Change, Is.EqualTo(ChangeType.Template));
            Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None));

            Assert.That(output.RightLines[0].Change, Is.EqualTo(ChangeType.None));
            Assert.That(output.RightLines[1].Change, Is.EqualTo(ChangeType.User));
            Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.User));
            Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.Template));
            Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None));
        }
            public void The_Removed_Table_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.RemoveTable(db2.Tables[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.ColumnOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);

                Assert.That(result.TableOperations, Has.Count(1));
                var op = (TableRemovalOperation)result.TableOperations.ElementAt(0);

                Assert.That(op, Is.Not.Null);
                Assert.That(op.Object, Is.SameAs(db1.Tables[0]));
            }
Пример #6
0
        public void MultiLineComments()
        {
            const string code   = @"
            /* adfjlaskdjflkasdjflkjdf */
            public class Class1 
            {
                /* Comment1-1
                 * Comment1-2 */
                public int i = 0; /* Trailing Comment
                * Comment2-1 */
                public int j = 0;
            }";
            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;

            Assert.That(codeRoot, Is.InstanceOfType(typeof(CodeRoot)));
            Assert.That(codeRoot.WalkChildren(), Has.Count(1));

            Class clazz = (Class)codeRoot.WalkChildren()[0];

            Assert.That(clazz, Is.Not.Null);

            Assert.That(clazz.Name, Is.EqualTo("Class1"));
            Assert.That(clazz.Comments.PreceedingComments, Has.Count(1));
            Assert.That(clazz.Comments.PreceedingComments[0].Trim(), Is.EqualTo("/* adfjlaskdjflkasdjflkjdf */"));

            Assert.That(clazz.WalkChildren(), Has.Count(2));
            Field field = (Field)clazz.WalkChildren()[0];

            Assert.That(field.Name, Is.EqualTo("i"));
            Assert.That(field.Comments.PreceedingComments, Has.Count(1));
            Assert.That(field.Comments.PreceedingComments[0], Is.EqualTo(@"/* Comment1-1
                 * Comment1-2 */"));
            Assert.That(field.Comments.TrailingComment, Is.EqualTo(@"/* Trailing Comment
                * Comment2-1 */"));

            field = (Field)clazz.WalkChildren()[1];
            Assert.That(field.Name, Is.EqualTo("j"));
            Assert.That(field.Comments.PreceedingComments, Has.Count(0));
        }
            public void The_New_Key_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].AddKey(new Key("PK_Table1_1"));

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.KeyOperations, Has.Count(1));
                IMergeOperation <IKey> op = result.KeyOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db2.Tables[0].Keys[1]));
                Assert.That(op, Is.TypeOf(typeof(KeyAdditionOperation)));
            }
        public void It_Creates_The_Right_Relationship()
        {
            var entity1 = mappingSet.EntitySet.GetEntity("BasicClass1");
            var entity2 = mappingSet.EntitySet.GetEntity("BasicClass2");

            Assert.That(entity1.References, Has.Count(1));
            Assert.That(entity2.References, Has.Count(1));

            Assert.That(entity1.References[0], Is.SameAs(entity2.References[0]));

            DirectedReference reference = entity1.DirectedReferences.First();

            Assert.That(reference.FromName, Is.EqualTo("Class2s"));
            Assert.That(reference.ToName, Is.EqualTo("Property1"));
            Assert.That(reference.FromEndCardinality, Is.EqualTo(Cardinality.Many));
            Assert.That(reference.ToEndCardinality, Is.EqualTo(Cardinality.One));
            Assert.That(reference.FromEndEnabled, Is.True);
            Assert.That(reference.ToEndEnabled, Is.True);
        }
            public void The_Removed_Index_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].RemoveIndex(db2.Tables[0].Indexes[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.IndexOperations, Has.Count(1));
                IMergeOperation <IIndex> op = result.IndexOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Indexes[0]));
                Assert.That(op, Is.TypeOf(typeof(IndexRemovalOperation)));
            }
        public void It_Fills_The_Properties_In()
        {
            var entity = mappingSet.EntitySet.GetEntity("BasicClass1");

            Assert.That(entity.Properties, Has.Count(3));

            var property = entity.Properties.ElementAt(0);

            Assert.That(property.Name, Is.EqualTo("ID"));
            Assert.That(property.Type, Is.EqualTo("int"));

            property = entity.Properties.ElementAt(1);
            Assert.That(property.Name, Is.EqualTo("Property1"));
            Assert.That(property.Type, Is.EqualTo("System.String"));

            property = entity.Properties.ElementAt(2);
            Assert.That(property.Name, Is.EqualTo("Property2"));
            Assert.That(property.Type, Is.EqualTo("Test.Class1"));
        }
Пример #11
0
        public void It_Should_Be_Reconstructed_Correctly()
        {
            const string xml =
                @"<LogicalSchema Version = ""1"">" +
                "<DatabaseName>Database1</DatabaseName>" +
                "<Table>" + When_Serialising_An_Empty_Table.ScriptBaseXml +
                "<Columns>" + When_Serialising_An_Empty_Column.BasicColumnXml + "</Columns>" +
                "</Table>" +
                "</LogicalSchema>";

            IDatabase db = new DatabaseDeserialisationScheme().Deserialise(xml);

            Assert.That(db.Tables, Has.Count(1));
            ITable table = db.Tables[0];

            Assert.That(table.Name, Is.EqualTo("Entity1"));
            Assert.That(table.Columns, Has.Count(1));
            Assert.That(table.Columns[0].Name, Is.EqualTo("Entity1"));
            Assert.That(table.Columns[0].Parent, Is.SameAs(table));
        }
Пример #12
0
        public void It_Should_Create_An_Association_Table_Mapped_To_The_Reference()
        {
            var mappedTable = reference.MappedTable();

            Assert.That(mappedTable, Is.Not.Null);
            Assert.That(mappedTable.Columns, Has.Count(2));
            Assert.That(mappedTable.Keys, Has.Count(2));

            var entity1Table = entity1.MappedTables().First();
            var entity2Table = entity2.MappedTables().First();

            var table1ForeignKey = mappedTable.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign && k.ReferencedKey == entity1Table.FirstPrimaryKey);
            var table2ForeignKey = mappedTable.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign && k.ReferencedKey == entity2Table.FirstPrimaryKey);

            Assert.That(table1ForeignKey, Is.Not.Null);
            Assert.That(table1ForeignKey.Columns, Has.Count(1));

            Assert.That(table2ForeignKey, Is.Not.Null);
            Assert.That(table2ForeignKey.Columns, Has.Count(1));
        }
Пример #13
0
        public void The_Rule_Fails()
        {
            var set = new MappingSetImpl();

            set.Database.AddTable(new Table("Table1"));
            var duplicate = new Table("Table1");

            set.Database.AddTable(duplicate);

            DatabaseNamingRule rule = new DatabaseNamingRule();
            var result = rule.Run(set);

            Assert.That(result.Issues, Has.Count(1));

            var issue = result.Issues[0];

            Assert.That(issue.ErrorLevel, Is.EqualTo(ValidationErrorLevel.Error));
            Assert.That(issue.Object, Is.SameAs(duplicate));
            StringAssert.Contains("Table1", issue.Description);
        }
        public void creating_keydata_programatically()
        {
            var strValueTest    = "Test String";
            var strKeyTest      = "Mykey";
            var commentListTest = new List <string>(new string[] { "testComment 1", "testComment 2" });

            //Create a key data
            KeyData kd = new KeyData(strKeyTest);

            kd.Value    = strValueTest;
            kd.Comments = commentListTest;

            //Assert not null and empty
            Assert.That(kd, Is.Not.Null);
            Assert.That(kd.KeyName, Is.EqualTo(strKeyTest));
            Assert.That(kd.Value, Is.EqualTo(strValueTest));
            Assert.That(kd.Comments, Has.Count(2));
            Assert.That(kd.Comments[0], Is.EqualTo("testComment 1"));
            Assert.That(kd.Comments[1], Is.EqualTo("testComment 2"));
        }
Пример #15
0
            public void The_Original_Foreign_Key_Should_Be_Modified()
            {
                var db1 = RelationshipDatabaseLoader.GetDb();

                IKey originalKey = db1.Tables[1].Keys[0];

                originalKey.Description = "old description";

                IKey newPrimaryKey = new Key(db1.Tables[0].Keys[0].Name);

                newPrimaryKey.Parent = new Table("Table1");
                newPrimaryKey.Parent.AddColumn(new Column("Column1"));
                newPrimaryKey.Description = "new description";
                newPrimaryKey.AddColumn("Column1");

                IKey newForeignKey = new Key(originalKey.Name);

                newForeignKey.Parent = new Table("Table2");
                newForeignKey.Parent.AddColumn(new Column("Column2"));
                newForeignKey.Parent.AddColumn(new Column("Column3"));
                newForeignKey.Description = "new description";
                newForeignKey.AddColumn("Column3");                 // This is the change.
                newForeignKey.ReferencedKey = newPrimaryKey;

                KeyChangeOperation op = new KeyChangeOperation(db1.Tables[1].Keys[0], newForeignKey);

                op.RunOperation();
                op.RunSecondStep();

                IKey key = db1.Tables[1].Keys[0];

                Assert.That(db1.Tables[1].Keys, Has.Count(1));
                Assert.That(key, Is.SameAs(originalKey), "Key object should still be the same");
                Assert.That(key.Description, Is.EqualTo("old description"), "Should not change user set properties.");
                Assert.That(key.ReferencedKey, Is.SameAs(db1.Tables[0].Keys[0]));
                Assert.That(key.Columns, Has.Count(1));
                Assert.That(key.Columns[0].Name, Is.EqualTo("Column3"));
                Assert.That(key.Columns[0], Is.Not.SameAs(newForeignKey.Columns[0]));
                Assert.That(key.Columns[0], Is.SameAs(db1.Tables[1].Columns[2]), "The new key should reference existing columns");
                Assert.That(key.Parent, Is.SameAs(db1.Tables[1]), "The new key's parent should be Table1 in the existing database");
            }
Пример #16
0
        public void TestDeleteLine()
        {
            TextFileInformation tfi = new TextFileInformation();

            tfi.NewGenFile       = new TextFile("line 0\r\nline 1\r\nline 2");
            tfi.IntelliMerge     = IntelliMergeType.PlainText;
            tfi.RelativeFilePath = "text.txt";

            ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi);
            VisualDiffOutput   output      = diffUtility.ProcessMergeOutput();

            Assert.IsNotNull(output);
            Assert.That(output.RightLines, Has.Count(3));
            Assert.That(output.LeftLines, Has.Count(3));

            output.RemoveLine(0);
            Assert.That(output.RightLines, Has.Count(2));
            Assert.That(output.LeftLines, Has.Count(2));
            Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1"));
            Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1"));
        }
Пример #17
0
        public void Structures_MultipleFields()
        {
            const string code = @"    
            public class Class1 
            {
                public struct Structure1 
				{
					public int i;
					public int j;
				}
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Struct con = (Struct)clazz.WalkChildren()[0];

            Assert.That(con.Name, Is.EqualTo("Structure1"));
            Assert.That(con.Modifiers, Has.Count(1));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));

            Field f1 = con.Fields[0];

            Assert.That(f1.Name, Is.EqualTo("i"));
            Assert.That(f1.Modifiers, Has.Count(1));
            Assert.That(f1.Modifiers[0], Is.EqualTo("public"));
            Assert.That(f1.DataType.Name, Is.EqualTo("int"));

            Field f2 = con.Fields[1];

            Assert.That(f2.Name, Is.EqualTo("j"));
            Assert.That(f2.Modifiers, Has.Count(1));
            Assert.That(f2.Modifiers[0], Is.EqualTo("public"));
            Assert.That(f2.DataType.Name, Is.EqualTo("int"));
        }
        public void It_Should_Create_This()
        {
            const string xml          = When_Serialising_A_Component.BasicComponentXml;
            var          parentEntity = new EntityImpl("Entity1");

            var entitySet = new EntitySetImpl();

            entitySet.AddEntity(parentEntity);

            var spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.EntitySet = entitySet;

            Component comp = new EntitySetDeserialisationScheme().DeserialiseComponent(xml.GetXmlDocRoot(), spec);

            Assert.That(comp.Name, Is.EqualTo("HomeAddress"));
            Assert.That(comp.ParentEntity, Is.SameAs(parentEntity));
            Assert.That(comp.Specification, Is.SameAs(spec));
            Assert.That(comp.Properties, Has.Count(1));
            Assert.That(comp.Properties[0].RepresentedProperty, Is.SameAs(spec.Properties[0]));
        }
Пример #19
0
        public void Structures()
        {
            const string code = @"    
            public class Class1 
            {
                public struct Structure1 { }
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Struct con = (Struct)clazz.WalkChildren()[0];

            Assert.That(con.Name, Is.EqualTo("Structure1"));
            Assert.That(con.Modifiers, Has.Count(1));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
        }
        public void ClearMap()
        {
            MockRepository mocks = new MockRepository();
            CodeRootMap    map   = new CodeRootMap();
            IBaseConstruct bc;

            using (mocks.Record())
            {
                bc = mocks.DynamicMock <IBaseConstruct>();
                Expect.Call(bc.WalkChildren()).Return(new List <IBaseConstruct>().AsReadOnly());
            }

            map.AddBaseConstructAsNewChild(bc, Version.User);

            Assert.That(map.AllNodes, Has.Count(1));
            Assert.That(map.ChildNodes, Has.Count(1));

            map.Clear();

            Assert.That(map.AllNodes, Has.Count(0));
            Assert.That(map.ChildNodes, Has.Count(0));
        }
        public void The_Rule_Fails()
        {
            var set    = new MappingSetImpl();
            var entity = new EntityImpl("Entity1");

            set.EntitySet.AddEntity(entity);
            entity.AddProperty(new PropertyImpl("Property1"));
            var duplicate = new PropertyImpl("Property1");

            entity.AddProperty(duplicate);

            EntityNamingRule rule = new EntityNamingRule();
            var result            = rule.Run(set);

            Assert.That(result.Issues, Has.Count(1));

            var issue = result.Issues[0];

            Assert.That(issue.ErrorLevel, Is.EqualTo(ValidationErrorLevel.Error));
            Assert.That(issue.Object, Is.SameAs(duplicate));
            StringAssert.Contains("Property1", issue.Description);
        }
Пример #22
0
        public void Interfaces()
        {
            const string code = @"    
            public class Class1 
            {
                public interface MarkerInterface { }
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Interface con = (Interface)clazz.WalkChildren()[0];

            Assert.That(con.Name, Is.EqualTo("MarkerInterface"));
            Assert.That(con.Modifiers, Has.Count(1));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
        }
        public void check_clone_operation()
        {
            var strValueTest    = "Test String";
            var strKeyTest      = "Mykey";
            var commentListTest = new List <string>(new string[] { "testComment 1", "testComment 2" });

            //Create a key data
            KeyData kd2 = new KeyData(strKeyTest);

            kd2.Value    = strValueTest;
            kd2.Comments = commentListTest;

            KeyData kd = kd2.Clone() as KeyData;

            //Assert not null and empty
            Assert.That(kd, Is.Not.Null);
            Assert.That(kd.KeyName, Is.EqualTo(strKeyTest));
            Assert.That(kd.Value, Is.EqualTo(strValueTest));
            Assert.That(kd.Comments, Has.Count(2));
            Assert.That(kd.Comments[0], Is.EqualTo("testComment 1"));
            Assert.That(kd.Comments[1], Is.EqualTo("testComment 2"));
        }
        /// <summary>
        /// Returns the IBaseConstruct for Class1
        /// </summary>
        /// <param name="cr"></param>
        /// <returns></returns>
        private static void AssertBasicConstructsExist(ICodeRoot cr)
        {
            Assert.That(cr.WalkChildren(), Has.Count(1));

            IBaseConstruct namespaceBC = cr.WalkChildren()[0];

            Assert.That(namespaceBC.FullyQualifiedIdentifer, Is.EqualTo("Slyce.IntelliMerge.UnitTesting.Resources.CSharp"));

            Assert.That(namespaceBC.WalkChildren(), Has.Count(1));
            IBaseConstruct classBC = namespaceBC.WalkChildren()[0];

            Assert.That(classBC.FullyQualifiedIdentifer,
                        Is.EqualTo(string.Format("Slyce.IntelliMerge.UnitTesting.Resources.CSharp{0}Class1", BaseConstructConstants.FullyQualifiedIdentifierSeparator)));

            Assert.That(classBC.WalkChildren(), Has.Count(1));
            IBaseConstruct methodBC = classBC.WalkChildren()[0];

            Assert.That(methodBC.FullyQualifiedIdentifer,
                        Is.EqualTo(string.Format("Slyce.IntelliMerge.UnitTesting.Resources.CSharp{0}Class1{0}Method ()", BaseConstructConstants.FullyQualifiedIdentifierSeparator)));

            return;
        }
            public void The_Changed_Key_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();

                db1.Tables[0].Keys[0].UID = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].Keys[0].Keytype = DatabaseKeyType.None;
                db2.Tables[0].Keys[0].UID     = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.KeyOperations, Has.Count(1));
                IMergeOperation <IKey> op = result.KeyOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Keys[0]));
                Assert.That(op, Is.TypeOf(typeof(KeyChangeOperation)));
            }
Пример #26
0
        public void Fields()
        {
            const string code = @"    
            public class Class1 
            {
                public static int i = 0;
                public const float PI = 3.14159265358979323846;
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.FormatSettings.ReorderBaseConstructs = false;
            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Field con = (Field)clazz.WalkChildren()[0];

            Assert.That(con.Name, Is.EqualTo("i"));
            Assert.That(con.Modifiers, Has.Count(2));
            Assert.That(con.DataType.Name, Is.EqualTo("int"));
            Assert.That(con.InitialValue, Is.EqualTo("0"));
            // Modifiers should be kept in order.
            Assert.That(con.Modifiers, Has.Count(2));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
            Assert.That(con.Modifiers[1], Is.EqualTo("static"));

            con = (Field)clazz.WalkChildren()[1];
            Assert.That(con.Name, Is.EqualTo("PI"));
            Assert.That(con.Modifiers, Has.Count(2));
            Assert.That(con.DataType.Name, Is.EqualTo("float"));
            Assert.That(con.InitialValue, Is.EqualTo("3.14159265358979323846"));
            // Modifiers should be kept in order.
            Assert.That(con.Modifiers, Has.Count(2));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
            Assert.That(con.Modifiers[1], Is.EqualTo("const"));
        }
        public void TestConflict_At_Start_Delete_At_End()
        {
            TextFileInformation tfi = new TextFileInformation();

            tfi.PrevGenFile      = new TextFile("line1\nline3");
            tfi.UserFile         = new TextFile("line00\nline1");
            tfi.NewGenFile       = new TextFile("line0\nline1");
            tfi.IntelliMerge     = IntelliMergeType.PlainText;
            tfi.RelativeFilePath = "text.txt";

            ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi);
            VisualDiffOutput   output      = diffUtility.ProcessMergeOutput();

            Assert.IsNotNull(output);
            Assert.That(output.RightLines, Is.Not.Empty);
            Assert.That(output.LeftLines, Is.Not.Empty);
            Assert.That(output.LeftLines, Has.Count(4));
            Assert.That(output.RightLines, Has.Count(4));

            Assert.That(output.LeftLines[0].Text, Is.EqualTo("line00"), "Line 1 on left");
            Assert.That(output.LeftLines[1].Text, Is.EqualTo("line0"), "Line 2 on left");
            Assert.That(output.LeftLines[2].Text, Is.EqualTo("line1"), "Line 3 on left");
            Assert.That(output.LeftLines[3].Text, Is.EqualTo("line3"), "Line 4 on left");
            Assert.That(output.RightLines[0].Text, Is.EqualTo(""), "Line 1 on right");
            Assert.That(output.RightLines[1].Text, Is.EqualTo(""), "Line 2 on right");
            Assert.That(output.RightLines[2].Text, Is.EqualTo("line1"), "Line 3 on right");
            Assert.That(output.RightLines[3].Text, Is.EqualTo(""), "Line 4 on right");

            Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.User));
            Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template));
            Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.None));
            Assert.That(output.LeftLines[3].Change, Is.EqualTo(ChangeType.UserAndTemplate));

            Assert.That(output.RightLines[0].IsVirtual, Is.True);
            Assert.That(output.RightLines[1].IsVirtual, Is.True);
            Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.None));
            Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.User | ChangeType.Template));
        }
        public void A_SQLCEDatabaseLoader_Is_Returned()
        {
            IDatabaseForm form  = MockRepository.GenerateMock <IDatabaseForm>();
            IMainPanel    panel = MockRepository.GenerateMock <IMainPanel>();

            DatabasePresenter presenter = new DatabasePresenter(panel, form);

            form.Stub(t => t.SelectedDatabaseType).Return(DatabaseTypes.SQLCE);
            form.Stub(t => t.SelectedDatabase).Return("1Table3Columns.sdf");

            IDatabaseLoader loader = presenter.CreateDatabaseLoader();

            Assert.That(loader, Is.Not.Null);
            Assert.That(loader, Is.TypeOf(typeof(SQLCEDatabaseLoader)));

            // Will throw an error if the database connection could not be established.
            loader.TestConnection();

            IDatabase db = loader.LoadDatabase();

            Assert.That(db.Name, Is.EqualTo("1Table3Columns"));
            Assert.That(db.Tables, Has.Count(1));             // Basic check to see if we got the correct database back.
        }
Пример #29
0
        public void Events()
        {
            const string code = @"    
            public class Class1 
            {
                public event Delegate1 Event1;
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Event enu = (Event)clazz.WalkChildren()[0];

            Assert.That(enu.Name, Is.EqualTo("Event1"));
            Assert.That(enu.Modifiers, Has.Count(1));
            Assert.That(enu.Modifiers[0], Is.EqualTo("public"));
            Assert.That(enu.DataType.ToString(), Is.EqualTo("Delegate1"));
        }
        public void testMultipleErrors()
        {
            CSharpParser parser = new CSharpParser();

            parser.ParseCode(@"using System
			using NUnit.Framework;
			class Hahaha
			{
				publi TestMethod()
				{ 
				}
			}"            );
            Assert.That(parser.ErrorOccurred, Is.True);
            Assert.That(parser.SyntaxErrors, Has.Count(2));
            Assert.That(parser.SyntaxErrors[0].LineNumber, Is.EqualTo(0));
            Assert.That(parser.SyntaxErrors[1].LineNumber, Is.EqualTo(4));


            parser = new CSharpParser();
            parser.ParseCode(@"using System
			using NUnit.Framework;
			class Hahaha
			{
				publi TestMethod()
				{ 
				}

				public testOtherMethod(
				{
				}
			}"            );
            Assert.That(parser.ErrorOccurred, Is.True);
            Assert.That(parser.SyntaxErrors, Has.Count(3));
            Assert.That(parser.SyntaxErrors[0].LineNumber, Is.EqualTo(0));
            Assert.That(parser.SyntaxErrors[1].LineNumber, Is.EqualTo(4));
            Assert.That(parser.SyntaxErrors[2].LineNumber, Is.EqualTo(8));
        }