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

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

            collection.AddNew(typeof(object), "One");
            collection.AddNew(typeof(int), "One");
        }
        public void RemovingNamedObjectCausesNameToBeAvailableAgain()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

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

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

            Assert.IsNotNull(obj2);
            Assert.IsTrue(obj != obj2);
        }
        public void IndexFiltersReturnedCollectionWithPredicate()
        {
            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");

            Assert.IsNull(collection["One"]);
            Assert.AreSame(o2, collection["Two"]);
        }
        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 CanAddNamedObjectAndIndexItByName()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();

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

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

            parentCollection.AddNew <object>();

            Assert.AreEqual(1, parentCollection.Count);
            Assert.AreEqual(0, childCollection.Count);
        }
        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 FilteredObjectWillNotBeReplacedByCreateNewIndexerBehavior()
        {
            Predicate <object> filter = delegate(object obj) { return(obj is MockDataObject); };

            TestableManagedObjectCollection <object> collection =
                CreateManagedObjectCollection(SearchMode.Local, delegate { return(new object()); }, filter);

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

            Assert.IsNull(collection["One"]);
        }
        public void RemovingObjectCausesItToBeTornDown()
        {
            TestableManagedObjectCollection <object> collection = CreateManagedObjectCollection();
            MockTearDownStrategy strategy = new MockTearDownStrategy();

            collection.Builder.Strategies.Add(strategy, BuilderStage.PreCreation);

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

            collection.Remove(obj);

            Assert.IsTrue(strategy.TearDownCalled);
        }