• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2008 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using Google.Protobuf.Reflection;
11 using UnitTest.Issues.TestProtos;
12 using NUnit.Framework;
13 
14 
15 namespace Google.Protobuf
16 {
17     /// <summary>
18     /// Tests for issues which aren't easily compartmentalized into other unit tests.
19     /// </summary>
20     public class IssuesTest
21     {
22         // Issue 45
23         [Test]
FieldCalledItem()24         public void FieldCalledItem()
25         {
26             ItemField message = new ItemField { Item = 3 };
27             FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
28             Assert.NotNull(field);
29             Assert.AreEqual(3, (int)field.Accessor.GetValue(message));
30         }
31 
32         [Test]
ReservedNames()33         public void ReservedNames()
34         {
35             var message = new ReservedNames { Types_ = 10, Descriptor_ = 20 };
36             // Underscores aren't reflected in the JSON.
37             Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToString());
38         }
39 
40         [Test]
JsonNameParseTest()41         public void JsonNameParseTest()
42         {
43             var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(UnittestIssuesReflection.Descriptor));
44             var parser = new JsonParser(settings);
45 
46             // It is safe to use either original field name or explicitly specified json_name
47             Assert.AreEqual(new TestJsonName { Name = "test", Description = "test2", Guid = "test3" },
48                 parser.Parse<TestJsonName>("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }"));
49         }
50 
51         [Test]
JsonNameFormatTest()52         public void JsonNameFormatTest()
53         {
54             var message = new TestJsonName { Name = "test", Description = "test2", Guid = "test3" };
55             Assert.AreEqual("{ \"name\": \"test\", \"desc\": \"test2\", \"exid\": \"test3\" }",
56                 JsonFormatter.Default.Format(message));
57         }
58     }
59 }
60