OLD | NEW |
1 #region Copyright notice and license | 1 #region Copyright notice and license |
2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2008 Google Inc. All rights reserved. | 3 // Copyright 2008 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 Assert.AreEqual(3, (int)field.Accessor.GetValue(message)); | 52 Assert.AreEqual(3, (int)field.Accessor.GetValue(message)); |
53 } | 53 } |
54 | 54 |
55 [Test] | 55 [Test] |
56 public void ReservedNames() | 56 public void ReservedNames() |
57 { | 57 { |
58 var message = new ReservedNames { Types_ = 10, Descriptor_ = 20 }; | 58 var message = new ReservedNames { Types_ = 10, Descriptor_ = 20 }; |
59 // Underscores aren't reflected in the JSON. | 59 // Underscores aren't reflected in the JSON. |
60 Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToS
tring()); | 60 Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToS
tring()); |
61 } | 61 } |
| 62 |
| 63 [Test] |
| 64 public void JsonNameParseTest() |
| 65 { |
| 66 var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(Un
ittestIssuesReflection.Descriptor)); |
| 67 var parser = new JsonParser(settings); |
| 68 |
| 69 // It is safe to use either original field name or explicitly specif
ied json_name |
| 70 Assert.AreEqual(new TestJsonName { Name = "test", Description = "tes
t2", Guid = "test3" }, |
| 71 parser.Parse<TestJsonName>("{ \"name\": \"test\", \"desc\": \"te
st2\", \"guid\": \"test3\" }")); |
| 72 } |
| 73 |
| 74 [Test] |
| 75 public void JsonNameFormatTest() |
| 76 { |
| 77 var message = new TestJsonName { Name = "test", Description = "test2
", Guid = "test3" }; |
| 78 Assert.AreEqual("{ \"name\": \"test\", \"desc\": \"test2\", \"exid\"
: \"test3\" }", |
| 79 JsonFormatter.Default.Format(message)); |
| 80 } |
62 } | 81 } |
63 } | 82 } |
OLD | NEW |