diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-17 21:44:30 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-17 21:44:30 -0800 |
commit | a16b9b9222da75b43a44cfde9de912bba4c09670 (patch) | |
tree | 5429e7a464fa77bf61ce111efe686183745e3537 /src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs | |
parent | 9a77154c54439bacd06938e2c0624c69d4e48c69 (diff) | |
parent | cdb850c6cf90381e6db75365272b7d65ef5fe359 (diff) | |
download | DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.zip DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.gz DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.bz2 |
Merge branch 'master' into master-Dev10
Conflicts:
build.proj
lib/DotNetOpenAuth.BuildTasks.dll
lib/DotNetOpenAuth.BuildTasks.pdb
src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs
src/DotNetOpenAuth.sln
src/DotNetOpenAuth.vsmdi
src/DotNetOpenAuth/OAuth/OAuthStrings.Designer.cs
Diffstat (limited to 'src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs b/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs deleted file mode 100644 index a293895..0000000 --- a/src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs +++ /dev/null @@ -1,99 +0,0 @@ -//----------------------------------------------------------------------- -// <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 NUnit.Framework; - - [TestFixture] - public class MultipartPostPartTests : TestBase { - /// <summary> - /// Verifies that the Length property matches the length actually serialized. - /// </summary> - [TestCase] - public void FormDataSerializeMatchesLength() { - var part = MultipartPostPart.CreateFormPart("a", "b"); - VerifyLength(part); - } - - /// <summary> - /// Verifies that the length property matches the length actually serialized. - /// </summary> - [TestCase] - 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> - [TestCase] - 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> - [TestCase] - 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) { - TestUtilities.TestLogger.InfoFormat("{0}: {1}", header, req.Headers[header]); - } - TestUtilities.TestLogger.InfoFormat(handler.RequestEntityAsString); - Assert.AreEqual(req.ContentLength, handler.RequestEntityStream.Length); - posted = true; - return null; - }; - request.PostMultipart(handler, parts); - Assert.IsTrue(posted, "HTTP POST never sent."); - } - } -} |