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_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_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_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); }
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 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); }