aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs
blob: 73037cce6a0ecb94570180ab5c6d0a0a780a80df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Google.ProtocolBuffers.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Google.ProtocolBuffers.Compatibility
{
    [TestClass]
    public class DictionaryCompatibilityTests : CompatibilityTests
    {
        protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
        {
            DictionaryWriter writer = new DictionaryWriter();
            writer.WriteMessage(message);
            return writer.ToDictionary();
        }

        protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
        {
            new DictionaryReader((IDictionary<string, object>)message).Merge(builder);
            return builder;
        }

        protected override void AssertOutputEquals(object lhs, object rhs)
        {
            IDictionary<string, object> left = (IDictionary<string, object>)lhs;
            IDictionary<string, object> right = (IDictionary<string, object>)rhs;

            Assert.AreEqual(
                String.Join(",", new List<string>(left.Keys).ToArray()),
                String.Join(",", new List<string>(right.Keys).ToArray())
            );
        }
    }
}