Skip to content

Commit 2b89702

Browse files
authored
Public OperationDescription.Begin/End/SyncMethod properties and add unit test (#5165)
* Public OperationDescription's Begin/End/SyncMethod properties and add unit test * Add equal check.
1 parent 13bd2cf commit 2b89702

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/System.Private.ServiceModel/tests/Common/Unit/ServiceInterfaces.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ public interface IDescriptionTestsServiceGenerated
117117
System.Threading.Tasks.Task<string> EchoAsync(string message);
118118
}
119119

120+
// Dummy interface used for ContractDescriptionTests
121+
// This code is deliberately not cleaned up after svcutil to test that we work with the raw Add Service Reference code.
122+
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IDescriptionTestsService")]
123+
public interface IDescriptionTestsServiceBeginEndGenerated
124+
{
125+
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IDescriptionTestsService/MessageRequestReply", ReplyAction = "http://tempuri.org/IDescriptionTestsService/MessageRequestReplyResponse")]
126+
System.ServiceModel.Channels.Message MessageRequestReply(System.ServiceModel.Channels.Message request);
127+
128+
[System.ServiceModel.OperationContractAttribute(AsyncPattern = true, Action = "http://tempuri.org/IDescriptionTestsService/MessageRequestReply", ReplyAction = "http://tempuri.org/IDescriptionTestsService/MessageRequestReplyResponse")]
129+
System.IAsyncResult BeginMessageRequestReply(System.ServiceModel.Channels.Message request, System.AsyncCallback callback, object asyncState);
130+
131+
System.ServiceModel.Channels.Message EndMessageRequestReply(System.IAsyncResult result);
132+
133+
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IDescriptionTestsService/Echo", ReplyAction = "http://tempuri.org/IDescriptionTestsService/EchoResponse")]
134+
string Echo(string message);
135+
136+
[System.ServiceModel.OperationContractAttribute(AsyncPattern = true, Action = "http://tempuri.org/IDescriptionTestsService/Echo", ReplyAction = "http://tempuri.org/IDescriptionTestsService/EchoResponse")]
137+
System.IAsyncResult BeginEcho(string message, System.AsyncCallback callback, object asyncState);
138+
139+
string EndEcho(System.IAsyncResult result);
140+
}
141+
120142
// Manually constructed service interface to validate MessageContract operations.
121143
// This interface closely matches the one found at http://app.thefreedictionary.com/w8feedback.asmx
122144
// This was done to test that we would work with that real world app.

src/System.ServiceModel.Primitives/ref/System.ServiceModel.Primitives.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,9 @@ public OperationDescription(string name, System.ServiceModel.Description.Contrac
17571757
public string Name { get { return default; } }
17581758
public System.Collections.ObjectModel.KeyedCollection<System.Type, System.ServiceModel.Description.IOperationBehavior> OperationBehaviors { get { return default; } }
17591759
public System.Reflection.MethodInfo TaskMethod { get { return default; } set { } }
1760+
public System.Reflection.MethodInfo BeginMethod { get { return default; } set { } }
1761+
public System.Reflection.MethodInfo EndMethod { get { return default; } set { } }
1762+
public System.Reflection.MethodInfo SyncMethod { get { return default; } set { } }
17601763
}
17611764
public partial class OperationDescriptionCollection : System.Collections.ObjectModel.Collection<System.ServiceModel.Description.OperationDescription>
17621765
{

src/System.ServiceModel.Primitives/tests/Description/ContractDescriptionTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,41 @@ public static void ContractDescription_GetContract()
202202
Assert.Equal(typeof(IDescriptionTestsService).Name, contractDescription.ContractType.Name);
203203
Assert.Equal("http://tempuri.org/", contractDescription.Namespace);
204204
}
205+
206+
[WcfFact]
207+
public static void OperationDescription_BeginEndSyncMethod_Property()
208+
{
209+
ContractDescription contractDescription = ContractDescription.GetContract(typeof(IDescriptionTestsServiceBeginEndGenerated));
210+
Assert.Equal(2, contractDescription.Operations.Count);
211+
foreach(OperationDescription operation in contractDescription.Operations)
212+
{
213+
Assert.NotNull(operation.BeginMethod);
214+
Assert.NotNull(operation.EndMethod);
215+
if(operation.Name.Equals("Echo"))
216+
{
217+
Assert.Equal(typeof(IDescriptionTestsServiceBeginEndGenerated).GetMethod(nameof(IDescriptionTestsServiceBeginEndGenerated.BeginEcho)), operation.BeginMethod);
218+
Assert.Equal(typeof(IDescriptionTestsServiceBeginEndGenerated).GetMethod(nameof(IDescriptionTestsServiceBeginEndGenerated.EndEcho)), operation.EndMethod);
219+
}
220+
else
221+
{
222+
Assert.Equal(typeof(IDescriptionTestsServiceBeginEndGenerated).GetMethod(nameof(IDescriptionTestsServiceBeginEndGenerated.BeginMessageRequestReply)), operation.BeginMethod);
223+
Assert.Equal(typeof(IDescriptionTestsServiceBeginEndGenerated).GetMethod(nameof(IDescriptionTestsServiceBeginEndGenerated.EndMessageRequestReply)), operation.EndMethod);
224+
}
225+
}
226+
227+
contractDescription = ContractDescription.GetContract(typeof(IDescriptionTestsService));
228+
Assert.Equal(2, contractDescription.Operations.Count);
229+
foreach (OperationDescription operation in contractDescription.Operations)
230+
{
231+
Assert.NotNull(operation.SyncMethod);
232+
if (operation.Name.Equals("Echo"))
233+
{
234+
Assert.Equal(typeof(IDescriptionTestsService).GetMethod(nameof(IDescriptionTestsService.Echo)), operation.SyncMethod);
235+
}
236+
else
237+
{
238+
Assert.Equal(typeof(IDescriptionTestsService).GetMethod(nameof(IDescriptionTestsService.MessageRequestReply)), operation.SyncMethod);
239+
}
240+
}
241+
}
205242
}

0 commit comments

Comments
 (0)