public void CanEnumerateCollection() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj1 = new object(); object obj2 = new object(); collection.Add(obj1); collection.Add(obj2); bool o1Found = false; bool o2Found = false; foreach (KeyValuePair <string, object> pair in collection) { if (pair.Value == obj1) { o1Found = true; } if (pair.Value == obj2) { o2Found = true; } } Assert.IsTrue(o1Found); Assert.IsTrue(o2Found); }
public void AddingTwoDifferentObjectsWithSameNameThrows() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add(new object(), "Foo"); collection.Add("Bar", "Foo"); }
public void AddingSameObjectWithSameNameThrows() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj, "Foo"); collection.Add(obj, "Foo"); }
public void CountReflectsNumberOfRegistrations() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj, "Foo"); collection.Add(obj, "Bar"); Assert.AreEqual(2, collection.Count); }
public void AddingUnnamedObjectTwiceYieldsSingleObjectInContainer() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj); collection.Add(obj); Assert.AreEqual(1, collection.LifetimeContainer.Count); }
public void CanAddSameObjectWithManyNames() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj, "Foo"); collection.Add(obj, "Bar"); Assert.AreEqual(1, collection.LifetimeContainer.Count); Assert.AreSame(obj, collection.Get("Foo")); Assert.AreSame(obj, collection.Get("Bar")); }
public void CouldIgnoresObjectsOfTheWrongType() { TestableManagedObjectCollection <object> objectCollection = CreateManagedObjectCollection(); TestableManagedObjectCollection <string> stringCollection = new TestableManagedObjectCollection <string>(objectCollection.LifetimeContainer, objectCollection.Locator, objectCollection.Builder, objectCollection.SearchMode, null, null, null); object obj1 = new object(); object obj2 = new object(); string obj3 = "Hello there!"; objectCollection.Add(obj1); objectCollection.Add(obj2); objectCollection.Add(obj3); Assert.AreEqual(3, objectCollection.Count); Assert.AreEqual(1, stringCollection.Count); }
public void AddedObjectStoredInProvidedContainer() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj); Assert.IsTrue(collection.LifetimeContainer.Contains(obj)); }
public void CanFindOutIfCollectionContainsObject() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj, "Foo"); Assert.IsTrue(collection.ContainsObject(obj)); }
public void AddingObjectRunsTheBuilder() { BuilderAwareObject obj = new BuilderAwareObject(); TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add(obj); Assert.IsTrue(obj.BuilderWasRun); }
public void CanFindObjectsByAssignableType_Generic() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add("Hello world"); Assert.AreEqual(1, collection.FindByType <string>().Count); Assert.AreEqual(1, collection.FindByType <object>().Count); Assert.AreEqual(0, collection.FindByType <int>().Count); }
public void ContainsDoesNotCheckParent() { TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(); TestableManagedObjectCollection <object> childCollection = new TestableManagedObjectCollection <object>(parentCollection); object obj = new object(); parentCollection.Add(obj, "Foo"); Assert.IsFalse(childCollection.Contains("Foo")); }
public void GetDoesNotCheckParentCollection_Generic() { TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(); TestableManagedObjectCollection <object> childCollection = new TestableManagedObjectCollection <object>(parentCollection); object obj = new object(); parentCollection.Add(obj, "Foo"); Assert.IsNull(childCollection.Get <object>("Foo")); }
public void CanFindObjectsByAssignableType() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add("Hello world"); Assert.AreEqual(1, collection.FindByType(typeof(string)).Count); Assert.AreEqual(1, collection.FindByType(typeof(object)).Count); Assert.AreEqual(0, collection.FindByType(typeof(int)).Count); }
public void RemoveRemovesFromLocator() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj, "Foo"); collection.Remove(obj); Assert.IsFalse(collection.Locator.Contains("Foo")); }
public void RemoveRemovesFromLifetimeContainer() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj = new object(); collection.Add(obj); collection.Remove(obj); Assert.IsFalse(collection.LifetimeContainer.Contains(obj)); }
public void IndexerDoesNotCheckParentCollection() { TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(); TestableManagedObjectCollection <object> childCollection = new TestableManagedObjectCollection <object>(parentCollection); object obj = new object(); parentCollection.Add(obj, "Foo"); Assert.IsNull(childCollection["Foo"]); }
public void AddedObjectIsAddedToLocator() { object obj = new object(); TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add(obj); IReadableLocator locator = collection.Locator.FindBy(delegate(KeyValuePair <object, object> pair) { return(pair.Value == obj); }); Assert.AreEqual(1, locator.Count); }
public void EnumeratorIgnoresItemsOfTheWrongTypeInTheLocator() { TestableManagedObjectCollection <object> objectCollection = CreateManagedObjectCollection(); TestableManagedObjectCollection <string> stringCollection = new TestableManagedObjectCollection <string>(objectCollection.LifetimeContainer, objectCollection.Locator, objectCollection.Builder, objectCollection.SearchMode, null, null, null); object obj1 = new object(); object obj2 = new object(); string obj3 = "Hello there!"; objectCollection.Add(obj1); objectCollection.Add(obj2); objectCollection.Add(obj3); bool o1Found = false; bool o2Found = false; bool o3Found = false; foreach (KeyValuePair <string, string> pair in stringCollection) { if (ReferenceEquals(pair.Value, obj1)) { o1Found = true; } if (ReferenceEquals(pair.Value, obj2)) { o2Found = true; } if (ReferenceEquals(pair.Value, obj3)) { o3Found = true; } } Assert.IsFalse(o1Found); Assert.IsFalse(o2Found); Assert.IsTrue(o3Found); }
public void AddingObjectTwiceOnlyInjectsDependenciesOnce() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); MockDataObject obj = new MockDataObject(); PropertySetterPolicy policy1 = new PropertySetterPolicy(); policy1.Properties.Add("IntProperty", new PropertySetterInfo("IntProperty", new ValueParameter <int>(19))); collection.Builder.Policies.Set <IPropertySetterPolicy>(policy1, typeof(MockDataObject), "Foo"); PropertySetterPolicy policy2 = new PropertySetterPolicy(); policy2.Properties.Add("IntProperty", new PropertySetterInfo("IntProperty", new ValueParameter <int>(36))); collection.Builder.Policies.Set <IPropertySetterPolicy>(policy2, typeof(MockDataObject), "Bar"); collection.Add(obj, "Foo"); Assert.AreEqual(19, obj.IntProperty); collection.Add(obj, "Bar"); Assert.AreEqual(19, obj.IntProperty); }
public void EnumeratorIgnoresItemsAddedDirectlyToLocator() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); object obj1 = new object(); object obj2 = new object(); object obj3 = new object(); collection.Add(obj1); collection.Add(obj2); collection.Locator.Add("Foo", obj3); bool o3Found = false; foreach (KeyValuePair <string, object> pair in collection) { if (pair.Value == obj3) { o3Found = true; } } Assert.IsFalse(o3Found); }
public void AddingNullObjectThrows() { TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(); collection.Add(null); }