Пример #1
0
        public static void TypeConverterStringResources()
        {
            var values = TestData.StringConverter;

            byte[] binaryWriterBuffer;

            using (MemoryStream ms = new MemoryStream())
                using (PreserializedResourceWriter writer = new PreserializedResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, TestData.GetStringValue(pair.Value), TestData.GetSerializationTypeName(pair.Value.GetType()));
                    }
                    writer.Generate();
                    binaryWriterBuffer = ms.ToArray();
                }

            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (DeserializingResourceReader reader = new DeserializingResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        ResourceValueEquals(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }
        }
Пример #2
0
        public static void PrimitiveResourcesAsStrings()
        {
            IReadOnlyDictionary <string, object> values = TestData.Primitive;

            byte[] writerBuffer, binaryWriterBuffer;
            using (MemoryStream ms = new MemoryStream())
                using (ResourceWriter writer = new ResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, pair.Value);
                    }

                    writer.Generate();
                    writerBuffer = ms.ToArray();
                }

            using (MemoryStream ms = new MemoryStream())
                using (PreserializedResourceWriter writer = new PreserializedResourceWriter(ms))
                {
                    foreach (var pair in values)
                    {
                        writer.AddResource(pair.Key, TestData.GetStringValue(pair.Value), TestData.GetSerializationTypeName(pair.Value.GetType()));
                    }
                    writer.Generate();
                    binaryWriterBuffer = ms.ToArray();
                }

            // PreserializedResourceWriter should write ResourceWriter/ResourceReader format
            Assert.Equal(writerBuffer, binaryWriterBuffer);

            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (ResourceReader reader = new ResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        Assert.Equal(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }

            // DeserializingResourceReader can read ResourceReader format
            using (MemoryStream ms = new MemoryStream(binaryWriterBuffer, false))
                using (DeserializingResourceReader reader = new DeserializingResourceReader(ms))
                {
                    IDictionaryEnumerator dictEnum = reader.GetEnumerator();

                    while (dictEnum.MoveNext())
                    {
                        Assert.Equal(values[(string)dictEnum.Key], dictEnum.Value);
                    }
                }
        }