Esempio n. 1
0
        public virtual void TestStringSchema()
        {
            var testString   = "hello world";
            var testBytes    = Encoding.UTF8.GetBytes(testString);
            var stringSchema = new StringSchema();

            Assert.Equal(testString, stringSchema.Decode(testBytes));
            var act = stringSchema.Encode(testString);

            for (var i = 0; i < testBytes.Length; i++)
            {
                var expected = testBytes[i];
                var actual   = act[i];
                Assert.Equal(expected, actual);
            }

            var bytes2            = Encoding.Unicode.GetBytes(testString);
            var stringSchemaUtf16 = new StringSchema(Encoding.Unicode);

            Assert.Equal(testString, stringSchemaUtf16.Decode(bytes2));
            var act2 = stringSchemaUtf16.Encode(testString);

            for (var i = 0; i < bytes2.Length; i++)
            {
                var expected = bytes2[i];
                var actual   = act2[i];
                Assert.Equal(expected, actual);
            }
        }
Esempio n. 2
0
        public virtual void TestUtf8Charset()
        {
            var schema = new StringSchema();
            var si     = schema.SchemaInfo;

            Assert.False(si.Properties.ContainsKey(StringSchema.CHARSET_KEY));

            var myString    = "my string for test";
            var data        = schema.Encode(myString);
            var actualBytes = Encoding.UTF8.GetBytes(myString);

            for (var i = 0; i < actualBytes.Length; i++)
            {
                var expected = actualBytes[i];
                var actual   = data[i];
                Assert.Equal(expected, actual);
            }
            var decodedString = schema.Decode(data);

            Assert.Equal(decodedString, myString);
        }