public void GetStandardValues_IReferenceServiceNullType_ReturnsExpected()
        {
            var converter = new ReferenceConverter(null);

            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var referenceService = new MockReferenceService();

            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            referenceService.AddReference("reference name 3", component3);

            int callCount = 0;
            var context   = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    callCount++;
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(referenceService);
                }
            };

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(1, callCount);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.Equal(2, callCount);
            Assert.NotSame(values1, values2);
        }
        public void GetStandardValues_NoReferenceCollectionOrIContainer_ReturnsEmpty()
        {
            var converter = new ReferenceConverter(typeof(TestComponent));
            var context   = new MockTypeDescriptorContext();

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.NotSame(values1, values2);
        }
Esempio n. 3
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList arrayList = new ArrayList();
            StandardValuesCollection standardValues           = base.GetStandardValues(context);
            StandardValuesCollection standardValuesCollection = null;

            this.FillList(arrayList, standardValues);
            ReferenceConverter referenceConverter = null;

            referenceConverter       = new ReferenceConverter(typeof(IListSource));
            standardValuesCollection = referenceConverter.GetStandardValues(context);
            this.FillList(arrayList, standardValuesCollection);
            referenceConverter       = new ReferenceConverter(typeof(DataView));
            standardValuesCollection = referenceConverter.GetStandardValues(context);
            this.FillList(arrayList, standardValuesCollection);
            referenceConverter       = new ReferenceConverter(typeof(IDbDataAdapter));
            standardValuesCollection = referenceConverter.GetStandardValues(context);
            this.FillList(arrayList, standardValuesCollection);
            referenceConverter       = new ReferenceConverter(typeof(IDataReader));
            standardValuesCollection = referenceConverter.GetStandardValues(context);
            this.FillList(arrayList, standardValuesCollection);
            referenceConverter       = new ReferenceConverter(typeof(IDbCommand));
            standardValuesCollection = referenceConverter.GetStandardValues(context);
            this.FillList(arrayList, standardValuesCollection);
            arrayList.Add(null);
            return(new StandardValuesCollection(arrayList));
        }
        public void GetStandardValues_NoReferenceCollectionOrIContainer_ReturnsEmpty()
        {
            var converter = new ReferenceConverter(typeof(TestComponent));
            var context   = new TestTypeDescriptorContext();

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.Equal(new object[] { null }, values.Cast <object>());
        }
        public void GetStandardValues_IReferenceServiceInvalid_ReturnsExpected(object referenceService)
        {
            var converter = new ReferenceConverter(typeof(TestComponent));
            int callCount = 0;
            var context   = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    callCount++;
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(referenceService);
                }
            };

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(1, callCount);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.Equal(2, callCount);
            Assert.NotSame(values1, values2);
        }
        public void GetStandardValues_IContainerNullType_ReturnsExpected()
        {
            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var container = new Container();

            container.Add(component1);
            container.Add(component2);
            container.Add(component3);

            var converter = new ReferenceConverter(null);
            var context   = new MockTypeDescriptorContext {
                Container = container
            };

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.NotSame(values1, values2);
        }
        public void GetStandardValues()
        {
            ReferenceConverter converter = new ReferenceConverter(typeof(TestComponent));

            TestComponent        component1       = new TestComponent();
            TestComponent        component2       = new TestComponent();
            TestReferenceService referenceService = new TestReferenceService();

            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            ITypeDescriptorContext context = new TestTypeDescriptorContext(referenceService);

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.IsNotNull(values, "#1");
            // 2 components + 1 null value
            Assert.AreEqual(3, values.Count, "#2");
        }
        public void GetStandardValues_IReferenceService_ReturnsExpected()
        {
            var converter = new ReferenceConverter(typeof(TestComponent));

            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var referenceService = new TestReferenceService();

            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            referenceService.AddReference("reference name 3", component3);

            var context = new TestTypeDescriptorContext(referenceService);

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.Equal(new object[] { component1, component2, null }, values.Cast <object>());
        }
        public void GetStandardValues_IContainer_ReturnsExpected()
        {
            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var container = new Container();

            container.Add(component1);
            container.Add(component2);
            container.Add(component3);

            var converter = new ReferenceConverter(typeof(TestComponent));
            var context   = new TestTypeDescriptorContext {
                Container = container
            };

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.Equal(new object[] { component1, component2, null }, values.Cast <object>());
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            StandardValuesCollection listSources = base.GetStandardValues(context);
            StandardValuesCollection lists       = listConverter.GetStandardValues(context);

            ArrayList listsList = new ArrayList();

            foreach (object listSource in listSources)
            {
                if (listSource != null)
                {
                    // bug 46563: work around the TableMappings property on the OleDbDataAdapter
                    ListBindableAttribute listBindable = (ListBindableAttribute)TypeDescriptor.GetAttributes(listSource)[typeof(ListBindableAttribute)];
                    if (listBindable != null && !listBindable.ListBindable)
                    {
                        continue;
                    }
                    listsList.Add(listSource);
                }
            }
            foreach (object list in lists)
            {
                if (list != null)
                {
                    // bug 46563: work around the TableMappings property on the OleDbDataAdapter
                    ListBindableAttribute listBindable = (ListBindableAttribute)TypeDescriptor.GetAttributes(list)[typeof(ListBindableAttribute)];
                    if (listBindable != null && !listBindable.ListBindable)
                    {
                        continue;
                    }
                    listsList.Add(list);
                }
            }
            // bug 71417: add a null list to reset the dataSource
            listsList.Add(null);

            return(new StandardValuesCollection(listsList));
        }
        public void GetStandardValues_NullContext_ReturnsEmpty()
        {
            var converter = new ReferenceConverter(typeof(TestComponent));

            Assert.Empty(converter.GetStandardValues(null));
        }
Esempio n. 12
0
        public void GetStandardValues()
        {
            ReferenceConverter converter = new ReferenceConverter(typeof(TestComponent));

            TestComponent component1 = new TestComponent();
            TestComponent component2 = new TestComponent();
            TestReferenceService referenceService = new TestReferenceService();
            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            ITypeDescriptorContext context = new TestTypeDescriptorContext(referenceService);

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.NotNull(values);
            // 2 components + 1 null value
            Assert.Equal(3, values.Count);
        }