forked from dotnet/wcf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding tests for NetHttpsBinding. * Fixes dotnet#507
- Loading branch information
1 parent
e671f7c
commit f641d96
Showing
8 changed files
with
346 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/System.Private.ServiceModel/tests/Scenarios/Binding/Http/NetHttpsBindingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
|
||
using System; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Channels; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
public static class Binding_Http_NetHttpsBindingTests | ||
{ | ||
[Fact] | ||
[OuterLoop] | ||
public static void DefaultCtor_NetHttps_Echo_RoundTrips_String() | ||
{ | ||
string testString = "Hello"; | ||
ChannelFactory<IWcfService> factory = null; | ||
IWcfService serviceProxy = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
NetHttpsBinding netHttpsBinding = new NetHttpsBinding(); | ||
factory = new ChannelFactory<IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); | ||
serviceProxy = factory.CreateChannel(); | ||
|
||
// *** EXECUTE *** \\ | ||
string result = serviceProxy.Echo(testString); | ||
|
||
// *** VALIDATE *** \\ | ||
Assert.True(String.Equals(testString, result), String.Format("Expected result was {0}. Actual was {1}", testString, result)); | ||
|
||
// *** CLEANUP *** \\ | ||
factory.Close(); | ||
((ICommunicationObject)serviceProxy).Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); | ||
} | ||
} | ||
|
||
[Fact] | ||
[OuterLoop] | ||
public static void TransportWithMessageCredential_NotSupported_NetHttps() | ||
{ | ||
string testString = "Hello"; | ||
ChannelFactory<IWcfService> factory = null; | ||
IWcfService serviceProxy = null; | ||
|
||
// BasicHttpsSecurityMode.TransportWithMessageCredential is accessible but not supported. | ||
// Verify the correct exception and message is thrown. | ||
// When/if Message Security is supported this test will fail and will serve as a reminder to add test coverage. | ||
Assert.Throws<PlatformNotSupportedException>(() => | ||
{ | ||
try | ||
{ | ||
// *** SETUP *** \\ | ||
NetHttpsBinding netHttpsBinding = new NetHttpsBinding(BasicHttpsSecurityMode.TransportWithMessageCredential); | ||
factory = new ChannelFactory<IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); | ||
serviceProxy = factory.CreateChannel(); | ||
|
||
// *** EXECUTE *** \\ | ||
string result = serviceProxy.Echo(testString); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); | ||
} | ||
}); | ||
} | ||
|
||
[Fact] | ||
[OuterLoop] | ||
public static void NonDefaultCtor_NetHttps_Echo_RoundTrips_String() | ||
{ | ||
string testString = "Hello"; | ||
ChannelFactory<IWcfService> factory = null; | ||
IWcfService serviceProxy = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
NetHttpsBinding netHttpsBinding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport); | ||
factory = new ChannelFactory<IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); | ||
serviceProxy = factory.CreateChannel(); | ||
|
||
// *** EXECUTE *** \\ | ||
string result = serviceProxy.Echo(testString); | ||
|
||
// *** VALIDATE *** \\ | ||
Assert.NotNull(result); | ||
Assert.Equal(testString, result); | ||
|
||
// *** CLEANUP *** \\ | ||
factory.Close(); | ||
((ICommunicationObject)serviceProxy).Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...ystem.Private.ServiceModel/tests/Scenarios/Client/ChannelLayer/DuplexChannelShapeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
|
||
using System; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Channels; | ||
using System.Xml; | ||
using Infrastructure.Common; | ||
using Xunit; | ||
|
||
public partial class DuplexChannelShapeTests : ConditionalWcfTest | ||
{ | ||
// Creating a ChannelFactory using a binding's 'BuildChannelFactory' method and providing a channel shape... | ||
// returns a concrete type determined by the channel shape requested and other binding related settings. | ||
// The tests in this file use the IDuplexChannel shape. | ||
|
||
[ConditionalFact(nameof(Root_Certificate_Installed))] | ||
[OuterLoop] | ||
[ActiveIssue(1157)] | ||
public static void IDuplexSessionChannel_Https_NetHttpsBinding() | ||
{ | ||
IChannelFactory<IDuplexSessionChannel> factory = null; | ||
IDuplexSessionChannel channel = null; | ||
Message replyMessage = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport); | ||
|
||
// Create the channel factory | ||
factory = binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection()); | ||
factory.Open(); | ||
|
||
// Create the channel. | ||
channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); | ||
channel.Open(); | ||
|
||
// Create the Message object to send to the service. | ||
Message requestMessage = Message.CreateMessage( | ||
binding.MessageVersion, | ||
action, | ||
new CustomBodyWriter(clientMessage)); | ||
requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid()); | ||
|
||
// *** EXECUTE *** \\ | ||
// Send the Message and receive the Response. | ||
channel.Send(requestMessage); | ||
replyMessage = channel.Receive(TimeSpan.FromSeconds(5)); | ||
|
||
// *** VALIDATE *** \\ | ||
// If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service | ||
string expectedMessageID = requestMessage.Headers.MessageId.ToString(); | ||
string actualMessageID = replyMessage.Headers.RelatesTo.ToString(); | ||
Assert.True(String.Equals(expectedMessageID, actualMessageID), String.Format("Expected Message ID was {0}. Actual was {1}", expectedMessageID, actualMessageID)); | ||
|
||
// Validate the Response | ||
var replyReader = replyMessage.GetReaderAtBodyContents(); | ||
string actualResponse = replyReader.ReadElementContentAsString(); | ||
string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; | ||
Assert.Equal(expectedResponse, actualResponse); | ||
|
||
// *** CLEANUP *** \\ | ||
replyMessage.Close(); | ||
channel.Close(); | ||
factory.Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); | ||
} | ||
} | ||
|
||
[ConditionalFact(nameof(Root_Certificate_Installed))] | ||
[OuterLoop] | ||
[ActiveIssue(1157)] | ||
public static void IDuplexSessionChannel_Http_BasicHttpBinding() | ||
{ | ||
IChannelFactory<IDuplexSessionChannel> factory = null; | ||
IDuplexSessionChannel channel = null; | ||
Message replyMessage = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
BasicHttpBinding binding = new BasicHttpBinding(); | ||
|
||
// Create the channel factory | ||
factory = binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection()); | ||
factory.Open(); | ||
|
||
// Create the channel. | ||
channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); | ||
channel.Open(); | ||
|
||
// Create the Message object to send to the service. | ||
Message requestMessage = Message.CreateMessage( | ||
binding.MessageVersion, | ||
action, | ||
new CustomBodyWriter(clientMessage)); | ||
requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid()); | ||
|
||
// *** EXECUTE *** \\ | ||
// Send the Message and receive the Response. | ||
channel.Send(requestMessage); | ||
replyMessage = channel.Receive(TimeSpan.FromSeconds(5)); | ||
|
||
// *** VALIDATE *** \\ | ||
// If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service | ||
Assert.Equal(requestMessage.Headers.MessageId.ToString(), replyMessage.Headers.RelatesTo.ToString()); | ||
|
||
// Validate the Response | ||
var replyReader = replyMessage.GetReaderAtBodyContents(); | ||
string actualResponse = replyReader.ReadElementContentAsString(); | ||
string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; | ||
Assert.Equal(expectedResponse, actualResponse); | ||
|
||
// *** CLEANUP *** \\ | ||
replyMessage.Close(); | ||
channel.Close(); | ||
factory.Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...vate.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/NetHttpsTestServiceHost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
|
||
using System; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Activation; | ||
using System.ServiceModel.Channels; | ||
|
||
namespace WcfService | ||
{ | ||
public class NetHttpsTestServiceHostFactory : ServiceHostFactory | ||
{ | ||
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) | ||
{ | ||
NetHttpsTestServiceHost serviceHost = new NetHttpsTestServiceHost(serviceType, baseAddresses); | ||
return serviceHost; | ||
} | ||
} | ||
public class NetHttpsTestServiceHost : TestServiceHostBase<IWcfService> | ||
{ | ||
protected override string Address { get { return "NetHttps"; } } | ||
|
||
protected override Binding GetBinding() | ||
{ | ||
return new NetHttpsBinding(); | ||
} | ||
|
||
public NetHttpsTestServiceHost(Type serviceType, params Uri[] baseAddresses) | ||
: base(serviceType, baseAddresses) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters