| #region Copyright notice and license |
| // Protocol Buffers - Google's data interchange format |
| // Copyright 2015 Google Inc. All rights reserved. |
| // |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file or at |
| // https://developers.google.com/open-source/licenses/bsd |
| #endregion |
| |
| using System; |
| using Google.Protobuf.TestProtos; |
| |
| namespace Google.Protobuf |
| { |
| /// <summary> |
| /// Helper methods to create sample instances of types generated from unit test messages. |
| /// </summary> |
| public class SampleMessages |
| { |
| /// <summary> |
| /// Creates a new sample TestAllTypes message with all fields populated. |
| /// The "oneof" field is populated with the string property (OneofString). |
| /// </summary> |
| public static TestAllTypes CreateFullTestAllTypes() |
| { |
| return new TestAllTypes |
| { |
| SingleBool = true, |
| SingleBytes = ByteString.CopyFrom(1, 2, 3, 4), |
| SingleDouble = 23.5, |
| SingleFixed32 = 23, |
| SingleFixed64 = 1234567890123, |
| SingleFloat = 12.25f, |
| SingleForeignEnum = ForeignEnum.ForeignBar, |
| SingleForeignMessage = new ForeignMessage { C = 10 }, |
| SingleImportEnum = ImportEnum.ImportBaz, |
| SingleImportMessage = new ImportMessage { D = 20 }, |
| SingleInt32 = 100, |
| SingleInt64 = 3210987654321, |
| SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo, |
| SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 }, |
| SinglePublicImportMessage = new PublicImportMessage { E = 54 }, |
| SingleSfixed32 = -123, |
| SingleSfixed64 = -12345678901234, |
| SingleSint32 = -456, |
| SingleSint64 = -12345678901235, |
| SingleString = "test", |
| SingleUint32 = UInt32.MaxValue, |
| SingleUint64 = UInt64.MaxValue, |
| RepeatedBool = { true, false }, |
| RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) }, |
| RepeatedDouble = { -12.25, 23.5 }, |
| RepeatedFixed32 = { UInt32.MaxValue, 23 }, |
| RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 }, |
| RepeatedFloat = { 100f, 12.25f }, |
| RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar }, |
| RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } }, |
| RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified }, |
| RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } }, |
| RepeatedInt32 = { 100, 200 }, |
| RepeatedInt64 = { 3210987654321, Int64.MaxValue }, |
| RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg }, |
| RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } }, |
| RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } }, |
| RepeatedSfixed32 = { -123, 123 }, |
| RepeatedSfixed64 = { -12345678901234, 12345678901234 }, |
| RepeatedSint32 = { -456, 100 }, |
| RepeatedSint64 = { -12345678901235, 123 }, |
| RepeatedString = { "foo", "bar" }, |
| RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue }, |
| RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue }, |
| OneofString = "Oneof string" |
| }; |
| } |
| } |
| } |