aboutsummaryrefslogblamecommitdiff
path: root/csharp/src/ProtocolBuffers.Test/Compatibility/DictionaryCompatibilityTests.cs
blob: 299bb1a6be3458c30ddbfb0e6c7924d56a92678c (plain) (tree)
1
2
3
4
5
6
7
8

                                  
                                            
                       
 
                                               
  
                  








                                                                                         
                                                                                                                                         









                                                                                       
                             





                                                                         
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Serialization;
using NUnit.Framework;

namespace Google.ProtocolBuffers.Compatibility
{
    [TestFixture]
    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())
            );
        }
    }
}