diff options
author | Jon Skeet <jonskeet@google.com> | 2016-01-20 18:43:00 +0000 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2016-01-20 18:43:00 +0000 |
commit | dd43dcca8c3a0af761ae981edcadd7e78e875fe8 (patch) | |
tree | 57451afd4dc559df5b267357f90a11cbc2d3a410 /csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs | |
parent | 8c5260b21bb0e217e91375893d507a0ef6578d67 (diff) | |
download | protobuf-dd43dcca8c3a0af761ae981edcadd7e78e875fe8.tar.gz protobuf-dd43dcca8c3a0af761ae981edcadd7e78e875fe8.tar.bz2 protobuf-dd43dcca8c3a0af761ae981edcadd7e78e875fe8.zip |
Ensure that FieldMask, Timestamp and Duration ToString() calls don't throw
The usage of ICustomDiagnosticMessage here is non-essential - ToDiagnosticString
doesn't actually get called by ToString() in this case, due to JsonFormatter code. It was
intended to make it clearer that it *did* have a custom format... but then arguably I should
do the same for Value, Struct, Any etc.
Moving some of the code out of JsonFormatter and into Duration/Timestamp/FieldMask likewise
feels somewhat nice, somewhat nasty... basically there are JSON-specific bits of formatting, but
also domain-specific bits of computation. <sigh>
Thoughts welcome.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs index 1aa02e16..141faf80 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs @@ -120,5 +120,13 @@ namespace Google.Protobuf.WellKnownTypes var duration = new Duration { Seconds = seconds, Nanos = nanoseconds }; duration.ToTimeSpan(); } + + [Test] + public void ToString_NonNormalized() + { + // Just a single example should be sufficient... + var duration = new Duration { Seconds = 1, Nanos = -1 }; + Assert.AreEqual("{ \"@warning\": \"Invalid Duration\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString()); + } } } |