summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs
blob: 63e0d7432a07f02d2537c11cd32d8228cc774411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//-----------------------------------------------------------------------
// <copyright file="ResponseTests.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Test.Messaging {
	using System;
	using System.IO;
	using System.Web;
	using DotNetOpenAuth.Messaging;
	using NUnit.Framework;

	[TestFixture]
	public class ResponseTests : TestBase {
		[TestCase, ExpectedException(typeof(InvalidOperationException))]
		public void RespondWithoutAspNetContext() {
			HttpContext.Current = null;
			new OutgoingWebResponse().Respond();
		}

		[Test]
		public void Respond() {
			StringWriter writer = new StringWriter();
			HttpRequest httpRequest = new HttpRequest("file", "http://server", string.Empty);
			HttpResponse httpResponse = new HttpResponse(writer);
			HttpContext context = new HttpContext(httpRequest, httpResponse);
			HttpContext.Current = context;

			OutgoingWebResponse response = new OutgoingWebResponse();
			response.Status = System.Net.HttpStatusCode.OK;
			response.Headers["someHeaderName"] = "someHeaderValue";
			response.Body = "some body";
			response.Respond();
			string results = writer.ToString();
			// For some reason the only output in test is the body... the headers require a web host
			Assert.AreEqual(response.Body, results);
		}
	}
}