public void GetStandardValues_IContainerNoValuesAllowed_ReturnsEmpty()
        {
            var component1 = new Component();
            var component2 = new TestComponent();
            var component3 = new TestComponent();

            var container = new Container();

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

            var converter = new SubReferenceConverter(typeof(TestComponent));
            var context   = new MockTypeDescriptorContext {
                Container = container
            };

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

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

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

            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>());
            Assert.Equal(new object[] { component2, component3 }, converter.DisallowedValues);

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

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

            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[] { null }, values.Cast <object>());
            Assert.Equal(new object[] { component2, component3 }, converter.Values);
        }
        public void GetStandardValues_IContainerNoValuesAllowed_ReturnsEmpty()
        {
            var component1 = new Component();
            var component2 = new TestComponent();
            var component3 = new TestComponent();

            var container = new Container();

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

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

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