public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid(string.Empty, CultureInfo.InvariantCulture, CultureInfo.InvariantCulture));

            yield return(ConvertTest.Valid("nl-BE", new CultureInfo("nl-BE"), CultureInfo.InvariantCulture));

            yield return(ConvertTest.Valid("(Default)", CultureInfo.InvariantCulture, CultureInfo.InvariantCulture));

            CultureInfo culture = null;

            try
            {
                culture = new CultureInfo("nl--B");
            }
            catch { }

            if (culture != null)
            {
                yield return(ConvertTest.Valid("nl-B", new CultureInfo("nl--B"), CultureInfo.InvariantCulture));

                yield return(ConvertTest.Valid("nl-B", new CultureInfo("nl--B"), new CultureInfo("en-US")));
            }
            if (PlatformDetection.IsNotBrowser)
            {
                yield return(ConvertTest.Valid("Afrikaans", new CultureInfo("af")));
            }

            yield return(ConvertTest.CantConvertFrom(CultureInfo.CurrentCulture));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }
Example #2
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid("string", "string"));

            yield return(ConvertTest.Valid(string.Empty, string.Empty));

            yield return(ConvertTest.Valid(null, string.Empty));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }
Example #3
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid("false  ", false));

            yield return(ConvertTest.Valid("true", true, CultureInfo.InvariantCulture));

            yield return(ConvertTest.Throws <FormatException>("1"));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(null));
        }
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid("  a  ", 'a'));

            yield return(ConvertTest.Valid("    ", '\0'));

            yield return(ConvertTest.Valid("", '\0'));

            yield return(ConvertTest.Throws <FormatException>("aa"));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(null));
        }
Example #5
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid(" {30da92c0-23e8-42a0-ae7c-734a0e5d2782}", new Guid(0x30da92c0, 0x23e8, 0x42a0, 0xae, 0x7c, 0x73, 0x4a, 0x0e, 0x5d, 0x27, 0x82)));

            yield return(ConvertTest.Valid("{30da92c0-23e8-42a0-ae7c-734a0e5d2782}", new Guid(0x30da92c0, 0x23e8, 0x42a0, 0xae, 0x7c, 0x73, 0x4a, 0x0e, 0x5d, 0x27, 0x82)));

            yield return(ConvertTest.Valid(" \t\r\n {30da92c0-23e8-42a0-ae7c-734a0e5d2782} \t\r\n ", new Guid(0x30da92c0, 0x23e8, 0x42a0, 0xae, 0x7c, 0x73, 0x4a, 0x0e, 0x5d, 0x27, 0x82)));

            yield return(ConvertTest.Throws <FormatException>(""));

            yield return(ConvertTest.Throws <FormatException>("invalid"));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid("  1000.00:00:00  ", new TimeSpan(1000, 0, 0, 0, 0), CultureInfo.InvariantCulture));

            yield return(ConvertTest.Valid("1000", new TimeSpan(1000, 0, 0, 0, 0)));

            yield return(ConvertTest.Throws <FormatException>("invalid"));

            yield return(ConvertTest.Throws <FormatException>("  "));

            yield return(ConvertTest.Throws <FormatException>(string.Empty));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(new 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 override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            DateTime date = new DateTime(1998, 12, 5);

            yield return(ConvertTest.Valid("", DateTime.MinValue));

            yield return(ConvertTest.Valid("    ", DateTime.MinValue));

            yield return(ConvertTest.Valid(date.ToString(), date));

            yield return(ConvertTest.Valid(date.ToString(CultureInfo.InvariantCulture.DateTimeFormat), date, CultureInfo.InvariantCulture));

            yield return(ConvertTest.Valid(" " + date.ToString(CultureInfo.InvariantCulture.DateTimeFormat) + " ", date, CultureInfo.InvariantCulture));

            yield return(ConvertTest.Throws <FormatException>("invalid"));

            yield return(ConvertTest.CantConvertFrom(new object()));

            yield return(ConvertTest.CantConvertFrom(1));
        }
Example #9
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            TimeOnly timeOnly = new TimeOnly(10, 30, 50);

            yield return(ConvertTest.Valid("", TimeOnly.MinValue));

            yield return(ConvertTest.Valid("    ", TimeOnly.MinValue));

            yield return(ConvertTest.Valid(timeOnly.ToString(), TimeOnly.Parse(timeOnly.ToString())));

            yield return(ConvertTest.Valid(timeOnly.ToString(CultureInfo.InvariantCulture.DateTimeFormat),
                                           TimeOnly.Parse(timeOnly.ToString(CultureInfo.InvariantCulture.DateTimeFormat))));

            yield return(ConvertTest.Valid(" " + timeOnly.ToString(CultureInfo.InvariantCulture.DateTimeFormat) + " ",
                                           TimeOnly.Parse(timeOnly.ToString(CultureInfo.InvariantCulture.DateTimeFormat))));

            yield return(ConvertTest.Throws <FormatException>("invalid"));

            yield return(ConvertTest.CantConvertFrom(new object()));

            yield return(ConvertTest.CantConvertFrom(1));
        }
Example #10
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Valid("1", (short)1));

            yield return(ConvertTest.Valid("-1  ", (short)-1));

            yield return(ConvertTest.Valid("#2", (short)2));

            yield return(ConvertTest.Valid("+7", (short)7));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("8.0"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>(""));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("bad"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("32768"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("-32769"));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }
Example #11
0
        public override IEnumerable <ConvertTest> ConvertFromTestData()
        {
            yield return(ConvertTest.Throws <ArgumentException, Exception>(""));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("bad"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("0x"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("0X"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("1x1"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("0y1"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("&h"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("&H"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("0h1"));

            yield return(ConvertTest.Throws <ArgumentException, Exception>("&i1"));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }
Example #12
0
 public override IEnumerable <ConvertTest> ConvertFromTestData()
 {
     yield return(ConvertTest.CantConvertFrom(new CustomCollection()));
 }
        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(string.Empty, null));

            yield return(ConvertTest.Valid("   ", null));

            yield return(ConvertTest.Valid("(none)", null).WithInvariantRemoteInvokeCulture());

            yield return(ConvertTest.Valid("nothing", null));

            // IReferenceService.
            var nullReferenceServiceContext = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(null);
                }
            };

            yield return(ConvertTest.Valid("reference name", null).WithContext(nullReferenceServiceContext));

            var invalidReferenceServiceContext = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(new object());
                }
            };

            yield return(ConvertTest.Valid("reference name", null).WithContext(invalidReferenceServiceContext));

            var component1       = new TestComponent();
            var component2       = new TestComponent();
            var nonComponent     = new object();
            var referenceService = new MockReferenceService();

            referenceService.AddReference("reference name", component1);
            referenceService.AddReference(string.Empty, component2);
            referenceService.AddReference("non component", nonComponent);
            var validReferenceServiceContext = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(referenceService);
                }
            };

            yield return(ConvertTest.Valid("reference name", component1).WithContext(validReferenceServiceContext));

            yield return(ConvertTest.Valid("  reference name  ", component1).WithContext(validReferenceServiceContext));

            yield return(ConvertTest.Valid(string.Empty, component2).WithContext(validReferenceServiceContext));

            yield return(ConvertTest.Valid("non component", nonComponent).WithContext(validReferenceServiceContext));

            yield return(ConvertTest.Valid("no such reference", null).WithContext(validReferenceServiceContext));

            // IContainer.
            var containerComponent1 = new TestComponent();
            var containerComponent2 = new TestComponent();
            var container           = new Container();

            container.Add(containerComponent1, "reference name");
            container.Add(containerComponent2, string.Empty);
            var contextWithContainer = new MockTypeDescriptorContext {
                Container = container
            };

            yield return(ConvertTest.Valid("reference name", containerComponent1).WithContext(contextWithContainer));

            yield return(ConvertTest.Valid(string.Empty, containerComponent2).WithContext(contextWithContainer));

            yield return(ConvertTest.Valid("no such reference", null).WithContext(contextWithContainer));

            yield return(ConvertTest.CantConvertFrom(1));

            yield return(ConvertTest.CantConvertFrom(new object()));
        }