public void RemoveWithoutUnsiting () { TestComponent compA; TestComponent compB; ISite siteA; ISite siteB; compA = new TestComponent (); _container.Add (compA); siteA = compA.Site; compB = new TestComponent (); _container.Add (compB); siteB = compB.Site; _container.RemoveWithoutUnsiting (compB); Assert.AreSame (siteA, compA.Site, "#A1"); Assert.AreSame (siteB, compB.Site, "#A2"); Assert.AreEqual (1, _container.Components.Count, "#A3"); Assert.AreSame (compA, _container.Components [0], "#A4"); // remove component with no site compB = new TestComponent (); _container.RemoveWithoutUnsiting (compB); Assert.AreSame (siteA, compA.Site, "#B1"); Assert.IsNull (compB.Site, "#B2"); Assert.AreEqual (1, _container.Components.Count, "#B3"); Assert.AreSame (compA, _container.Components [0], "#B4"); // remove component associated with other container TestContainer container2 = new TestContainer (); compB = new TestComponent (); container2.Add (compB); siteB = compB.Site; _container.RemoveWithoutUnsiting (compB); Assert.AreSame (siteA, compA.Site, "#C1"); Assert.AreSame (siteB, compB.Site, "#C2"); Assert.AreEqual (1, _container.Components.Count, "#C3"); Assert.AreSame (compA, _container.Components [0], "#C4"); Assert.AreEqual (1, container2.Components.Count, "#C5"); Assert.AreSame (compB, container2.Components [0], "#C6"); }
public void ValidateName_Name_Duplicate () { TestComponent compA = new TestComponent (); _container.Add (compA, "dup"); // same component, same case _container.InvokeValidateName (compA, "dup"); // existing component, same case TestComponent compB = new TestComponent (); _container.Add (compB, "B"); try { _container.InvokeValidateName (compB, "dup"); Assert.Fail ("#A1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2"); Assert.IsNull (ex.InnerException, "#A3"); Assert.IsNotNull (ex.Message, "#A4"); Assert.IsTrue (ex.Message.IndexOf ("'dup'") != -1, "#A5"); Assert.IsNull (ex.ParamName, "#A6"); Assert.AreEqual (2, _container.Components.Count, "#A7"); } _container.InvokeValidateName (compB, "whatever"); // new component, different case TestComponent compC = new TestComponent (); try { _container.InvokeValidateName (compC, "dup"); Assert.Fail ("#B1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2"); Assert.IsNull (ex.InnerException, "#B3"); Assert.IsNotNull (ex.Message, "#B4"); Assert.IsTrue (ex.Message.IndexOf ("'dup'") != -1, "#B5"); Assert.IsNull (ex.ParamName, "#B6"); Assert.AreEqual (2, _container.Components.Count, "#B7"); } _container.InvokeValidateName (compC, "whatever"); // component of other container, different case TestContainer container2 = new TestContainer (); TestComponent compD = new TestComponent (); container2.Add (compD, "B"); try { _container.InvokeValidateName (compD, "dup"); Assert.Fail ("#C1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2"); Assert.IsNull (ex.InnerException, "#C3"); Assert.IsNotNull (ex.Message, "#C4"); Assert.IsTrue (ex.Message.IndexOf ("'dup'") != -1, "#C5"); Assert.IsNull (ex.ParamName, "#C6"); Assert.AreEqual (2, _container.Components.Count, "#C7"); } _container.InvokeValidateName (compD, "whatever"); Assert.AreEqual (1, container2.Components.Count, "#C8"); Assert.AreSame (compD, container2.Components [0], "#C9"); }
public void Add2_Name_Duplicate () { TestContainer container = new TestContainer (); TestComponent c1 = new TestComponent (); container.Add (c1, "dup"); // new component, same case TestComponent c2 = new TestComponent (); try { container.Add (c2, "dup"); Assert.Fail ("#A1"); } catch (ArgumentException ex) { // Duplicate component name 'dup'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2"); Assert.IsNull (ex.InnerException, "#A3"); Assert.IsNotNull (ex.Message, "#A4"); Assert.IsTrue (ex.Message.IndexOf ("'dup'") != -1, "#A5"); Assert.IsNull (ex.ParamName, "#A6"); Assert.AreEqual (1, container.Components.Count, "#A7"); } // new component, different case TestComponent c3 = new TestComponent (); try { container.Add (c3, "duP"); Assert.Fail ("#B1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2"); Assert.IsNull (ex.InnerException, "#B3"); Assert.IsNotNull (ex.Message, "#B4"); Assert.IsTrue (ex.Message.IndexOf ("'duP'") != -1, "#B5"); Assert.IsNull (ex.ParamName, "#B6"); Assert.AreEqual (1, container.Components.Count, "#B7"); } // existing component, same case TestComponent c4 = new TestComponent (); container.Add (c4, "C4"); Assert.AreEqual (2, container.Components.Count, "#C1"); container.Add (c4, "dup"); Assert.AreEqual (2, container.Components.Count, "#C2"); Assert.AreEqual ("C4", c4.Site.Name, "#C3"); // component of other container, same case TestContainer container2 = new TestContainer (); TestComponent c5 = new TestComponent (); container2.Add (c5, "C5"); try { container.Add (c5, "dup"); Assert.Fail ("#D1"); } catch (ArgumentException ex) { // Duplicate component name 'dup'. Component names must be // unique and case-insensitive Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2"); Assert.IsNull (ex.InnerException, "#D3"); Assert.IsNotNull (ex.Message, "#D4"); Assert.IsTrue (ex.Message.IndexOf ("'dup'") != -1, "#D5"); Assert.IsNull (ex.ParamName, "#D6"); Assert.AreEqual (2, container.Components.Count, "#D7"); } Assert.AreEqual (1, container2.Components.Count, "#D8"); Assert.AreSame (c5, container2.Components [0], "#D9"); #if NET_2_0 container.AllowDuplicateNames = true; TestComponent c6 = new TestComponent (); container.Add (c6, "dup"); Assert.AreEqual (3, container.Components.Count, "#E1"); Assert.IsNotNull (c1.Site, "#E2"); Assert.AreEqual ("dup", c1.Site.Name, "#E3"); Assert.IsNotNull (c6.Site, "#E4"); Assert.AreEqual ("dup", c6.Site.Name, "#E5"); Assert.IsFalse (object.ReferenceEquals (c1.Site, c6.Site), "#E6"); #endif }
[Test] // Dispose () public void Dispose1 () { TestComponent compA; TestComponent compB; compA = new TestComponent (); _container.Add (compA); compB = new TestComponent (); _container.Add (compB); _container.Dispose (); Assert.AreEqual (0, _container.Components.Count, "#A1"); Assert.IsTrue (compA.IsDisposed, "#A2"); Assert.IsNull (compA.Site, "#A3"); Assert.IsTrue (compB.IsDisposed, "#A4"); Assert.IsNull (compB.Site, "#A5"); _container = new TestContainer (); compA = new TestComponent (); compA.ThrowOnDispose = true; _container.Add (compA); compB = new TestComponent (); _container.Add (compB); // assert that component is not removed from components until after // Dispose of component has succeeded try { _container.Dispose (); Assert.Fail ("#B1"); } catch (InvalidOperationException) { Assert.AreEqual (0, _container.Components.Count, "#B2"); Assert.IsFalse (compA.IsDisposed, "#B4"); Assert.IsNull (compA.Site, "#B5"); Assert.IsTrue (compB.IsDisposed, "#B6"); Assert.IsNull (compB.Site, "#B7"); } finally { compA.ThrowOnDispose = false; } _container = new TestContainer (); compA = new TestComponent (); _container.Add (compA); compB = new TestComponent (); compB.ThrowOnDispose = true; _container.Add (compB); try { _container.Dispose (); Assert.Fail ("#C1"); } catch (InvalidOperationException) { Assert.AreEqual (1, _container.Components.Count, "#C2"); Assert.AreSame (compA, _container.Components [0], "#C3"); Assert.IsFalse (compA.IsDisposed, "#C4"); Assert.IsNotNull (compA.Site, "#C5"); Assert.IsFalse (compB.IsDisposed, "#C6"); Assert.IsNull (compB.Site, "#C7"); } finally { compB.ThrowOnDispose = false; } }
public void Init () { _container = new TestContainer (); }
[Test] // Add (IComponent, String) public void Add2 () { TestContainer containerA = new TestContainer (); TestContainer containerB = new TestContainer (); ISite siteA; ISite siteB; TestComponent compA = new TestComponent (); Assert.IsNull (compA.Site); TestComponent compB = new TestComponent (); Assert.IsNull (compB.Site); Assert.AreEqual (0, containerA.Components.Count); Assert.AreEqual (0, containerB.Components.Count); containerA.Add (compA, "A"); siteA = compA.Site; Assert.IsNotNull (siteA); Assert.AreSame (compA, siteA.Component); Assert.AreSame (containerA, siteA.Container); Assert.IsFalse (siteA.DesignMode); Assert.AreEqual ("A", siteA.Name); containerA.Add (compB, "B"); siteB = compB.Site; Assert.IsNotNull (siteB); Assert.AreSame (compB, siteB.Component); Assert.AreSame (containerA, siteB.Container); Assert.IsFalse (siteB.DesignMode); Assert.AreEqual ("B", siteB.Name); Assert.IsFalse (object.ReferenceEquals (siteA, siteB)); Assert.AreEqual (2, containerA.Components.Count); Assert.AreEqual (0, containerB.Components.Count); Assert.AreSame (compA, containerA.Components [0]); Assert.AreSame (compB, containerA.Components [1]); // check effect of adding component that is already member of // another container containerB.Add (compA, "A2"); Assert.IsFalse (object.ReferenceEquals (siteA, compA.Site)); siteA = compA.Site; Assert.IsNotNull (siteA); Assert.AreSame (compA, siteA.Component); Assert.AreSame (containerB, siteA.Container); Assert.IsFalse (siteA.DesignMode); Assert.AreEqual ("A2", siteA.Name); Assert.AreEqual (1, containerA.Components.Count); Assert.AreEqual (1, containerB.Components.Count); Assert.AreSame (compB, containerA.Components [0]); Assert.AreSame (compA, containerB.Components [0]); // check effect of add component twice to same container containerB.Add (compA, "A2"); Assert.AreSame (siteA, compA.Site); Assert.AreEqual ("A2", siteA.Name); Assert.AreEqual (1, containerA.Components.Count); Assert.AreEqual (1, containerB.Components.Count); Assert.AreSame (compB, containerA.Components [0]); Assert.AreSame (compA, containerB.Components [0]); // add again with different name containerB.Add (compA, "A3"); Assert.AreSame (siteA, compA.Site); Assert.AreEqual ("A2", siteA.Name); Assert.AreEqual (1, containerA.Components.Count); Assert.AreEqual (1, containerB.Components.Count); Assert.AreSame (compB, containerA.Components [0]); Assert.AreSame (compA, containerB.Components [0]); // check effect of add component twice to same container containerB.Add (compA, "A2"); Assert.AreSame (siteA, compA.Site); Assert.AreEqual ("A2", siteA.Name); }
public void ValidateName_Name_Duplicate() { TestComponent compA = new TestComponent(); _container.Add(compA, "dup"); // same component, same case _container.InvokeValidateName(compA, "dup"); // existing component, same case TestComponent compB = new TestComponent(); _container.Add(compB, "B"); try { _container.InvokeValidateName(compB, "dup"); Assert.Fail("#A1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A2"); Assert.IsNull(ex.InnerException, "#A3"); Assert.IsNotNull(ex.Message, "#A4"); Assert.IsTrue(ex.Message.IndexOf("'dup'") != -1, "#A5"); Assert.IsNull(ex.ParamName, "#A6"); Assert.AreEqual(2, _container.Components.Count, "#A7"); } _container.InvokeValidateName(compB, "whatever"); // new component, different case TestComponent compC = new TestComponent(); try { _container.InvokeValidateName(compC, "dup"); Assert.Fail("#B1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#B2"); Assert.IsNull(ex.InnerException, "#B3"); Assert.IsNotNull(ex.Message, "#B4"); Assert.IsTrue(ex.Message.IndexOf("'dup'") != -1, "#B5"); Assert.IsNull(ex.ParamName, "#B6"); Assert.AreEqual(2, _container.Components.Count, "#B7"); } _container.InvokeValidateName(compC, "whatever"); // component of other container, different case TestContainer container2 = new TestContainer(); TestComponent compD = new TestComponent(); container2.Add(compD, "B"); try { _container.InvokeValidateName(compD, "dup"); Assert.Fail("#C1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#C2"); Assert.IsNull(ex.InnerException, "#C3"); Assert.IsNotNull(ex.Message, "#C4"); Assert.IsTrue(ex.Message.IndexOf("'dup'") != -1, "#C5"); Assert.IsNull(ex.ParamName, "#C6"); Assert.AreEqual(2, _container.Components.Count, "#C7"); } _container.InvokeValidateName(compD, "whatever"); Assert.AreEqual(1, container2.Components.Count, "#C8"); Assert.AreSame(compD, container2.Components [0], "#C9"); }
[Test] // Dispose () public void Dispose1() { TestComponent compA; TestComponent compB; compA = new TestComponent(); _container.Add(compA); compB = new TestComponent(); _container.Add(compB); _container.Dispose(); Assert.AreEqual(0, _container.Components.Count, "#A1"); Assert.IsTrue(compA.IsDisposed, "#A2"); Assert.IsNull(compA.Site, "#A3"); Assert.IsTrue(compB.IsDisposed, "#A4"); Assert.IsNull(compB.Site, "#A5"); _container = new TestContainer(); compA = new TestComponent(); compA.ThrowOnDispose = true; _container.Add(compA); compB = new TestComponent(); _container.Add(compB); // assert that component is not removed from components until after // Dispose of component has succeeded try { _container.Dispose(); Assert.Fail("#B1"); } catch (InvalidOperationException) { Assert.AreEqual(0, _container.Components.Count, "#B2"); Assert.IsFalse(compA.IsDisposed, "#B4"); Assert.IsNull(compA.Site, "#B5"); Assert.IsTrue(compB.IsDisposed, "#B6"); Assert.IsNull(compB.Site, "#B7"); } finally { compA.ThrowOnDispose = false; } _container = new TestContainer(); compA = new TestComponent(); _container.Add(compA); compB = new TestComponent(); compB.ThrowOnDispose = true; _container.Add(compB); try { _container.Dispose(); Assert.Fail("#C1"); } catch (InvalidOperationException) { Assert.AreEqual(1, _container.Components.Count, "#C2"); Assert.AreSame(compA, _container.Components [0], "#C3"); Assert.IsFalse(compA.IsDisposed, "#C4"); Assert.IsNotNull(compA.Site, "#C5"); Assert.IsFalse(compB.IsDisposed, "#C6"); Assert.IsNull(compB.Site, "#C7"); } finally { compB.ThrowOnDispose = false; } }
public void Add2_Name_Duplicate() { TestContainer container = new TestContainer(); TestComponent c1 = new TestComponent(); container.Add(c1, "dup"); // new component, same case TestComponent c2 = new TestComponent(); try { container.Add(c2, "dup"); Assert.Fail("#A1"); } catch (ArgumentException ex) { // Duplicate component name 'dup'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A2"); Assert.IsNull(ex.InnerException, "#A3"); Assert.IsNotNull(ex.Message, "#A4"); Assert.IsTrue(ex.Message.IndexOf("'dup'") != -1, "#A5"); Assert.IsNull(ex.ParamName, "#A6"); Assert.AreEqual(1, container.Components.Count, "#A7"); } // new component, different case TestComponent c3 = new TestComponent(); try { container.Add(c3, "duP"); Assert.Fail("#B1"); } catch (ArgumentException ex) { // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#B2"); Assert.IsNull(ex.InnerException, "#B3"); Assert.IsNotNull(ex.Message, "#B4"); Assert.IsTrue(ex.Message.IndexOf("'duP'") != -1, "#B5"); Assert.IsNull(ex.ParamName, "#B6"); Assert.AreEqual(1, container.Components.Count, "#B7"); } // existing component, same case TestComponent c4 = new TestComponent(); container.Add(c4, "C4"); Assert.AreEqual(2, container.Components.Count, "#C1"); container.Add(c4, "dup"); Assert.AreEqual(2, container.Components.Count, "#C2"); Assert.AreEqual("C4", c4.Site.Name, "#C3"); // component of other container, same case TestContainer container2 = new TestContainer(); TestComponent c5 = new TestComponent(); container2.Add(c5, "C5"); try { container.Add(c5, "dup"); Assert.Fail("#D1"); } catch (ArgumentException ex) { // Duplicate component name 'dup'. Component names must be // unique and case-insensitive Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#D2"); Assert.IsNull(ex.InnerException, "#D3"); Assert.IsNotNull(ex.Message, "#D4"); Assert.IsTrue(ex.Message.IndexOf("'dup'") != -1, "#D5"); Assert.IsNull(ex.ParamName, "#D6"); Assert.AreEqual(2, container.Components.Count, "#D7"); } Assert.AreEqual(1, container2.Components.Count, "#D8"); Assert.AreSame(c5, container2.Components [0], "#D9"); container.AllowDuplicateNames = true; TestComponent c6 = new TestComponent(); container.Add(c6, "dup"); Assert.AreEqual(3, container.Components.Count, "#E1"); Assert.IsNotNull(c1.Site, "#E2"); Assert.AreEqual("dup", c1.Site.Name, "#E3"); Assert.IsNotNull(c6.Site, "#E4"); Assert.AreEqual("dup", c6.Site.Name, "#E5"); Assert.IsFalse(object.ReferenceEquals(c1.Site, c6.Site), "#E6"); }
[Test] // Add (IComponent, String) public void Add2() { TestContainer containerA = new TestContainer(); TestContainer containerB = new TestContainer(); ISite siteA; ISite siteB; TestComponent compA = new TestComponent(); Assert.IsNull(compA.Site); TestComponent compB = new TestComponent(); Assert.IsNull(compB.Site); Assert.AreEqual(0, containerA.Components.Count); Assert.AreEqual(0, containerB.Components.Count); containerA.Add(compA, "A"); siteA = compA.Site; Assert.IsNotNull(siteA); Assert.AreSame(compA, siteA.Component); Assert.AreSame(containerA, siteA.Container); Assert.IsFalse(siteA.DesignMode); Assert.AreEqual("A", siteA.Name); containerA.Add(compB, "B"); siteB = compB.Site; Assert.IsNotNull(siteB); Assert.AreSame(compB, siteB.Component); Assert.AreSame(containerA, siteB.Container); Assert.IsFalse(siteB.DesignMode); Assert.AreEqual("B", siteB.Name); Assert.IsFalse(object.ReferenceEquals(siteA, siteB)); Assert.AreEqual(2, containerA.Components.Count); Assert.AreEqual(0, containerB.Components.Count); Assert.AreSame(compA, containerA.Components [0]); Assert.AreSame(compB, containerA.Components [1]); // check effect of adding component that is already member of // another container containerB.Add(compA, "A2"); Assert.IsFalse(object.ReferenceEquals(siteA, compA.Site)); siteA = compA.Site; Assert.IsNotNull(siteA); Assert.AreSame(compA, siteA.Component); Assert.AreSame(containerB, siteA.Container); Assert.IsFalse(siteA.DesignMode); Assert.AreEqual("A2", siteA.Name); Assert.AreEqual(1, containerA.Components.Count); Assert.AreEqual(1, containerB.Components.Count); Assert.AreSame(compB, containerA.Components [0]); Assert.AreSame(compA, containerB.Components [0]); // check effect of add component twice to same container containerB.Add(compA, "A2"); Assert.AreSame(siteA, compA.Site); Assert.AreEqual("A2", siteA.Name); Assert.AreEqual(1, containerA.Components.Count); Assert.AreEqual(1, containerB.Components.Count); Assert.AreSame(compB, containerA.Components [0]); Assert.AreSame(compA, containerB.Components [0]); // add again with different name containerB.Add(compA, "A3"); Assert.AreSame(siteA, compA.Site); Assert.AreEqual("A2", siteA.Name); Assert.AreEqual(1, containerA.Components.Count); Assert.AreEqual(1, containerB.Components.Count); Assert.AreSame(compB, containerA.Components [0]); Assert.AreSame(compA, containerB.Components [0]); // check effect of add component twice to same container containerB.Add(compA, "A2"); Assert.AreSame(siteA, compA.Site); Assert.AreEqual("A2", siteA.Name); }
public void Init() { _container = new TestContainer(); }