summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-12-29 21:20:40 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-12-29 21:20:40 -0800
commit187d3c24b6a76ec0898399f738b3a4f82031ceb0 (patch)
tree5ee920acbfbf1bca76e3a7b4edfcb04e930e2367 /src/DotNetOpenAuth.Test
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
downloadDotNetOpenAuth-187d3c24b6a76ec0898399f738b3a4f82031ceb0.zip
DotNetOpenAuth-187d3c24b6a76ec0898399f738b3a4f82031ceb0.tar.gz
DotNetOpenAuth-187d3c24b6a76ec0898399f738b3a4f82031ceb0.tar.bz2
Replaces IDirectWebRequestHandler with HttpClient in DNOA.Core.
Build breaks are everywhere outside of just this one project as a result.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs38
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestWebRequestHandler.cs116
3 files changed, 0 insertions, 156 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 0e13449..b1d066d 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -115,7 +115,6 @@
<Compile Include="Messaging\ErrorUtilitiesTests.cs" />
<Compile Include="Messaging\MessageSerializerTests.cs" />
<Compile Include="Messaging\MultipartPostPartTests.cs" />
- <Compile Include="Messaging\OutgoingWebResponseTests.cs" />
<Compile Include="Messaging\Reflection\MessageDescriptionTests.cs" />
<Compile Include="Messaging\Reflection\MessageDictionaryTests.cs" />
<Compile Include="Messaging\MessagingTestBase.cs" />
@@ -154,7 +153,6 @@
<Compile Include="Mocks\TestExpiringMessage.cs" />
<Compile Include="Mocks\TestSignedDirectedMessage.cs" />
<Compile Include="Mocks\MockSigningBindingElement.cs" />
- <Compile Include="Mocks\TestWebRequestHandler.cs" />
<Compile Include="Mocks\TestChannel.cs" />
<Compile Include="Mocks\TestMessage.cs" />
<Compile Include="Mocks\TestMessageFactory.cs" />
diff --git a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs b/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs
deleted file mode 100644
index 3efc471..0000000
--- a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OutgoingWebResponseTests.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.Messaging {
- using System.Net;
- using System.Net.Mime;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using NUnit.Framework;
-
- [TestFixture]
- public class OutgoingWebResponseTests {
- /// <summary>
- /// Verifies that setting the Body property correctly converts to a byte stream.
- /// </summary>
- [Test]
- public void SetBodyToByteStream() {
- var response = new OutgoingWebResponse();
- string stringValue = "abc";
- response.Body = stringValue;
- Assert.AreEqual(stringValue.Length, response.ResponseStream.Length);
-
- // Verify that the actual bytes are correct.
- Encoding encoding = new UTF8Encoding(false); // avoid emitting a byte-order mark
- var expectedBuffer = encoding.GetBytes(stringValue);
- var actualBuffer = new byte[stringValue.Length];
- Assert.AreEqual(stringValue.Length, response.ResponseStream.Read(actualBuffer, 0, stringValue.Length));
- CollectionAssert.AreEqual(expectedBuffer, actualBuffer);
-
- // Verify that the header was set correctly.
- Assert.IsNull(response.Headers[HttpResponseHeader.ContentEncoding]);
- Assert.AreEqual(encoding.HeaderName, new ContentType(response.Headers[HttpResponseHeader.ContentType]).CharSet);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestWebRequestHandler.cs b/src/DotNetOpenAuth.Test/Mocks/TestWebRequestHandler.cs
deleted file mode 100644
index b38a3d8..0000000
--- a/src/DotNetOpenAuth.Test/Mocks/TestWebRequestHandler.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="TestWebRequestHandler.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.Mocks {
- using System;
- using System.IO;
- using System.Net;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth.ChannelElements;
-
- internal class TestWebRequestHandler : IDirectWebRequestHandler {
- private Stream postEntity;
-
- /// <summary>
- /// Gets or sets the callback used to provide the mock response for the mock request.
- /// </summary>
- internal Func<HttpWebRequest, IncomingWebResponse> Callback { get; set; }
-
- /// <summary>
- /// Gets the stream that was written out as if on an HTTP request.
- /// </summary>
- internal Stream RequestEntityStream {
- get {
- if (this.postEntity == null) {
- return null;
- }
-
- Stream result = new MemoryStream();
- long originalPosition = this.postEntity.Position;
- this.postEntity.Position = 0;
- this.postEntity.CopyTo(result);
- this.postEntity.Position = originalPosition;
- result.Position = 0;
- return result;
- }
- }
-
- /// <summary>
- /// Gets the stream that was written out as if on an HTTP request as an ordinary string.
- /// </summary>
- internal string RequestEntityAsString {
- get {
- if (this.postEntity == null) {
- return null;
- }
-
- StreamReader reader = new StreamReader(this.RequestEntityStream);
- return reader.ReadToEnd();
- }
- }
-
- #region IWebRequestHandler Members
-
- public bool CanSupport(DirectWebRequestOptions options) {
- return true;
- }
-
- /// <summary>
- /// Prepares an <see cref="HttpWebRequest"/> that contains an POST entity for sending the entity.
- /// </summary>
- /// <param name="request">The <see cref="HttpWebRequest"/> that should contain the entity.</param>
- /// <returns>
- /// The writer the caller should write out the entity data to.
- /// </returns>
- public Stream GetRequestStream(HttpWebRequest request) {
- return this.GetRequestStream(request, DirectWebRequestOptions.None);
- }
-
- public Stream GetRequestStream(HttpWebRequest request, DirectWebRequestOptions options) {
- this.postEntity = new MemoryStream();
- return this.postEntity;
- }
-
- /// <summary>
- /// Processes an <see cref="HttpWebRequest"/> and converts the
- /// <see cref="HttpWebResponse"/> to a <see cref="Response"/> instance.
- /// </summary>
- /// <param name="request">The <see cref="HttpWebRequest"/> to handle.</param>
- /// <returns>
- /// An instance of <see cref="Response"/> describing the response.
- /// </returns>
- public IncomingWebResponse GetResponse(HttpWebRequest request) {
- return this.GetResponse(request, DirectWebRequestOptions.None);
- }
-
- public IncomingWebResponse GetResponse(HttpWebRequest request, DirectWebRequestOptions options) {
- if (this.Callback == null) {
- throw new InvalidOperationException("Set the Callback property first.");
- }
-
- return this.Callback(request);
- }
-
- #endregion
-
- #region IDirectSslWebRequestHandler Members
-
- public Stream GetRequestStream(HttpWebRequest request, bool requireSsl) {
- ErrorUtilities.VerifyProtocol(!requireSsl || request.RequestUri.Scheme == Uri.UriSchemeHttps, "disallowed request");
- return this.GetRequestStream(request);
- }
-
- public IncomingWebResponse GetResponse(HttpWebRequest request, bool requireSsl) {
- ErrorUtilities.VerifyProtocol(!requireSsl || request.RequestUri.Scheme == Uri.UriSchemeHttps, "disallowed request");
- var result = this.GetResponse(request);
- ErrorUtilities.VerifyProtocol(!requireSsl || result.FinalUri.Scheme == Uri.UriSchemeHttps, "disallowed request");
- return result;
- }
-
- #endregion
- }
-}