public void ConvertFrom() { ReferenceConverter converter = new ReferenceConverter(typeof(ITestInterface)); string referenceName = "reference name"; // no context Assert.IsNull(converter.ConvertFrom(null, null, referenceName), "#1"); TestComponent component = new TestComponent(); // context with IReferenceService TestReferenceService referenceService = new TestReferenceService(); referenceService.AddReference(referenceName, component); TestTypeDescriptorContext context = new TestTypeDescriptorContext(referenceService); Assert.AreSame(component, converter.ConvertFrom(context, null, referenceName), "#2"); // context with Component without IReferenceService Container container = new Container(); container.Add(component, referenceName); context = new TestTypeDescriptorContext(); context.Container = container; Assert.AreSame(component, converter.ConvertFrom(context, null, referenceName), "#3"); }
public void ConvertTo() { ReferenceConverter converter = new ReferenceConverter(typeof(ITestInterface)); string referenceName = "reference name"; Assert.AreEqual("(none)", (string)converter.ConvertTo(null, null, null, typeof(string)), "#1"); TestComponent component = new TestComponent(); // no context Assert.AreEqual(String.Empty, (string)converter.ConvertTo(null, null, component, typeof(string)), "#2"); // context with IReferenceService TestReferenceService referenceService = new TestReferenceService(); referenceService.AddReference(referenceName, component); TestTypeDescriptorContext context = new TestTypeDescriptorContext(referenceService); Assert.AreEqual(referenceName, (string)converter.ConvertTo(context, null, component, typeof(string)), "#3"); // context with Component without IReferenceService Container container = new Container(); container.Add(component, referenceName); context = new TestTypeDescriptorContext(); context.Container = container; Assert.AreEqual(referenceName, (string)converter.ConvertTo(context, null, component, typeof(string)), "#4"); }
public override IEnumerable <ConvertTest> ConvertToTestData() { var component = new TestComponent(); // No Context. yield return(ConvertTest.Valid(null, "(none)").WithInvariantRemoteInvokeCulture());; yield return(ConvertTest.Valid(null, "(none)").WithContext(null).WithInvariantRemoteInvokeCulture());; yield return(ConvertTest.Valid(string.Empty, string.Empty).WithContext(null)); // IReferenceCollection. var referenceService = new TestReferenceService(); referenceService.AddReference("reference name", component); var contextWithReferenceService = new TestTypeDescriptorContext(referenceService); yield return(ConvertTest.Valid(component, "reference name").WithContext(contextWithReferenceService)); yield return(ConvertTest.Valid(new Component(), string.Empty).WithContext(contextWithReferenceService)); // IContainer. var container = new Container(); container.Add(component, "reference name"); var contextWithContainer = new TestTypeDescriptorContext { Container = container }; yield return(ConvertTest.Valid(component, "reference name").WithContext(contextWithContainer)); yield return(ConvertTest.Valid(new Component(), string.Empty).WithContext(contextWithContainer)); yield return(ConvertTest.CantConvertTo(1, typeof(int))); }
public void ConvertTo() { RemoteInvoke(() => { CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; ReferenceConverter remoteConverter = new ReferenceConverter(typeof(ITestInterface)); Assert.Equal("(none)", (string)remoteConverter.ConvertTo(null, null, null, typeof(string))); }).Dispose(); ReferenceConverter converter = new ReferenceConverter(typeof(ITestInterface)); string referenceName = "reference name"; TestComponent component = new TestComponent(); // no context Assert.Equal(String.Empty, (string)converter.ConvertTo(null, null, component, typeof(string))); // context with IReferenceService TestReferenceService referenceService = new TestReferenceService(); referenceService.AddReference(referenceName, component); TestTypeDescriptorContext context = new TestTypeDescriptorContext(referenceService); Assert.Equal(referenceName, (string)converter.ConvertTo(context, null, component, typeof(string))); // context with Component without IReferenceService Container container = new Container(); container.Add(component, referenceName); context = new TestTypeDescriptorContext(); context.Container = container; Assert.Equal(referenceName, (string)converter.ConvertTo(context, null, component, typeof(string))); }
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 override IEnumerable <ConvertTest> ConvertFromTestData() { // This does actually succeed despite CanConvertFrom returning false. ConvertTest noContext = ConvertTest.Valid("reference name", null).WithContext(null); noContext.CanConvert = false; yield return(noContext); // No IReferenceService or IContainer. yield return(ConvertTest.Valid("", null)); yield return(ConvertTest.Valid(" ", null)); yield return(ConvertTest.Valid("(none)", null).WithInvariantRemoteInvokeCulture()); yield return(ConvertTest.Valid("nothing", null)); // IReferenceService. var component = new TestComponent(); var referenceService = new TestReferenceService(); referenceService.AddReference("reference name", component); var contextWithReferenceCollection = new TestTypeDescriptorContext(referenceService); yield return(ConvertTest.Valid("reference name", component).WithContext(contextWithReferenceCollection)); yield return(ConvertTest.Valid("no such reference", null).WithContext(contextWithReferenceCollection)); // IContainer. var container = new Container(); container.Add(component, "reference name"); var contextWithContainer = new TestTypeDescriptorContext { Container = container }; yield return(ConvertTest.Valid("reference name", component).WithContext(contextWithContainer)); yield return(ConvertTest.Valid("no such reference", null).WithContext(contextWithContainer)); yield return(ConvertTest.CantConvertFrom(1)); yield return(ConvertTest.CantConvertFrom(new object())); }
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 ConvertTo () { ReferenceConverter converter = new ReferenceConverter (typeof(ITestInterface)); string referenceName = "reference name"; Assert.AreEqual ("(none)", (string)converter.ConvertTo (null, null, null, typeof(string)), "#1"); TestComponent component = new TestComponent(); // no context Assert.AreEqual (String.Empty, (string)converter.ConvertTo (null, null, component, typeof(string)), "#2"); // context with IReferenceService TestReferenceService referenceService = new TestReferenceService (); referenceService.AddReference (referenceName, component); TestTypeDescriptorContext context = new TestTypeDescriptorContext (referenceService); Assert.AreEqual (referenceName, (string)converter.ConvertTo (context, null, component, typeof(string)), "#3"); // context with Component without IReferenceService Container container = new Container (); container.Add (component, referenceName); context = new TestTypeDescriptorContext (); context.Container = container; Assert.AreEqual (referenceName, (string)converter.ConvertTo (context, null, component, typeof(string)), "#4"); }
public void ConvertFrom () { ReferenceConverter converter = new ReferenceConverter (typeof(ITestInterface)); string referenceName = "reference name"; // no context Assert.IsNull (converter.ConvertFrom (null, null, referenceName), "#1"); TestComponent component = new TestComponent(); // context with IReferenceService TestReferenceService referenceService = new TestReferenceService (); referenceService.AddReference (referenceName, component); TestTypeDescriptorContext context = new TestTypeDescriptorContext (referenceService); Assert.AreSame (component, converter.ConvertFrom (context, null, referenceName), "#2"); // context with Component without IReferenceService Container container = new Container (); container.Add (component, referenceName); context = new TestTypeDescriptorContext (); context.Container = container; Assert.AreSame (component, converter.ConvertFrom (context, null, referenceName), "#3"); }