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 CanCreateService_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();

            MockDataObject svc = services.AddNew <MockDataObject>();

            Assert.IsNotNull(svc);
            Assert.AreSame(svc, services.Get <MockDataObject>());
        }
        public void CanAskForBuilderToEnsureServiceExists()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject            svc      = new MockDataObject();

            services.Add(typeof(MockDataObject), svc);
            MockDataObject result = (MockDataObject)services.Get(typeof(MockDataObject), true);

            Assert.AreSame(svc, result);
        }
        public void AddingServiceToContainerAllowsRetrievalOfService()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject            svc      = new MockDataObject();

            services.Add(typeof(MockDataObject), svc);
            MockDataObject result = (MockDataObject)services.Get(typeof(MockDataObject));

            Assert.AreSame(svc, result);
        }
Ejemplo n.º 5
0
        public void AddingServiceToWorkItemAllowsRetrievalOfService_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject            svc      = new MockDataObject();

            services.Add(typeof(MockDataObject), svc);
            MockDataObject result = services.Get <MockDataObject>();

            Assert.AreSame(svc, result);
        }
        public void CanCreateServiceInChildWhenServiceExistsInParent_Generic()
        {
            TestableServiceCollection services      = CreateServiceCollection();
            TestableServiceCollection childServices = new TestableServiceCollection(services);

            MockDataObject parentService = services.AddNew <MockDataObject>();
            MockDataObject childService  = childServices.AddNew <MockDataObject>();

            Assert.AreSame(parentService, services.Get <MockDataObject>());
            Assert.AreSame(childService, childServices.Get <MockDataObject>());
        }
        private void RemovingMultipleRegisteredServiceOnlyRemovesStrongReferenceWhenLastInstanceIsGone_Generic_TestHelper2(out TestableServiceCollection services, out WeakReference wr)
        {
            services = CreateServiceCollection();
            MockDataObject mdo = new MockDataObject();

            wr = new WeakReference(mdo);
            services.Add <IMockDataObject>(mdo);
            services.Add <IMockDataObject2>(mdo);
            mdo = null;

            services.Remove <IMockDataObject>();
        }
        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 RemovingMultipleRegisteredServiceOnlyRemovesStrongReferenceWhenLastInstanceIsGone_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject            mdo      = new MockDataObject();
            WeakReference             wr       = new WeakReference(mdo);

            services.Add <IMockDataObject>(mdo);
            services.Add <IMockDataObject2>(mdo);
            mdo = null;

            services.Remove <IMockDataObject>();
            GC.Collect();
            Assert.IsNotNull(wr.Target);

            services.Remove <IMockDataObject2>();
            GC.Collect();
            Assert.IsNull(wr.Target);
        }
        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);
        }
Ejemplo n.º 11
0
        public void RemovingMultipleRegisteredServiceOnlyRemovesStrongReferenceWhenLastInstanceIsGone_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            var wRefwr = CallInItsOwnScope(() =>
            {
                MockDataObject mdo = new MockDataObject();
                WeakReference wr   = new WeakReference(mdo);
                services.Add <IMockDataObject>(mdo);
                services.Add <IMockDataObject2>(mdo);
                mdo = null;
                return(wr);
            });


            services.Remove <IMockDataObject>();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Assert.IsNotNull(wRefwr.Target);

            services.Remove <IMockDataObject2>();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Assert.IsNull(wRefwr.Target);
        }
        public void RemovingMultipleRegisteredServiceOnlyRemovesStrongReferenceWhenLastInstanceIsGone_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject mdo = new MockDataObject();
            WeakReference wr = new WeakReference(mdo);
            services.Add<IMockDataObject>(mdo);
            services.Add<IMockDataObject2>(mdo);
            mdo = null;

            services.Remove<IMockDataObject>();
            GC.Collect();
            Assert.IsNotNull(wr.Target);

            services.Remove<IMockDataObject2>();
            GC.Collect();
            Assert.IsNull(wr.Target);
        }
        public void CanAskForBuilderToEnsureServiceExists_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject svc = new MockDataObject();

            services.Add(typeof (MockDataObject), svc);
            MockDataObject result = services.Get<MockDataObject>(true);

            Assert.AreSame(svc, result);
        }
        public void AddingServiceToContainerAllowsRetrievalOfService_Generic()
        {
            TestableServiceCollection services = CreateServiceCollection();
            MockDataObject svc = new MockDataObject();

            services.Add(typeof (MockDataObject), svc);
            MockDataObject result = services.Get<MockDataObject>();

            Assert.AreSame(svc, result);
        }