public void ToStringTest() { var ds = new DataSet(); DataTable dtChild = DataProvider.CreateChildDataTable(); DataTable dtParent = DataProvider.CreateParentDataTable(); ds.Tables.Add(dtParent); ds.Tables.Add(dtChild); DataRelation dRel; dRel = new DataRelation(null, dtParent.Columns[0], dtChild.Columns[0]); // ToString 1 Assert.Equal(string.Empty, dRel.ToString()); ds.Relations.Add(dRel); // ToString 2 Assert.Equal("Relation1", dRel.ToString()); dRel.RelationName = "myRelation"; // ToString 3 Assert.Equal("myRelation", dRel.ToString()); }
public void Creation3() { DataRelation Relation = new DataRelation("Rel", Mom.Columns [1], Child.Columns [0], false); Set.Relations.Add(Relation); DataRelation Test = null; Assert.That(Mom.ChildRelations.Count, Is.EqualTo(1), "test#01"); Assert.That(Child.ChildRelations.Count, Is.EqualTo(0), "test#02"); Assert.That(Mom.ParentRelations.Count, Is.EqualTo(0), "test#03"); Assert.That(Child.ParentRelations.Count, Is.EqualTo(1), "test#04"); Test = Child.ParentRelations [0]; Assert.That(Test.ToString(), Is.EqualTo("Rel"), "test#05"); Assert.That(Test.RelationName, Is.EqualTo("Rel"), "test#06"); Assert.That(Test.ParentTable.TableName, Is.EqualTo("Mom"), "test#07"); Assert.That(Test.ParentKeyConstraint, Is.Null, "test#08"); Assert.That(Test.ParentKeyConstraint, Is.Null, "test#09"); Assert.That(Test.ParentColumns.Length, Is.EqualTo(1), "test#10"); Assert.That(Test.Nested, Is.False, "test#11"); Assert.That(Test.ExtendedProperties.Count, Is.EqualTo(0), "test#12"); Assert.That(Test.ChildTable.TableName, Is.EqualTo("Child"), "test#13"); Assert.That(Test.ChildKeyConstraint, Is.Null, "test#14"); Assert.That(Test.ChildColumns.Length, Is.EqualTo(1), "test#15"); Assert.That(Mom.Constraints.Count, Is.EqualTo(0), "test#16"); Assert.That(Child.Constraints.Count, Is.EqualTo(0), "test#17"); }
public void Creation3() { DataRelation Relation = new DataRelation("Rel", Mom.Columns [1], Child.Columns [0], false); Set.Relations.Add(Relation); DataRelation Test = null; AssertEquals("test#01", 1, Mom.ChildRelations.Count); AssertEquals("test#02", 0, Child.ChildRelations.Count); AssertEquals("test#03", 0, Mom.ParentRelations.Count); AssertEquals("test#04", 1, Child.ParentRelations.Count); Test = Child.ParentRelations [0]; AssertEquals("test#05", "Rel", Test.ToString()); AssertEquals("test#06", "Rel", Test.RelationName); AssertEquals("test#07", "Mom", Test.ParentTable.TableName); Assert("test#08", Test.ParentKeyConstraint == null); Assert("test#09", Test.ParentKeyConstraint == null); AssertEquals("test#10", 1, Test.ParentColumns.Length); AssertEquals("test#11", false, Test.Nested); AssertEquals("test#12", 0, Test.ExtendedProperties.Count); AssertEquals("test#13", "Child", Test.ChildTable.TableName); Assert("test#14", Test.ChildKeyConstraint == null); AssertEquals("test#15", 1, Test.ChildColumns.Length); AssertEquals("test#16", 0, Mom.Constraints.Count); AssertEquals("test#17", 0, Child.Constraints.Count); }
public void Creation4() { DataRelation Relation = new DataRelation("Rel", "Mom", "Child", new string[] { "ChildName" }, new string[] { "Name" }, true); Assert.Throws <NullReferenceException>(() => _set.Relations.Add(Relation)); Assert.Throws <NullReferenceException>(() => _set.Relations.AddRange(new DataRelation[] { Relation })); _set.BeginInit(); _set.Relations.AddRange(new DataRelation[] { Relation }); _set.EndInit(); DataRelation Test = null; Assert.Equal(1, _mom.ChildRelations.Count); Assert.Equal(0, _child.ChildRelations.Count); Assert.Equal(0, _mom.ParentRelations.Count); Assert.Equal(1, _child.ParentRelations.Count); Test = _child.ParentRelations[0]; Assert.Equal("Rel", Test.ToString()); Assert.Equal("Rel", Test.RelationName); Assert.Equal("Mom", Test.ParentTable.TableName); Assert.Null(Test.ParentKeyConstraint); Assert.Equal(1, Test.ParentColumns.Length); Assert.True(Test.Nested); Assert.Equal(0, Test.ExtendedProperties.Count); Assert.Equal("Child", Test.ChildTable.TableName); Assert.Null(Test.ChildKeyConstraint); Assert.Equal(1, Test.ChildColumns.Length); }
public void Creation3() { DataRelation Relation = new DataRelation("Rel", _mom.Columns[1], _child.Columns[0], false); _set.Relations.Add(Relation); DataRelation Test = null; Assert.Equal(1, _mom.ChildRelations.Count); Assert.Equal(0, _child.ChildRelations.Count); Assert.Equal(0, _mom.ParentRelations.Count); Assert.Equal(1, _child.ParentRelations.Count); Test = _child.ParentRelations[0]; Assert.Equal("Rel", Test.ToString()); Assert.Equal("Rel", Test.RelationName); Assert.Equal("Mom", Test.ParentTable.TableName); Assert.Null(Test.ParentKeyConstraint); Assert.Null(Test.ParentKeyConstraint); Assert.Equal(1, Test.ParentColumns.Length); Assert.False(Test.Nested); Assert.Equal(0, Test.ExtendedProperties.Count); Assert.Equal("Child", Test.ChildTable.TableName); Assert.Null(Test.ChildKeyConstraint); Assert.Equal(1, Test.ChildColumns.Length); Assert.Equal(0, _mom.Constraints.Count); Assert.Equal(0, _child.Constraints.Count); }
//Activate This Construntor to log All To Standard output //public TestClass():base(true){} //Activate this constructor to log Failures to a log file //public TestClass(System.IO.TextWriter tw):base(tw, false){} //Activate this constructor to log All to a log file //public TestClass(System.IO.TextWriter tw):base(tw, true){} //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES public void run() { Exception exp = null; DataSet ds = new DataSet(); DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable(); DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable(); ds.Tables.Add(dtParent); ds.Tables.Add(dtChild); DataRelation dRel; dRel = new DataRelation(null, dtParent.Columns[0], dtChild.Columns[0]); try { BeginCase("ToString 1"); Compare(dRel.ToString(), string.Empty); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } ds.Relations.Add(dRel); try { BeginCase("ToString 2"); Compare(dRel.ToString(), "Relation1"); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } dRel.RelationName = "myRelation"; try { BeginCase("ToString 3"); Compare(dRel.ToString(), "myRelation"); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } }
public void Creation4() { DataRelation Relation = new DataRelation("Rel", "Mom", "Child", new string [] { "ChildName" }, new string [] { "Name" }, true); try { Set.Relations.Add(Relation); Fail("test#01"); } catch (Exception e) { AssertEquals("test#02", typeof(NullReferenceException), e.GetType()); } try { Set.Relations.AddRange(new DataRelation [] { Relation }); Fail("test#03"); } catch (Exception e) { AssertEquals("test#04", typeof(NullReferenceException), e.GetType()); } Set.BeginInit(); Set.Relations.AddRange(new DataRelation [] { Relation }); Set.EndInit(); DataRelation Test = null; AssertEquals("test#01", 1, Mom.ChildRelations.Count); AssertEquals("test#02", 0, Child.ChildRelations.Count); AssertEquals("test#03", 0, Mom.ParentRelations.Count); AssertEquals("test#04", 1, Child.ParentRelations.Count); Test = Child.ParentRelations [0]; AssertEquals("test#05", "Rel", Test.ToString()); AssertEquals("test#06", "Rel", Test.RelationName); AssertEquals("test#07", "Mom", Test.ParentTable.TableName); AssertEquals("test#08", true, Test.ParentKeyConstraint == null); AssertEquals("test#10", 1, Test.ParentColumns.Length); AssertEquals("test#11", true, Test.Nested); AssertEquals("test#12", 0, Test.ExtendedProperties.Count); AssertEquals("test#13", "Child", Test.ChildTable.TableName); AssertEquals("test#14", true, Test.ChildKeyConstraint == null); AssertEquals("test#15", 1, Test.ChildColumns.Length); }
public void Creation4() { DataRelation Relation = new DataRelation("Rel", "Mom", "Child", new string [] { "ChildName" }, new string [] { "Name" }, true); try { Set.Relations.Add(Relation); Assert.Fail("test#01"); } catch (Exception e) { Assert.That(e, Is.TypeOf(typeof(NullReferenceException)), "test#02"); } try { Set.Relations.AddRange(new DataRelation [] { Relation }); Assert.Fail("test#03"); } catch (Exception e) { Assert.That(e, Is.TypeOf(typeof(NullReferenceException)), "test#04"); } Set.BeginInit(); Set.Relations.AddRange(new DataRelation [] { Relation }); Set.EndInit(); DataRelation Test = null; Assert.That(Mom.ChildRelations.Count, Is.EqualTo(1), "test#01"); Assert.That(Child.ChildRelations.Count, Is.EqualTo(0), "test#02"); Assert.That(Mom.ParentRelations.Count, Is.EqualTo(0), "test#03"); Assert.That(Child.ParentRelations.Count, Is.EqualTo(1), "test#04"); Test = Child.ParentRelations [0]; Assert.That(Test.ToString(), Is.EqualTo("Rel"), "test#05"); Assert.That(Test.RelationName, Is.EqualTo("Rel"), "test#06"); Assert.That(Test.ParentTable.TableName, Is.EqualTo("Mom"), "test#07"); Assert.That(Test.ParentKeyConstraint, Is.Null, "test#08"); Assert.That(Test.ParentColumns.Length, Is.EqualTo(1), "test#10"); Assert.That(Test.Nested, Is.True, "test#11"); Assert.That(Test.ExtendedProperties.Count, Is.EqualTo(0), "test#12"); Assert.That(Test.ChildTable.TableName, Is.EqualTo("Child"), "test#13"); Assert.That(Test.ChildKeyConstraint, Is.Null, "test#14"); Assert.That(Test.ChildColumns.Length, Is.EqualTo(1), "test#15"); }
public void Creation() { DataRelation relation = new DataRelation("Rel", _mom.Columns[1], _child.Columns[0]); _set.Relations.Add(relation); Assert.Equal(1, _mom.ChildRelations.Count); Assert.Equal(0, _child.ChildRelations.Count); Assert.Equal(0, _mom.ParentRelations.Count); Assert.Equal(1, _child.ParentRelations.Count); DataRelation test = _child.ParentRelations[0]; Assert.Equal("Rel", test.ToString()); Assert.Equal("Rel", test.RelationName); Assert.Equal("Mom", test.ParentTable.TableName); Assert.Equal(1, test.ParentKeyConstraint.Columns.Length); Assert.False(test.ParentKeyConstraint.IsPrimaryKey); Assert.Equal(1, test.ParentColumns.Length); Assert.False(test.Nested); Assert.Equal(0, test.ExtendedProperties.Count); Assert.Equal("Child", test.ChildTable.TableName); Assert.Equal("Rel", test.ChildKeyConstraint.ConstraintName); Assert.Equal(1, test.ChildColumns.Length); }
public void Creation2() { DataSet Set = new DataSet(); DataTable Mom2 = new DataTable("Mom"); DataTable Child2 = new DataTable("Child"); DataTable Hubby = new DataTable("Hubby"); Set.Tables.Add(Mom2); Set.Tables.Add(Child2); Set.Tables.Add(Hubby); DataColumn Col = new DataColumn("Name"); DataColumn Col2 = new DataColumn("ChildName"); DataColumn Col3 = new DataColumn("hubby"); Mom2.Columns.Add(Col); Mom2.Columns.Add(Col2); Mom2.Columns.Add(Col3); DataColumn Col4 = new DataColumn("Name"); DataColumn Col5 = new DataColumn("Age"); DataColumn Col6 = new DataColumn("father"); Child2.Columns.Add(Col4); Child2.Columns.Add(Col5); Child2.Columns.Add(Col6); DataColumn Col7 = new DataColumn("Name"); DataColumn Col8 = new DataColumn("Age"); Hubby.Columns.Add(Col7); Hubby.Columns.Add(Col8); DataColumn [] Parents = new DataColumn [2]; Parents [0] = Col2; Parents [1] = Col3; DataColumn [] Childs = new DataColumn [2]; Childs [0] = Col4; Childs [1] = Col7; DataRelation Relation = null; try { Relation = new DataRelation("Rel", Parents, Childs); Assert.Fail("test#01"); } catch (InvalidConstraintException e) { // Assert.That (e.GetType (), Is.EqualTo(typeof (InvalidConstraintException)), "test#02"); // Assert.That (e.Message, Is.EqualTo("Cannot create a Key from Columns that belong to different tables."), "test#03"); } Childs [1] = Col6; Relation = new DataRelation("Rel", Parents, Childs); Set.Relations.Add(Relation); DataRelation Test = null; Assert.That(Mom2.ChildRelations.Count, Is.EqualTo(1), "test#01"); Assert.That(Child2.ChildRelations.Count, Is.EqualTo(0), "test#02"); Assert.That(Mom2.ParentRelations.Count, Is.EqualTo(0), "test#03"); Assert.That(Child2.ParentRelations.Count, Is.EqualTo(1), "test#04"); Test = Child2.ParentRelations [0]; Assert.That(Test.ToString(), Is.EqualTo("Rel"), "test#05"); Assert.That(Test.RelationName, Is.EqualTo("Rel"), "test#06"); Assert.That(Test.ParentTable.TableName, Is.EqualTo("Mom"), "test#07"); Assert.That(Test.ParentKeyConstraint.Columns.Length, Is.EqualTo(2), "test#08"); Assert.That(Test.ParentKeyConstraint.IsPrimaryKey, Is.False, "test#09"); Assert.That(Test.ParentColumns.Length, Is.EqualTo(2), "test#10"); Assert.That(Test.Nested, Is.False, "test#11"); Assert.That(Test.ExtendedProperties.Count, Is.EqualTo(0), "test#12"); Assert.That(Test.ChildTable.TableName, Is.EqualTo("Child"), "test#13"); Assert.That(Test.ChildKeyConstraint.ConstraintName, Is.EqualTo("Rel"), "test#14"); Assert.That(Test.ChildColumns.Length, Is.EqualTo(2), "test#15"); Assert.That(Mom2.Constraints.Count, Is.EqualTo(1), "test#16"); Assert.That(Mom2.Constraints [0].ToString(), Is.EqualTo("Constraint1"), "test#17"); Assert.That(Child2.Constraints.Count, Is.EqualTo(1), "test#18"); Assert.That(Hubby.Constraints.Count, Is.EqualTo(0), "test#19"); }
public new void ToString() { var ds = new DataSet(); DataTable dtChild = DataProvider.CreateChildDataTable(); DataTable dtParent = DataProvider.CreateParentDataTable(); ds.Tables.Add(dtParent); ds.Tables.Add(dtChild); DataRelation dRel; dRel = new DataRelation(null, dtParent.Columns[0], dtChild.Columns[0]); // ToString 1 Assert.Equal(string.Empty, dRel.ToString()); ds.Relations.Add(dRel); // ToString 2 Assert.Equal("Relation1", dRel.ToString()); dRel.RelationName = "myRelation"; // ToString 3 Assert.Equal("myRelation", dRel.ToString()); }
// <Snippet1> private void PrintName(DataRelation relation) { // Print the name of the DataRelation. Console.WriteLine(relation.ToString()); }
public void Creation2() { DataSet Set = new DataSet(); DataTable Mom2 = new DataTable("Mom"); DataTable Child2 = new DataTable("Child"); DataTable Hubby = new DataTable("Hubby"); Set.Tables.Add(Mom2); Set.Tables.Add(Child2); Set.Tables.Add(Hubby); DataColumn Col = new DataColumn("Name"); DataColumn Col2 = new DataColumn("ChildName"); DataColumn Col3 = new DataColumn("hubby"); Mom2.Columns.Add(Col); Mom2.Columns.Add(Col2); Mom2.Columns.Add(Col3); DataColumn Col4 = new DataColumn("Name"); DataColumn Col5 = new DataColumn("Age"); DataColumn Col6 = new DataColumn("father"); Child2.Columns.Add(Col4); Child2.Columns.Add(Col5); Child2.Columns.Add(Col6); DataColumn Col7 = new DataColumn("Name"); DataColumn Col8 = new DataColumn("Age"); Hubby.Columns.Add(Col7); Hubby.Columns.Add(Col8); DataColumn[] Parents = new DataColumn[2]; Parents[0] = Col2; Parents[1] = Col3; DataColumn[] Childs = new DataColumn[2]; Childs[0] = Col4; Childs[1] = Col7; Assert.Throws <InvalidConstraintException>(() => new DataRelation("Rel", Parents, Childs)); Childs[1] = Col6; Set.Relations.Add(new DataRelation("Rel", Parents, Childs)); Assert.Equal(1, Mom2.ChildRelations.Count); Assert.Equal(0, Child2.ChildRelations.Count); Assert.Equal(0, Mom2.ParentRelations.Count); Assert.Equal(1, Child2.ParentRelations.Count); DataRelation Test = Child2.ParentRelations[0]; Assert.Equal("Rel", Test.ToString()); Assert.Equal("Rel", Test.RelationName); Assert.Equal("Mom", Test.ParentTable.TableName); Assert.Equal(2, Test.ParentKeyConstraint.Columns.Length); Assert.False(Test.ParentKeyConstraint.IsPrimaryKey); Assert.Equal(2, Test.ParentColumns.Length); Assert.False(Test.Nested); Assert.Equal(0, Test.ExtendedProperties.Count); Assert.Equal("Child", Test.ChildTable.TableName); Assert.Equal("Rel", Test.ChildKeyConstraint.ConstraintName); Assert.Equal(2, Test.ChildColumns.Length); Assert.Equal(1, Mom2.Constraints.Count); Assert.Equal("Constraint1", Mom2.Constraints[0].ToString()); Assert.Equal(1, Child2.Constraints.Count); Assert.Equal(0, Hubby.Constraints.Count); }
public void Creation2() { DataSet set = new DataSet(); DataTable mom2 = new DataTable("Mom"); DataTable child2 = new DataTable("Child"); DataTable hubby = new DataTable("Hubby"); set.Tables.Add(mom2); set.Tables.Add(child2); set.Tables.Add(hubby); DataColumn col = new DataColumn("Name"); DataColumn col2 = new DataColumn("ChildName"); DataColumn col3 = new DataColumn("hubby"); mom2.Columns.Add(col); mom2.Columns.Add(col2); mom2.Columns.Add(col3); DataColumn col4 = new DataColumn("Name"); DataColumn col5 = new DataColumn("Age"); DataColumn col6 = new DataColumn("father"); child2.Columns.Add(col4); child2.Columns.Add(col5); child2.Columns.Add(col6); DataColumn col7 = new DataColumn("Name"); DataColumn col8 = new DataColumn("Age"); hubby.Columns.Add(col7); hubby.Columns.Add(col8); DataColumn[] Parents = new DataColumn[2]; Parents[0] = col2; Parents[1] = col3; DataColumn[] childs = new DataColumn[2]; childs[0] = col4; childs[1] = col7; Assert.Throws <InvalidConstraintException>(() => new DataRelation("Rel", Parents, childs)); childs[1] = col6; set.Relations.Add(new DataRelation("Rel", Parents, childs)); Assert.Equal(1, mom2.ChildRelations.Count); Assert.Equal(0, child2.ChildRelations.Count); Assert.Equal(0, mom2.ParentRelations.Count); Assert.Equal(1, child2.ParentRelations.Count); DataRelation test = child2.ParentRelations[0]; Assert.Equal("Rel", test.ToString()); Assert.Equal("Rel", test.RelationName); Assert.Equal("Mom", test.ParentTable.TableName); Assert.Equal(2, test.ParentKeyConstraint.Columns.Length); Assert.False(test.ParentKeyConstraint.IsPrimaryKey); Assert.Equal(2, test.ParentColumns.Length); Assert.False(test.Nested); Assert.Equal(0, test.ExtendedProperties.Count); Assert.Equal("Child", test.ChildTable.TableName); Assert.Equal("Rel", test.ChildKeyConstraint.ConstraintName); Assert.Equal(2, test.ChildColumns.Length); Assert.Equal(1, mom2.Constraints.Count); Assert.Equal("Constraint1", mom2.Constraints[0].ToString()); Assert.Equal(1, child2.Constraints.Count); Assert.Equal(0, hubby.Constraints.Count); }