1
//-----------------------------------------------------------------------
2 // <copyright file="MessagingUtilitiesTests.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.Test
.Messaging
10 using System
.Collections
.Generic
;
11 using System
.Collections
.Specialized
;
15 using DotNetOpenAuth
.Messaging
;
16 using Microsoft
.VisualStudio
.TestTools
.UnitTesting
;
19 public class MessagingUtilitiesTests
: TestBase
{
21 public void CreateQueryString() {
22 var args
= new Dictionary
<string, string>();
24 args
.Add("c/d", "e/f");
25 Assert
.AreEqual("a=b&c%2fd=e%2ff", MessagingUtilities
.CreateQueryString(args
));
29 public void CreateQueryStringEmptyCollection() {
30 Assert
.AreEqual(0, MessagingUtilities
.CreateQueryString(new Dictionary
<string, string>()).Length
);
33 [TestMethod
, ExpectedException(typeof(ArgumentNullException
))]
34 public void CreateQueryStringNullDictionary() {
35 MessagingUtilities
.CreateQueryString(null);
39 public void AppendQueryArgs() {
40 UriBuilder uri
= new UriBuilder("http://baseline.org/page");
41 var args
= new Dictionary
<string, string>();
43 args
.Add("c/d", "e/f");
44 MessagingUtilities
.AppendQueryArgs(uri
, args
);
45 Assert
.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff", uri
.Uri
.AbsoluteUri
);
48 MessagingUtilities
.AppendQueryArgs(uri
, args
);
49 Assert
.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff&g=h", uri
.Uri
.AbsoluteUri
);
52 [TestMethod
, ExpectedException(typeof(ArgumentNullException
))]
53 public void AppendQueryArgsNullUriBuilder() {
54 MessagingUtilities
.AppendQueryArgs(null, new Dictionary
<string, string>());
58 public void AppendQueryArgsNullDictionary() {
59 MessagingUtilities
.AppendQueryArgs(new UriBuilder(), null);
63 public void ToDictionary() {
64 NameValueCollection nvc
= new NameValueCollection();
67 nvc
[string.Empty
] = "emptykey";
68 Dictionary
<string, string> actual
= MessagingUtilities
.ToDictionary(nvc
);
69 Assert
.AreEqual(nvc
.Count
, actual
.Count
);
70 Assert
.AreEqual(nvc
["a"], actual
["a"]);
71 Assert
.AreEqual(nvc
["c"], actual
["c"]);
74 [TestMethod
, ExpectedException(typeof(ArgumentException
))]
75 public void ToDictionaryWithNullKey() {
76 NameValueCollection nvc
= new NameValueCollection();
79 nvc
.ToDictionary(true);
83 public void ToDictionaryWithSkippedNullKey() {
84 NameValueCollection nvc
= new NameValueCollection();
87 var dictionary
= nvc
.ToDictionary(false);
88 Assert
.AreEqual(1, dictionary
.Count
);
89 Assert
.AreEqual(nvc
["b"], dictionary
["b"]);
93 public void ToDictionaryNull() {
94 Assert
.IsNull(MessagingUtilities
.ToDictionary(null));
97 [TestMethod
, ExpectedException(typeof(ArgumentNullException
))]
98 public void ApplyHeadersToResponseNullResponse() {
99 MessagingUtilities
.ApplyHeadersToResponse(new WebHeaderCollection(), null);
102 [TestMethod
, ExpectedException(typeof(ArgumentNullException
))]
103 public void ApplyHeadersToResponseNullHeaders() {
104 MessagingUtilities
.ApplyHeadersToResponse(null, new HttpResponse(new StringWriter()));
108 public void ApplyHeadersToResponse() {
109 var headers
= new WebHeaderCollection();
110 headers
[HttpResponseHeader
.ContentType
] = "application/binary";
112 var response
= new HttpResponse(new StringWriter());
113 MessagingUtilities
.ApplyHeadersToResponse(headers
, response
);
115 Assert
.AreEqual(headers
[HttpResponseHeader
.ContentType
], response
.ContentType
);