public void AttachToMultipleObjectsNotAllowed() { var obj1 = new MockObjectWithComponents(); var obj2 = new MockObjectWithComponents(); var comp = new MockParentAwareComponentBase(); obj1.GoRogueComponents.Add(comp); comp.ClearHistory(); Assert.Throws <ArgumentException>(() => obj2.GoRogueComponents.Add(comp)); Assert.Same(obj1, comp.Parent); Assert.Equal(0, comp.TimesAddedCalled); Assert.Equal(0, comp.TimesRemovedCalled); }
public void AddedAndRemovedFire() { var obj = new MockObjectWithComponents(); var comp = new MockParentAwareComponentBase(); // Added (and only added) should fire when component is added to an object obj.GoRogueComponents.Add(comp); Assert.Equal(1, comp.TimesAddedCalled); Assert.Equal(0, comp.TimesRemovedCalled); // When removed, ONLY removed should fire comp.ClearHistory(); obj.GoRogueComponents.Remove(comp); Assert.Equal(0, comp.TimesAddedCalled); Assert.Equal(1, comp.TimesRemovedCalled); }