Commit 32ead755 authored by Jie Luo's avatar Jie Luo

Merge pull request #313 from jskeet/csharp

First steps to making the C# runtime work with new codegen
parents b977c3ed 5ca6dd76
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra;
option java_package = "com.google.protobuf";
message TestUnpackedExtensions {
extensions 1 to max;
}
extend TestUnpackedExtensions {
repeated int32 unpacked_int32_extension = 90;
repeated int64 unpacked_int64_extension = 91;
repeated uint32 unpacked_uint32_extension = 92;
repeated uint64 unpacked_uint64_extension = 93;
repeated sint32 unpacked_sint32_extension = 94;
repeated sint64 unpacked_sint64_extension = 95;
repeated fixed32 unpacked_fixed32_extension = 96;
repeated fixed64 unpacked_fixed64_extension = 97;
repeated sfixed32 unpacked_sfixed32_extension = 98;
repeated sfixed64 unpacked_sfixed64_extension = 99;
repeated float unpacked_float_extension = 100;
repeated double unpacked_double_extension = 101;
repeated bool unpacked_bool_extension = 102;
repeated UnpackedExtensionsForeignEnum unpacked_enum_extension = 103;
}
enum UnpackedExtensionsForeignEnum {
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
}
// Additional options required for C# generation. File from copyright syntax = "proto2";
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasFullProtoFile";
package protobuf_unittest_extra; package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = CODE_SIZE; option optimize_for = CODE_SIZE;
option java_package = "com.google.protobuf"; option java_package = "com.google.protobuf";
message TestInteropPerson { message TestInteropPerson {
...@@ -45,7 +41,10 @@ message TestInteropEmployeeId { ...@@ -45,7 +41,10 @@ message TestInteropEmployeeId {
} }
extend TestInteropPerson { extend TestInteropPerson {
required TestInteropEmployeeId employee_id = 126; // Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeId employee_id = 126;
} }
message TestMissingFieldsA { message TestMissingFieldsA {
......
// Additional options required for C# generation. File from copyright syntax = "proto2";
// line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasLiteProtoFile";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra; package protobuf_unittest_extra;
option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
option java_package = "com.google.protobuf"; option java_package = "com.google.protobuf";
message TestRequiredLite { message TestRequiredLite {
...@@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite { ...@@ -58,7 +53,10 @@ message TestInteropEmployeeIdLite {
} }
extend TestInteropPersonLite { extend TestInteropPersonLite {
required TestInteropEmployeeIdLite employee_id_lite = 126; // Note: changed from required to optional, as required fields are not
// permitted in extensions. (The fact that this was allowed in protogen
// before was almost certainly a bug.)
optional TestInteropEmployeeIdLite employee_id_lite = 126;
} }
/* Removed from unittest_lite.proto and added back here */ /* Removed from unittest_lite.proto and added back here */
......
import "google/protobuf/csharp_options.proto"; syntax = "proto2";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestXmlSerializerTestProtoFile"; option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).add_serializable = true;
package protobuf_unittest_extra; package protobuf_unittest_extra;
......
syntax = "proto2";
// Additional options required for C# generation. File from copyright // Additional options required for C# generation. File from copyright
// line onwards is as per original distribution. // line onwards is as per original distribution.
import "google/protobuf/csharp_options.proto";
import "google/protobuf/unittest.proto"; import "google/protobuf/unittest.proto";
import "google/protobuf/unittest_custom_options.proto"; import "google/protobuf/unittest_custom_options.proto";
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestGenericServices";
option (google.protobuf.csharp_file_options).service_generator_type = GENERIC; option csharp_namespace = "Google.ProtocolBuffers.TestProtos";
// option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;
// We don't put this in a package within proto2 because we need to make sure
// that the generated code doesn't depend on being in the proto2 namespace.
package protobuf_unittest;
option optimize_for = SPEED; option optimize_for = SPEED;
service TestGenericService { service TestGenericService {
rpc Foo(FooRequest) returns (FooResponse); rpc Foo(FooRequest) returns (FooResponse);
rpc Bar(BarRequest) returns (BarResponse); rpc Bar(BarRequest) returns (BarResponse);
} }
service TestGenericServiceWithCustomOptions { service TestGenericServiceWithCustomOptions {
option (service_opt1) = -9876543210; option (service_opt1) = -9876543210;
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) { rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
option (method_opt1) = METHODOPT1_VAL2; option (method_opt1) = METHODOPT1_VAL2;
} }
} }
syntax = "proto2";
// These proto descriptors have at one time been reported as an issue or defect. // These proto descriptors have at one time been reported as an issue or defect.
// They are kept here to replicate the issue, and continue to verify the fix. // They are kept here to replicate the issue, and continue to verify the fix.
import "google/protobuf/csharp_options.proto";
// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified // Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
option (google.protobuf.csharp_file_options).namespace = "UnitTest.Issues.TestProtos"; option csharp_namespace = "UnitTest.Issues.TestProtos";
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasIssuesProtoFile";
package unittest_issues; package unittest_issues;
option optimize_for = SPEED; option optimize_for = SPEED;
...@@ -67,24 +67,28 @@ service TestGenericService { ...@@ -67,24 +67,28 @@ service TestGenericService {
rpc Bar(TestBasicNoFields) returns (TestBasicMessage); rpc Bar(TestBasicNoFields) returns (TestBasicMessage);
} }
*/ */
// Issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
// New issue 309: https://github.com/google/protobuf/issues/309
message A { // message A {
optional int32 _A = 1; // optional int32 _A = 1;
} // }
message B { // message B {
optional int32 B_ = 1; // optional int32 B_ = 1;
} // }
message AB { //message AB {
optional int32 a_b = 1; // optional int32 a_b = 1;
} //}
// Similar issue with numeric names // Similar issue with numeric names
message NumberField { // Java code failed too, so probably best for this to be a restriction.
optional int32 _01 = 1; // See https://github.com/google/protobuf/issues/308
} // message NumberField {
// optional int32 _01 = 1;
// }
// Issue 28: Circular message dependencies result in null defaults for DefaultInstance // Issue 28: Circular message dependencies result in null defaults for DefaultInstance
......
...@@ -132,8 +132,8 @@ namespace Google.ProtocolBuffers ...@@ -132,8 +132,8 @@ namespace Google.ProtocolBuffers
{ {
byte[] bytes = TestUtil.GetPackedSet().ToByteArray(); byte[] bytes = TestUtil.GetPackedSet().ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry); Unittest.RegisterAllExtensions(registry);
UnitTestExtrasProtoFile.RegisterAllExtensions(registry); UnittestImport.RegisterAllExtensions(registry);
TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry); TestUnpackedExtensions message = TestUnpackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertUnpackedExtensionsSet(message); TestUtil.AssertUnpackedExtensionsSet(message);
} }
...@@ -143,7 +143,7 @@ namespace Google.ProtocolBuffers ...@@ -143,7 +143,7 @@ namespace Google.ProtocolBuffers
{ {
byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray(); byte[] bytes = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestProtoFile.RegisterAllExtensions(registry); Unittest.RegisterAllExtensions(registry);
TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry); TestPackedExtensions message = TestPackedExtensions.ParseFrom(bytes, registry);
TestUtil.AssertPackedExtensionsSet(message); TestUtil.AssertPackedExtensionsSet(message);
} }
...@@ -250,7 +250,7 @@ namespace Google.ProtocolBuffers ...@@ -250,7 +250,7 @@ namespace Google.ProtocolBuffers
TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build(); TestAllTypes d = TestAllTypes.CreateBuilder(c).AddRepeatedString("y").Build();
TestAllExtensions e = TestUtil.GetAllExtensionsSet(); TestAllExtensions e = TestUtil.GetAllExtensionsSet();
TestAllExtensions f = TestAllExtensions.CreateBuilder(e) TestAllExtensions f = TestAllExtensions.CreateBuilder(e)
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 999).Build(); .AddExtension(Unittest.RepeatedInt32Extension, 999).Build();
CheckEqualsIsConsistent(a); CheckEqualsIsConsistent(a);
CheckEqualsIsConsistent(b); CheckEqualsIsConsistent(b);
......
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using Google.ProtocolBuffers.DescriptorProtos;
using Google.ProtocolBuffers.Descriptors;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers
{
[TestClass]
public class DescriptorUtilTest
{
[TestMethod]
public void ExplicitNamespace()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder
{
Name = "x",
Package = "pack",
Options =
new FileOptions.Builder().SetExtension(
CSharpOptions.CSharpFileOptions,
new CSharpFileOptions.Builder {Namespace = "Foo.Bar"}.Build()).
Build()
}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("Foo.Bar", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void NoNamespaceFallsBackToPackage()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x", Package = "pack"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("pack", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void NoNamespaceOrPackageFallsBackToEmptyString()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("", descriptor.CSharpOptions.Namespace);
}
[TestMethod]
public void ExplicitlyNamedFileClass()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder
{
Name = "x",
Options =
new FileOptions.Builder().SetExtension(
CSharpOptions.CSharpFileOptions,
new CSharpFileOptions.Builder {UmbrellaClassname = "Foo"}.Build())
.Build()
}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("Foo", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithProtoSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar.proto"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithProtoDevelSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar.protodevel"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithNoSuffix()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "foo_bar"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
[TestMethod]
public void ImplicitFileClassWithDirectoryStructure()
{
FileDescriptorProto proto = new FileDescriptorProto.Builder {Name = "x/y/foo_bar"}.Build();
FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
}
}
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -7,7 +7,7 @@ namespace Google.ProtocolBuffers.Compatibility
{ {
/// <summary> /// <summary>
/// This abstract base implements several tests to ensure that well-known messages can be written /// This abstract base implements several tests to ensure that well-known messages can be written
/// and read to/from various formats without loosing data. Implementations overload the two serailization /// and read to/from various formats without losing data. Implementations overload the two serailization
/// methods to provide the tests with the means to read and write for a given format. /// methods to provide the tests with the means to read and write for a given format.
/// </summary> /// </summary>
public abstract class CompatibilityTests public abstract class CompatibilityTests
......
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.Descriptors
{
[TestClass]
public class MessageDescriptorTest
{
[TestMethod]
public void FindPropertyWithDefaultName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.NormalFieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("Normal"));
}
[TestMethod]
public void FindPropertyWithAutoModifiedName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.OptionsMessage_FieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("OptionsMessage_"));
}
[TestMethod]
public void FindPropertyWithCustomizedName()
{
Assert.AreSame(OptionsMessage.Descriptor.FindFieldByNumber(OptionsMessage.CustomNameFieldNumber),
OptionsMessage.Descriptor.FindFieldByPropertyName("CustomName"));
}
[TestMethod]
public void FindPropertyWithInvalidName()
{
Assert.IsNull(OptionsMessage.Descriptor.FindFieldByPropertyName("Bogus"));
}
}
}
\ No newline at end of file
...@@ -398,24 +398,24 @@ namespace Google.ProtocolBuffers ...@@ -398,24 +398,24 @@ namespace Google.ProtocolBuffers
{ {
// ClearExtension() is not actually used in TestUtil, so try it manually. // ClearExtension() is not actually used in TestUtil, so try it manually.
Assert.IsFalse(TestAllExtensions.CreateBuilder() Assert.IsFalse(TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1) .SetExtension(Unittest.OptionalInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.OptionalInt32Extension) .ClearExtension(Unittest.OptionalInt32Extension)
.HasExtension(UnitTestProtoFile.OptionalInt32Extension)); .HasExtension(Unittest.OptionalInt32Extension));
Assert.AreEqual(0, TestAllExtensions.CreateBuilder() Assert.AreEqual(0, TestAllExtensions.CreateBuilder()
.AddExtension(UnitTestProtoFile.RepeatedInt32Extension, 1) .AddExtension(Unittest.RepeatedInt32Extension, 1)
.ClearExtension(UnitTestProtoFile.RepeatedInt32Extension) .ClearExtension(Unittest.RepeatedInt32Extension)
.GetExtensionCount(UnitTestProtoFile.RepeatedInt32Extension)); .GetExtensionCount(Unittest.RepeatedInt32Extension));
} }
[TestMethod] [TestMethod]
public void ExtensionMergeFrom() public void ExtensionMergeFrom()
{ {
TestAllExtensions original = TestAllExtensions.CreateBuilder() TestAllExtensions original = TestAllExtensions.CreateBuilder()
.SetExtension(UnitTestProtoFile.OptionalInt32Extension, 1).Build(); .SetExtension(Unittest.OptionalInt32Extension, 1).Build();
TestAllExtensions merged = TestAllExtensions merged =
TestAllExtensions.CreateBuilder().MergeFrom(original).Build(); TestAllExtensions.CreateBuilder().MergeFrom(original).Build();
Assert.IsTrue((merged.HasExtension(UnitTestProtoFile.OptionalInt32Extension))); Assert.IsTrue((merged.HasExtension(Unittest.OptionalInt32Extension)));
Assert.AreEqual(1, (int) merged.GetExtension(UnitTestProtoFile.OptionalInt32Extension)); Assert.AreEqual(1, (int) merged.GetExtension(Unittest.OptionalInt32Extension));
} }
/* Removed multiple files option for the moment /* Removed multiple files option for the moment
...@@ -430,13 +430,13 @@ namespace Google.ProtocolBuffers ...@@ -430,13 +430,13 @@ namespace Google.ProtocolBuffers
.Build(); .Build();
Assert.AreEqual(message, MessageWithNoOuter.ParseFrom(message.ToByteString())); Assert.AreEqual(message, MessageWithNoOuter.ParseFrom(message.ToByteString()));
Assert.AreEqual(MultiFileProto.Descriptor, MessageWithNoOuter.Descriptor.File); Assert.AreEqual(MultiFileProto.DescriptorProtoFile, MessageWithNoOuter.DescriptorProtoFile.File);
FieldDescriptor field = MessageWithNoOuter.Descriptor.FindDescriptor<FieldDescriptor>("foreign_enum"); FieldDescriptor field = MessageWithNoOuter.DescriptorProtoFile.FindDescriptor<FieldDescriptor>("foreign_enum");
Assert.AreEqual(MultiFileProto.Descriptor.FindTypeByName<EnumDescriptor>("EnumWithNoOuter") Assert.AreEqual(MultiFileProto.DescriptorProtoFile.FindTypeByName<EnumDescriptor>("EnumWithNoOuter")
.FindValueByNumber((int)EnumWithNoOuter.BAR), message[field]); .FindValueByNumber((int)EnumWithNoOuter.BAR), message[field]);
Assert.AreEqual(MultiFileProto.Descriptor, ServiceWithNoOuter.Descriptor.File); Assert.AreEqual(MultiFileProto.DescriptorProtoFile, ServiceWithNoOuter.DescriptorProtoFile.File);
Assert.IsFalse(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter)); Assert.IsFalse(TestAllExtensions.DefaultInstance.HasExtension(MultiFileProto.ExtensionWithOuter));
}*/ }*/
...@@ -512,14 +512,14 @@ namespace Google.ProtocolBuffers ...@@ -512,14 +512,14 @@ namespace Google.ProtocolBuffers
{ {
Assert.AreEqual(TestRequired.SingleFieldNumber, 1000); Assert.AreEqual(TestRequired.SingleFieldNumber, 1000);
Assert.AreEqual(TestRequired.MultiFieldNumber, 1001); Assert.AreEqual(TestRequired.MultiFieldNumber, 1001);
Assert.AreEqual(UnitTestProtoFile.OptionalInt32ExtensionFieldNumber, 1); Assert.AreEqual(Unittest.OptionalInt32ExtensionFieldNumber, 1);
Assert.AreEqual(UnitTestProtoFile.OptionalGroupExtensionFieldNumber, 16); Assert.AreEqual(Unittest.OptionalGroupExtensionFieldNumber, 16);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedMessageExtensionFieldNumber, 18); Assert.AreEqual(Unittest.OptionalNestedMessageExtensionFieldNumber, 18);
Assert.AreEqual(UnitTestProtoFile.OptionalNestedEnumExtensionFieldNumber, 21); Assert.AreEqual(Unittest.OptionalNestedEnumExtensionFieldNumber, 21);
Assert.AreEqual(UnitTestProtoFile.RepeatedInt32ExtensionFieldNumber, 31); Assert.AreEqual(Unittest.RepeatedInt32ExtensionFieldNumber, 31);
Assert.AreEqual(UnitTestProtoFile.RepeatedGroupExtensionFieldNumber, 46); Assert.AreEqual(Unittest.RepeatedGroupExtensionFieldNumber, 46);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedMessageExtensionFieldNumber, 48); Assert.AreEqual(Unittest.RepeatedNestedMessageExtensionFieldNumber, 48);
Assert.AreEqual(UnitTestProtoFile.RepeatedNestedEnumExtensionFieldNumber, 51); Assert.AreEqual(Unittest.RepeatedNestedEnumExtensionFieldNumber, 51);
} }
[TestMethod] [TestMethod]
......
...@@ -32,4 +32,4 @@ using System.Runtime.InteropServices; ...@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
// We don't really need CLSCompliance, but if the assembly builds with no warnings, // We don't really need CLSCompliance, but if the assembly builds with no warnings,
// that means the generator is okay. // that means the generator is okay.
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(false)]
\ No newline at end of file \ No newline at end of file
...@@ -82,14 +82,23 @@ ...@@ -82,14 +82,23 @@
<Compile Include="Compatibility\TextCompatibilityTests.cs" /> <Compile Include="Compatibility\TextCompatibilityTests.cs" />
<Compile Include="Compatibility\XmlCompatibilityTests.cs" /> <Compile Include="Compatibility\XmlCompatibilityTests.cs" />
<Compile Include="SerializableAttribute.cs" /> <Compile Include="SerializableAttribute.cs" />
<Compile Include="TestProtos\UnitTestExtrasProtoFile.cs" /> <Compile Include="TestProtos\GoogleSize.cs" />
<Compile Include="TestProtos\GoogleSpeed.cs" />
<Compile Include="TestProtos\Unittest.cs" />
<Compile Include="TestProtos\UnittestCustomOptions.cs" />
<Compile Include="TestProtos\UnittestDropUnknownFields.cs" />
<Compile Include="TestProtos\UnittestEnormousDescriptor.cs" />
<Compile Include="TestProtos\UnittestExtrasXmltest.cs" />
<Compile Include="TestProtos\UnittestImport.cs" />
<Compile Include="TestProtos\UnittestImportPublic.cs" />
<Compile Include="TestProtos\UnittestIssues.cs" />
<Compile Include="TestProtos\UnittestMset.cs" />
<Compile Include="TestProtos\UnittestOptimizeFor.cs" />
<Compile Include="TestProtos\UnknownEnumTest.cs" />
<Compile Include="TestResources.cs" /> <Compile Include="TestResources.cs" />
<Compile Include="TestRpcForMimeTypes.cs" />
<Compile Include="TestReaderForUrlEncoded.cs" /> <Compile Include="TestReaderForUrlEncoded.cs" />
<Compile Include="CSharpOptionsTest.cs" />
<Compile Include="DeprecatedMemberTest.cs" /> <Compile Include="DeprecatedMemberTest.cs" />
<Compile Include="DescriptorsTest.cs" /> <Compile Include="DescriptorsTest.cs" />
<Compile Include="Descriptors\MessageDescriptorTest.cs" />
<Compile Include="DynamicMessageTest.cs" /> <Compile Include="DynamicMessageTest.cs" />
<Compile Include="ExtendableMessageTest.cs" /> <Compile Include="ExtendableMessageTest.cs" />
<Compile Include="GeneratedBuilderTest.cs" /> <Compile Include="GeneratedBuilderTest.cs" />
...@@ -104,26 +113,8 @@ ...@@ -104,26 +113,8 @@
<Compile Include="ReflectionTester.cs" /> <Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" /> <Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableTest.cs" /> <Compile Include="SerializableTest.cs" />
<Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.cs" /> <Compile Include="TestCornerCases.cs" />
<Compile Include="TestMimeMessageFormats.cs" /> <Compile Include="TestMimeMessageFormats.cs" />
<Compile Include="TestProtos\UnitTestCSharpOptionsProtoFile.cs" />
<Compile Include="TestProtos\UnitTestCustomOptionsProtoFile.cs" />
<Compile Include="TestProtos\UnitTestEmbedOptimizeForProtoFile.cs" />
<Compile Include="TestProtos\UnitTestEmptyProtoFile.cs" />
<Compile Include="TestProtos\UnitTestExtrasIssuesProtoFile.cs" />
<Compile Include="TestProtos\UnitTestGenericServices.cs" />
<Compile Include="TestProtos\UnitTestGoogleSizeProtoFile.cs" />
<Compile Include="TestProtos\UnitTestGoogleSpeedProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportProtoFile.cs" />
<Compile Include="TestProtos\UnitTestMessageSetProtoFile.cs" />
<Compile Include="TestProtos\UnitTestNoGenericServicesProtoFile.cs" />
<Compile Include="TestProtos\UnitTestOptimizeForProtoFile.cs" />
<Compile Include="TestProtos\UnitTestProtoFile.cs" />
<Compile Include="TestProtos\UnitTestRpcInterop.cs" />
<Compile Include="TestProtos\UnitTestXmlSerializerTestProtoFile.cs" />
<Compile Include="TestRpcGenerator.cs" />
<Compile Include="TestUtil.cs" /> <Compile Include="TestUtil.cs" />
<Compile Include="TestWriterFormatJson.cs" /> <Compile Include="TestWriterFormatJson.cs" />
<Compile Include="TestWriterFormatXml.cs" /> <Compile Include="TestWriterFormatXml.cs" />
...@@ -162,6 +153,7 @@ ...@@ -162,6 +153,7 @@
<EmbeddedResource Include="Compatibility\google_message1.dat" /> <EmbeddedResource Include="Compatibility\google_message1.dat" />
<EmbeddedResource Include="Compatibility\google_message2.dat" /> <EmbeddedResource Include="Compatibility\google_message2.dat" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -97,10 +97,8 @@ namespace Google.ProtocolBuffers ...@@ -97,10 +97,8 @@ namespace Google.ProtocolBuffers
this.extensionRegistry = extensionRegistry; this.extensionRegistry = extensionRegistry;
this.file = baseDescriptor.File; this.file = baseDescriptor.File;
// TODO(jonskeet): We've got 2 dependencies, not 1 - because of the C# options. Hmm. Assert.AreEqual(1, file.Dependencies.Count);
// Assert.AreEqual(1, file.Dependencies.Count); this.importFile = file.Dependencies[0];
// TODO(jonskeet): Find dependency by name instead of number?
this.importFile = file.Dependencies[1];
MessageDescriptor testAllTypes; MessageDescriptor testAllTypes;
if (baseDescriptor.Name == "TestAllTypes") if (baseDescriptor.Name == "TestAllTypes")
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Hosting;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Text; using System.Text;
...@@ -20,6 +21,7 @@ namespace Google.ProtocolBuffers ...@@ -20,6 +21,7 @@ namespace Google.ProtocolBuffers
public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder(); public static readonly ISerializable CompileTimeCheckSerializableBuilder = new TestXmlMessage.Builder();
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainMessage() public void TestPlainMessage()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
...@@ -53,6 +55,7 @@ namespace Google.ProtocolBuffers ...@@ -53,6 +55,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestMessageWithExtensions() public void TestMessageWithExtensions()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
...@@ -74,16 +77,16 @@ namespace Google.ProtocolBuffers ...@@ -74,16 +77,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder() .AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE) .AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3]))) .SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
.Build(); .Build();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, message); new BinaryFormatter().Serialize(ms, message);
...@@ -98,6 +101,7 @@ namespace Google.ProtocolBuffers ...@@ -98,6 +101,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestPlainBuilder() public void TestPlainBuilder()
{ {
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder() TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
...@@ -131,6 +135,7 @@ namespace Google.ProtocolBuffers ...@@ -131,6 +135,7 @@ namespace Google.ProtocolBuffers
} }
[TestMethod] [TestMethod]
[Ignore] // Serialization hasn't been reimplemented yet
public void TestBuilderWithExtensions() public void TestBuilderWithExtensions()
{ {
TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder() TestXmlMessage.Builder builder = TestXmlMessage.CreateBuilder()
...@@ -152,16 +157,16 @@ namespace Google.ProtocolBuffers ...@@ -152,16 +157,16 @@ namespace Google.ProtocolBuffers
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder() .AddChildren(TestXmlMessage.Types.Children.CreateBuilder()
.AddOptions(EnumOptions.THREE) .AddOptions(EnumOptions.THREE)
.SetBinary(ByteString.CopyFrom(new byte[3]))) .SetBinary(ByteString.CopyFrom(new byte[3])))
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnittestExtrasXmltest.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
; ;
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, builder); new BinaryFormatter().Serialize(ms, builder);
......
This diff is collapsed.
// Generated by ProtoGen, Version=2.4.1.555, Culture=neutral, PublicKeyToken=55f7125234beb589. DO NOT EDIT!
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
namespace Google.ProtocolBuffers.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static partial class UnitTestEmptyProtoFile {
#region Extension registration
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
}
#endregion
#region Static variables
#endregion
#region Descriptor
public static pbd::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbd::FileDescriptor descriptor;
static UnitTestEmptyProtoFile() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CiRnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfZW1wdHkucHJvdG8aJGdvb2ds",
"ZS9wcm90b2J1Zi9jc2hhcnBfb3B0aW9ucy5wcm90b0I+wj47CiFHb29nbGUu",
"UHJvdG9jb2xCdWZmZXJzLlRlc3RQcm90b3MSFlVuaXRUZXN0RW1wdHlQcm90",
"b0ZpbGU="));
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root;
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
RegisterAllExtensions(registry);
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry);
return registry;
};
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbd::FileDescriptor[] {
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor,
}, assigner);
}
#endregion
}
}
#endregion Designer generated code
This diff is collapsed.
This diff is collapsed.
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using Google.ProtocolBuffers;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Google.ProtocolBuffers
{
/// <summary>
/// This class verifies the correct code is generated from unittest_rpc_interop.proto and provides a small demonstration
/// of using the new IRpcDispatch to write a client/server
/// </summary>
[TestClass]
public class TestRpcGenerator
{
/// <summary>
/// A sample implementation of the ISearchService for testing
/// </summary>
private class ExampleSearchImpl : ISearchService
{
SearchResponse ISearchService.Search(SearchRequest searchRequest)
{
if (searchRequest.CriteriaCount == 0)
{
throw new ArgumentException("No criteria specified.", new InvalidOperationException());
}
SearchResponse.Builder resp = SearchResponse.CreateBuilder();
foreach (string criteria in searchRequest.CriteriaList)
{
resp.AddResults(
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://search.com").
Build());
}
return resp.Build();
}
SearchResponse ISearchService.RefineSearch(RefineSearchRequest refineSearchRequest)
{
SearchResponse.Builder resp = refineSearchRequest.PreviousResults.ToBuilder();
foreach (string criteria in refineSearchRequest.CriteriaList)
{
resp.AddResults(
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://refine.com").
Build());
}
return resp.Build();
}
}
/// <summary>
/// An example extraction of the wire protocol
/// </summary>
private interface IWireTransfer
{
byte[] Execute(string method, byte[] message);
}
/// <summary>
/// An example of a server responding to a wire request
/// </summary>
private class ExampleServerHost : IWireTransfer
{
private readonly IRpcServerStub _stub;
public ExampleServerHost(ISearchService implementation)
{
//on the server, we create a dispatch to call the appropriate method by name
IRpcDispatch dispatch = new SearchService.Dispatch(implementation);
//we then wrap that dispatch in a server stub which will deserialize the wire bytes to the message
//type appropriate for the method name being invoked.
_stub = new SearchService.ServerStub(dispatch);
}
byte[] IWireTransfer.Execute(string method, byte[] message)
{
//now when we recieve a wire transmission to invoke a method by name with a byte[] or stream payload
//we just simply call the sub:
IMessageLite response = _stub.CallMethod(method, CodedInputStream.CreateInstance(message),
ExtensionRegistry.Empty);
//now we return the expected response message:
return response.ToByteArray();
}
}
/// <summary>
/// An example of a client sending a wire request
/// </summary>
private class ExampleClient : IRpcDispatch
{
private readonly IWireTransfer _wire;
public ExampleClient(IWireTransfer wire)
{
_wire = wire;
}
TMessage IRpcDispatch.CallMethod<TMessage, TBuilder>(string method, IMessageLite request,
IBuilderLite<TMessage, TBuilder> response)
{
byte[] rawResponse = _wire.Execute(method, request.ToByteArray());
response.MergeFrom(rawResponse);
return response.Build();
}
}
/// <summary>
/// Put it all together to create one seamless client/server experience full of rich-type goodness ;)
/// All you need to do is send/recieve the method name and message bytes across the wire.
/// </summary>
[TestMethod]
public void TestClientServerDispatch()
{
ExampleServerHost server = new ExampleServerHost(new ExampleSearchImpl());
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting
IWireTransfer wire = server;
ISearchService client = new SearchService(new ExampleClient(wire));
//now the client has a real, typed, interface to work with:
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build());
Assert.AreEqual(1, result.ResultsCount);
Assert.AreEqual("Test", result.ResultsList[0].Name);
Assert.AreEqual("http://search.com", result.ResultsList[0].Url);
//The test part of this, call the only other method
result =
client.RefineSearch(
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build());
Assert.AreEqual(2, result.ResultsCount);
Assert.AreEqual("Test", result.ResultsList[0].Name);
Assert.AreEqual("http://search.com", result.ResultsList[0].Url);
Assert.AreEqual("Refine", result.ResultsList[1].Name);
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url);
}
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -315,7 +315,7 @@ namespace Google.ProtocolBuffers ...@@ -315,7 +315,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionText() public void TestXmlWithExtensionText()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnittestExtrasXmltest.ExtensionText, " extension text value ! ")
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -324,7 +324,7 @@ namespace Google.ProtocolBuffers ...@@ -324,7 +324,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -334,7 +334,7 @@ namespace Google.ProtocolBuffers ...@@ -334,7 +334,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionMessage() public void TestXmlWithExtensionMessage()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, .SetExtension(UnittestExtrasXmltest.ExtensionMessage,
new TestXmlExtension.Builder().SetNumber(42).Build()).Build(); new TestXmlExtension.Builder().SetNumber(42).Build()).Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -343,7 +343,7 @@ namespace Google.ProtocolBuffers ...@@ -343,7 +343,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -353,9 +353,9 @@ namespace Google.ProtocolBuffers ...@@ -353,9 +353,9 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionArray() public void TestXmlWithExtensionArray()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 100)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 101) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 101)
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 102) .AddExtension(UnittestExtrasXmltest.ExtensionNumber, 102)
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -364,7 +364,7 @@ namespace Google.ProtocolBuffers ...@@ -364,7 +364,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
...@@ -374,7 +374,7 @@ namespace Google.ProtocolBuffers ...@@ -374,7 +374,7 @@ namespace Google.ProtocolBuffers
public void TestXmlWithExtensionEnum() public void TestXmlWithExtensionEnum()
{ {
TestXmlMessage message = TestXmlMessage.CreateBuilder() TestXmlMessage message = TestXmlMessage.CreateBuilder()
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionEnum, EnumOptions.ONE) .SetExtension(UnittestExtrasXmltest.ExtensionEnum, EnumOptions.ONE)
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -383,7 +383,7 @@ namespace Google.ProtocolBuffers ...@@ -383,7 +383,7 @@ namespace Google.ProtocolBuffers
string xml = sw.ToString(); string xml = sw.ToString();
ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
UnitTestXmlSerializerTestProtoFile.RegisterAllExtensions(registry); UnittestExtrasXmltest.RegisterAllExtensions(registry);
XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml); XmlFormatReader rdr = XmlFormatReader.CreateInstance(xml);
TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build(); TestXmlMessage copy = rdr.Merge(TestXmlMessage.CreateBuilder(), registry).Build();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment