Exemplo n.º 1
0
        public void TestConvertBoolToString()
        {
            AttributeType test = new AttributeType("test", typeof(Boolean));

            Assert.AreEqual("true", test.Convert(true));
            Assert.AreEqual("false", test.Convert(false));
        }
Exemplo n.º 2
0
        public void TestConvertUriToString()
        {
            AttributeType test = new AttributeType("test", typeof(Uri));
            Uri           uri  = new Uri("foo", UriKind.Relative);

            Assert.AreEqual(uri.ToString(), test.Convert(uri));
        }
Exemplo n.º 3
0
        private void TestConvertFromStringScalar <T>(T value)
            where T : IFormattable
        {
            AttributeType test      = new AttributeType("test", typeof(T));
            object        converted = test.Convert(value.ToString(null, CultureInfo.InvariantCulture));

            Assert.AreEqual(converted, value);
        }
Exemplo n.º 4
0
        private void TestConvertToStringScalar <T>(T value)
            where T : IFormattable
        {
            AttributeType test     = new AttributeType("test", typeof(T));
            string        expected = value.ToString(null, CultureInfo.InvariantCulture);
            string        actual   = test.Convert(value);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        private void TestConvertFromString <T>(T value1, T value2)
            where T : IFormattable
        {
            TestConvertFromStringScalar <T>(value1);

            AttributeType arrayTest    = new AttributeType("test", typeof(T[]), 2);
            string        valueString1 = value1.ToString(null, CultureInfo.InvariantCulture);
            string        valueString2 = value2.ToString(null, CultureInfo.InvariantCulture);
            object        converted    = arrayTest.Convert(valueString1 + " " + valueString2);

            Assert.AreEqual(converted, new T[] { value1, value2 });
        }
Exemplo n.º 6
0
        public void TestConvertRelativeUriContainingSpacesToString()
        {
            var test = new AttributeType("test", typeof(Uri));

            var baseUri = new Uri("C:\\base\\path");
            var relPath = "rel\\path\\with spaces\\in it\\file.txt";

            var absUri = new Uri(baseUri, relPath);
            var relUri = baseUri.MakeRelativeUri(absUri);

            var uriToString  = relUri.ToString();
            var uriConverted = test.Convert(relUri);

            Assert.AreEqual(uriToString, uriConverted);
        }
Exemplo n.º 7
0
        public void TestDateTimeConversion()
        {
            var test = new AttributeType("test", typeof(DateTime));

            var    original  = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Local);
            string written   = test.Convert(original);
            var    roundTrip = (DateTime)test.Convert(written);

            Assert.IsTrue(AreEqual(original, roundTrip));

            original  = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Utc);
            written   = test.Convert(original);
            roundTrip = (DateTime)test.Convert(written);
            Assert.IsTrue(AreEqual(original, roundTrip));

            original  = new DateTime(2015, 3, 10, 4, 32, 59, DateTimeKind.Unspecified);
            written   = test.Convert(original);
            roundTrip = (DateTime)test.Convert(written);
            Assert.IsTrue(AreEqual(original, roundTrip));

            //The following tests the output (DateTime to string) of ATF 3.2 to 3.9,
            //  which used the following code:
            //result = ((DateTime)value).ToString(@"yyyy-MM-ddTHH:mm:ss.fffffffZ");
            //  Note the appended 'Z' which is not a custom format specifier character.
            //  The 'Z' indicates UTC time even though the DateTimeobject may not be in
            //  UTC time.
            original  = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Utc);
            written   = "2015-03-10T16:32:00.0000000Z";
            roundTrip = (DateTime)test.Convert(written);
            Assert.IsTrue(AreEqual(original, roundTrip));

            //original = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Unspecified);
            //written = "2015-03-10T16:32:00.0000000Z";
            //roundTrip = (DateTime)test.Convert(written);
            //Assert.IsTrue(AreEqual(original, roundTrip));

            //original = new DateTime(2015, 3, 10, 16, 32, 00, DateTimeKind.Local);
            //written = "2015-03-10T16:32:00.0000000Z";
            //roundTrip = (DateTime)test.Convert(written);
            //Assert.IsTrue(AreEqual(original, roundTrip));
        }
Exemplo n.º 8
0
        // Test that arrays of strings are converted to and from the 'object' type correctly.
        private void TestStringArray(AttributeType stringArrayType)
        {
            // Test without spaces, like in ATF 3.1 when spaces were not handled correctly.
            {
                string[] array =
                {
                    "e1",
                    "e2",
                    "e3",
                    "e4"
                };
                string toString = stringArrayType.Convert(array);
                object toObject = stringArrayType.Convert(toString);
                Assert.IsTrue(stringArrayType.AreEqual(array, toObject));
            }

            // Test elements that have spaces and quotes ('"') and other special characters.
            {
                string[] array =
                {
                    "first",
                    "second with spaces",
                    "third with \\@##\\\\$#%%!\"~~~ possible escape __ characters\n",
                    "\"fourth\""
                };
                string toString = stringArrayType.Convert(array);
                object toObject = stringArrayType.Convert(toString);
                Assert.IsTrue(stringArrayType.AreEqual(array, toObject));
            }

            // Test that empty strings and null strings are encoded correctly.
            {
                string[] array =
                {
                    "first element",
                    "",
                    "\"",
                    ""
                };
                string toString = stringArrayType.Convert(array);
                object toObject = stringArrayType.Convert(toString);
                Assert.IsTrue(stringArrayType.AreEqual(array, toObject));
            }
        }
Exemplo n.º 9
0
        public void TestConvertBoolArrayToString()
        {
            AttributeType test = new AttributeType("test", typeof(Boolean[]), 2);

            Assert.AreEqual("true false", test.Convert(new Boolean[] { true, false }));
        }
Exemplo n.º 10
0
        public void TestConvertStringArrayToString()
        {
            AttributeType test = new AttributeType("test", typeof(string[]), 2);

            Assert.AreEqual("foo bar", test.Convert(new string[] { "foo", "bar" }));
        }
Exemplo n.º 11
0
        public void TestConvertStringToString()
        {
            AttributeType test = new AttributeType("test", typeof(string));

            Assert.AreEqual("foo", test.Convert((object)"foo"));
        }