public void CreatingTwoObjectsOfDifferentTypesButTheSameNameThrows()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            collection.AddNew(typeof(object), "One");
            collection.AddNew(typeof(int), "One");
        }
        public void EnumerationDoesNotReturnReplacedObjects()
        {
            TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(SearchMode.Up);
            TestableManagedObjectCollection <object> childCollection  = new TestableManagedObjectCollection <object>(parentCollection);

            object obj1 = parentCollection.AddNew <object>("Foo");
            object obj2 = childCollection.AddNew <object>("Foo");

            bool o1Found = false;
            bool o2Found = false;

            foreach (KeyValuePair <string, object> pair in childCollection)
            {
                if (pair.Value == obj1)
                {
                    o1Found = true;
                }
                if (pair.Value == obj2)
                {
                    o2Found = true;
                }
            }

            Assert.IsFalse(o1Found);
            Assert.IsTrue(o2Found);
        }
        public void AddingTwoDifferentObjectsWithSameNameThrows()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            collection.Add(new object(), "Foo");
            collection.Add("Bar", "Foo");
        }
        public void EnumerationFiltersReturnedCollectionWithPredicate()
        {
            Predicate <object> filter = delegate(object obj)
            {
                return(obj is MockDataObject);
            };

            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(SearchMode.Local, null, filter);

            object         o1 = collection.AddNew <object>("One");
            MockDataObject o2 = collection.AddNew <MockDataObject>("Two");

            bool o1Found = false;
            bool o2Found = false;

            foreach (KeyValuePair <string, object> pair in collection)
            {
                if (pair.Value.Equals(o1))
                {
                    o1Found = true;
                }
                if (pair.Value.Equals(o2))
                {
                    o2Found = true;
                }
            }

            Assert.IsFalse(o1Found);
            Assert.IsTrue(o2Found);
        }
        public void CreatingTwoObjectsOfDifferentTypesButTheSameNameThrows_Generic()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            collection.AddNew <object>("One");
            collection.AddNew <int>("One");
        }
        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 AddingSameObjectWithSameNameThrows()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = new object();

            collection.Add(obj, "Foo");
            collection.Add(obj, "Foo");
        }
        public void CanAddNamedObjectAndIndexItByName()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew <object>("foo");

            Assert.AreSame(obj, collection["foo"]);
        }
        public void IndexerCreatesWhenFlagSetToCreateAndItemDoesNotExist()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(SearchMode.Local, delegate { return(new object()); });

            object foo = collection["Foo"];

            Assert.IsNotNull(foo);
        }
        public void CanAddNamedObjectAndFindItByName_Generic()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew <object>("foo");

            Assert.AreSame(obj, collection.Get <object>("foo"));
        }
        public void AddedItemCanBeLocatedByTypeIDPair()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew <object>("Foo");

            Assert.AreSame(obj, collection.Locator.Get(new DependencyResolutionLocatorKey(typeof(object), "Foo")));
        }
        public void AddNewOnlyCallsBuilderOnce()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            BuilderAwareObject obj = (BuilderAwareObject)collection.AddNew(typeof(BuilderAwareObject));

            Assert.AreEqual(1, obj.BuilderRunCount);
        }
        public void AddNewNamedWillCreateANewObjectAndGiveItToMe()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew(typeof(object), "Foo");

            Assert.IsNotNull(obj);
        }
        public void AddNewOnlyCallsBuilderOnce_Generic()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            BuilderAwareObject obj = collection.AddNew <BuilderAwareObject>();

            Assert.AreEqual(1, obj.BuilderRunCount);
        }
        public void AddNewWillCreateANewObjectAndGiveItToMe_Generic()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew <object>();

            Assert.IsNotNull(obj);
        }
        public void CanFindOutIfCollectionContainsObject()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = new object();

            collection.Add(obj, "Foo");

            Assert.IsTrue(collection.ContainsObject(obj));
        }
        public void AddNewAddsToLocatorAndLifetimeContainer()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            object obj = collection.AddNew(typeof(object), "Foo");

            Assert.IsTrue(collection.LifetimeContainer.Contains(obj));
            Assert.AreEqual(obj, collection.Get("Foo"));
        }
        public void RemovingItemRemovesTypeIdPairFromLocator()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = collection.AddNew <object>("Foo");

            collection.Remove(obj);

            Assert.IsNull(collection.Locator.Get(new DependencyResolutionLocatorKey(typeof(object), "Foo")));
        }
        public void AddedObjectStoredInProvidedContainer()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = new object();

            collection.Add(obj);

            Assert.IsTrue(collection.LifetimeContainer.Contains(obj));
        }
        public void CreatedIndexerItemIsRetrievedForSecondIndex()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection(SearchMode.Local, delegate { return(new object()); });

            object foo  = collection["Foo"];
            object foo2 = collection["Foo"];

            Assert.AreSame(foo, foo2);
        }
        public void AddingObjectRunsTheBuilder()
        {
            BuilderAwareObject obj = new BuilderAwareObject();
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

            collection.Add(obj);

            Assert.IsTrue(obj.BuilderWasRun);
        }
        public void GetCanSearchUpTheLocatorChain()
        {
            TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(SearchMode.Up);
            TestableManagedObjectCollection <object> childCollection  = new TestableManagedObjectCollection <object>(parentCollection);

            object obj = parentCollection.AddNew <object>("Foo");

            Assert.AreSame(obj, childCollection.Get("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 AddingUnnamedObjectTwiceYieldsSingleObjectInContainer()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = new object();

            collection.Add(obj);
            collection.Add(obj);

            Assert.AreEqual(1, collection.LifetimeContainer.Count);
        }
        public void FindByTypeSearchesParentContainerWhenConfiguredForSearchUp()
        {
            TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection();
            ManagedObjectCollection <object>         childCollection  =
                new ManagedObjectCollection <object>(new LifetimeContainer(), new Locator(parentCollection.Locator), parentCollection.Builder, SearchMode.Up, null, null, parentCollection);

            parentCollection.AddNew <object>();

            Assert.AreEqual(1, childCollection.FindByType(typeof(object)).Count);
        }
        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 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 GetDoesNotReturnReplacedObject()
        {
            TestableManagedObjectCollection <object> parentCollection = CreateManagedObjectCollection(SearchMode.Up);
            TestableManagedObjectCollection <object> childCollection  = new TestableManagedObjectCollection <object>(parentCollection);

            object obj1 = parentCollection.AddNew <object>("Foo");
            object obj2 = childCollection.AddNew <object>("Foo");

            Assert.AreSame(obj2, childCollection.Get("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 RemoveRemovesFromLocator()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            object obj = new object();

            collection.Add(obj, "Foo");
            collection.Remove(obj);

            Assert.IsFalse(collection.Locator.Contains("Foo"));
        }