DictionaryCompatibilityTests.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using Google.ProtocolBuffers.Serialization;
  4. using NUnit.Framework;
  5. namespace Google.ProtocolBuffers.Compatibility
  6. {
  7. [TestFixture]
  8. public class DictionaryCompatibilityTests : CompatibilityTests
  9. {
  10. protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
  11. {
  12. DictionaryWriter writer = new DictionaryWriter();
  13. writer.WriteMessage(message);
  14. return writer.ToDictionary();
  15. }
  16. protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
  17. {
  18. new DictionaryReader((IDictionary<string, object>)message).Merge(builder);
  19. return builder;
  20. }
  21. protected override void AssertOutputEquals(object lhs, object rhs)
  22. {
  23. IDictionary<string, object> left = (IDictionary<string, object>)lhs;
  24. IDictionary<string, object> right = (IDictionary<string, object>)rhs;
  25. Assert.AreEqual(
  26. String.Join(",", new List<string>(left.Keys).ToArray()),
  27. String.Join(",", new List<string>(right.Keys).ToArray())
  28. );
  29. }
  30. }
  31. }