summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs24
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs99
3 files changed, 112 insertions, 13 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index f21e4dc..84dfb97 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -137,7 +137,7 @@
<Compile Include="Messaging\EnumerableCacheTests.cs" />
<Compile Include="Messaging\ErrorUtilitiesTests.cs" />
<Compile Include="Messaging\MessageSerializerTests.cs" />
- <Compile Include="Messaging\MultiPartPostPartTests.cs" />
+ <Compile Include="Messaging\MultipartPostPartTests.cs" />
<Compile Include="Messaging\Reflection\MessageDescriptionTests.cs" />
<Compile Include="Messaging\Reflection\MessageDictionaryTests.cs" />
<Compile Include="Messaging\MessagingTestBase.cs" />
diff --git a/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs b/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs
index 95404a4..f87ae59 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="MultiPartPostPartTests.cs" company="Andrew Arnott">
+// <copyright file="MultipartPostPartTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -14,13 +14,13 @@ namespace DotNetOpenAuth.Test.Messaging {
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
- public class MultiPartPostPartTests : TestBase {
+ public class MultipartPostPartTests : TestBase {
/// <summary>
/// Verifies that the Length property matches the length actually serialized.
/// </summary>
[TestMethod]
public void FormDataSerializeMatchesLength() {
- var part = MultiPartPostPart.CreateFormPart("a", "b");
+ var part = MultipartPostPart.CreateFormPart("a", "b");
VerifyLength(part);
}
@@ -32,7 +32,7 @@ namespace DotNetOpenAuth.Test.Messaging {
using (TempFileCollection tfc = new TempFileCollection()) {
string file = tfc.AddExtension(".txt");
File.WriteAllText(file, "sometext");
- var part = MultiPartPostPart.CreateFormFilePart("someformname", file, "text/plain");
+ var part = MultipartPostPart.CreateFormFilePart("someformname", file, "text/plain");
VerifyLength(part);
}
}
@@ -45,9 +45,9 @@ namespace DotNetOpenAuth.Test.Messaging {
using (TempFileCollection tfc = new TempFileCollection()) {
string file = tfc.AddExtension("txt");
File.WriteAllText(file, "sometext");
- this.VerifyFullPost(new List<MultiPartPostPart> {
- MultiPartPostPart.CreateFormPart("a", "b"),
- MultiPartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
+ this.VerifyFullPost(new List<MultipartPostPart> {
+ MultipartPostPart.CreateFormPart("a", "b"),
+ MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
});
}
}
@@ -60,14 +60,14 @@ namespace DotNetOpenAuth.Test.Messaging {
using (TempFileCollection tfc = new TempFileCollection()) {
string file = tfc.AddExtension("txt");
File.WriteAllText(file, "\x1020\x818");
- this.VerifyFullPost(new List<MultiPartPostPart> {
- MultiPartPostPart.CreateFormPart("a", "\x987"),
- MultiPartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
+ this.VerifyFullPost(new List<MultipartPostPart> {
+ MultipartPostPart.CreateFormPart("a", "\x987"),
+ MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
});
}
}
- private static void VerifyLength(MultiPartPostPart part) {
+ private static void VerifyLength(MultipartPostPart part) {
Contract.Requires(part != null);
var expectedLength = part.Length;
@@ -79,7 +79,7 @@ namespace DotNetOpenAuth.Test.Messaging {
Assert.AreEqual(expectedLength, actualLength);
}
- private void VerifyFullPost(List<MultiPartPostPart> parts) {
+ private void VerifyFullPost(List<MultipartPostPart> parts) {
var request = (HttpWebRequest)WebRequest.Create("http://localhost");
var handler = new Mocks.TestWebRequestHandler();
bool posted = false;
diff --git a/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs b/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs
new file mode 100644
index 0000000..f87ae59
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs
@@ -0,0 +1,99 @@
+//-----------------------------------------------------------------------
+// <copyright file="MultipartPostPartTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Messaging {
+ using System.CodeDom.Compiler;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+ using System.IO;
+ using System.Net;
+ using DotNetOpenAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class MultipartPostPartTests : TestBase {
+ /// <summary>
+ /// Verifies that the Length property matches the length actually serialized.
+ /// </summary>
+ [TestMethod]
+ public void FormDataSerializeMatchesLength() {
+ var part = MultipartPostPart.CreateFormPart("a", "b");
+ VerifyLength(part);
+ }
+
+ /// <summary>
+ /// Verifies that the length property matches the length actually serialized.
+ /// </summary>
+ [TestMethod]
+ public void FileSerializeMatchesLength() {
+ using (TempFileCollection tfc = new TempFileCollection()) {
+ string file = tfc.AddExtension(".txt");
+ File.WriteAllText(file, "sometext");
+ var part = MultipartPostPart.CreateFormFilePart("someformname", file, "text/plain");
+ VerifyLength(part);
+ }
+ }
+
+ /// <summary>
+ /// Verifies MultiPartPost sends the right number of bytes.
+ /// </summary>
+ [TestMethod]
+ public void MultiPartPostAscii() {
+ using (TempFileCollection tfc = new TempFileCollection()) {
+ string file = tfc.AddExtension("txt");
+ File.WriteAllText(file, "sometext");
+ this.VerifyFullPost(new List<MultipartPostPart> {
+ MultipartPostPart.CreateFormPart("a", "b"),
+ MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
+ });
+ }
+ }
+
+ /// <summary>
+ /// Verifies MultiPartPost sends the right number of bytes.
+ /// </summary>
+ [TestMethod]
+ public void MultiPartPostMultiByteCharacters() {
+ using (TempFileCollection tfc = new TempFileCollection()) {
+ string file = tfc.AddExtension("txt");
+ File.WriteAllText(file, "\x1020\x818");
+ this.VerifyFullPost(new List<MultipartPostPart> {
+ MultipartPostPart.CreateFormPart("a", "\x987"),
+ MultipartPostPart.CreateFormFilePart("SomeFormField", file, "text/plain"),
+ });
+ }
+ }
+
+ private static void VerifyLength(MultipartPostPart part) {
+ Contract.Requires(part != null);
+
+ var expectedLength = part.Length;
+ var ms = new MemoryStream();
+ var sw = new StreamWriter(ms);
+ part.Serialize(sw);
+ sw.Flush();
+ var actualLength = ms.Length;
+ Assert.AreEqual(expectedLength, actualLength);
+ }
+
+ private void VerifyFullPost(List<MultipartPostPart> parts) {
+ var request = (HttpWebRequest)WebRequest.Create("http://localhost");
+ var handler = new Mocks.TestWebRequestHandler();
+ bool posted = false;
+ handler.Callback = req => {
+ foreach (string header in req.Headers) {
+ TestContext.WriteLine("{0}: {1}", header, req.Headers[header]);
+ }
+ TestContext.WriteLine(handler.RequestEntityAsString);
+ Assert.AreEqual(req.ContentLength, handler.RequestEntityStream.Length);
+ posted = true;
+ return null;
+ };
+ request.PostMultipart(handler, parts);
+ Assert.IsTrue(posted, "HTTP POST never sent.");
+ }
+ }
+}