Beispiel #1
0
        public void SequentialWriter_MicrosoftWriterApacherReaderOfDictionary()
        {
            var expected = new List <ContainingDictionaryClass <string, string> >();

            for (var i = 0; i < 7; i++)
            {
                expected.Add(ContainingDictionaryClass <string, string> .Create(
                                 new Dictionary <string, string>
                {
                    { "testkey" + i, "testvalue" + i }
                }));
            }

            var w = AvroContainer.CreateWriter <ContainingDictionaryClass <string, string> >(this.resultStream, Codec.Deflate);

            using (var writer = new SequentialWriter <ContainingDictionaryClass <string, string> >(w, 2))
            {
                expected.ForEach(writer.Write);
            }

            this.resultStream.Seek(0, SeekOrigin.Begin);

            var reader = DataFileReader <GenericRecord> .OpenReader(this.resultStream);

            var actual = new List <GenericRecord>(reader);

            Assert.AreEqual(expected.Count, actual.Count);

            for (var i = 0; i < expected.Count; ++i)
            {
                var actualValue = actual[i]["Property"] as Dictionary <string, object>;
                Assert.IsNotNull(actualValue);
                Assert.AreEqual(actualValue["testkey" + i] as string, expected[i].Property["testkey" + i]);
            }
        }
Beispiel #2
0
        public bool Equals(ContainingDictionaryClass <TK, TV> other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Utilities.DictionaryEquals(this.Property, other.Property));
        }
        public void Container_MicrosoftWriterApacherReaderOfDictionary()
        {
            var expected = new List <ContainingDictionaryClass <string, string> >();

            for (var i = 0; i < 7; i++)
            {
                expected.Add(ContainingDictionaryClass <string, string> .Create(
                                 new Dictionary <string, string>
                {
                    { "testkey" + i, "testvalue" + i }
                }));
            }

            using (var memoryStream = new MemoryStream())
            {
                var writer = AvroContainer.CreateWriter <ContainingDictionaryClass <string, string> >(memoryStream, Codec.Deflate);

                {
                    var i = 0;
                    while (i < expected.Count)
                    {
                        var block = writer.CreateBlockAsync().Result;
                        for (var j = 0; j < 2; j++)
                        {
                            if (i >= expected.Count)
                            {
                                break;
                            }
                            block.Write(expected[i]);
                            i++;
                        }
                        writer.WriteBlockAsync(block).Wait();
                    }
                    writer.Dispose();
                }

                memoryStream.Seek(0, SeekOrigin.Begin);

                var reader = DataFileReader <GenericRecord> .OpenReader(memoryStream);

                var actual = new List <GenericRecord>(reader);

                Assert.Equal(expected.Count, actual.Count);

                for (var i = 0; i < expected.Count; ++i)
                {
                    var actualValue = actual[i]["Property"] as Dictionary <string, object>;
                    Assert.Equal(actualValue["testkey" + i] as string, expected[i].Property["testkey" + i]);
                }
            }
        }