OpenID error direct response messages are now sent with HTTP status codes of 400.
[dotnetoauth.git] / src / DotNetOpenAuth.Test / OpenId / Messages / DirectErrorResponseTests.cs
blob5b8b73fe80a24d246744214fefa72d9b60e55294
1 //-----------------------------------------------------------------------
2 // <copyright file="DirectErrorResponseTests.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth.Test.OpenId.Messages {
8 using System;
9 using DotNetOpenAuth.Messaging;
10 using DotNetOpenAuth.OpenId;
11 using DotNetOpenAuth.OpenId.Messages;
12 using Microsoft.VisualStudio.TestTools.UnitTesting;
13 using System.Net;
15 [TestClass]
16 public class DirectErrorResponseTests : OpenIdTestBase {
17 private DirectErrorResponse response;
19 [TestInitialize]
20 public override void SetUp() {
21 base.SetUp();
23 var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host"));
24 this.response = new DirectErrorResponse(request);
27 [TestMethod]
28 public void ParameterNames() {
29 this.response.ErrorMessage = "Some Error";
30 this.response.Contact = "Andrew Arnott";
31 this.response.Reference = "http://blog.nerdbank.net/";
33 MessageSerializer serializer = MessageSerializer.Get(this.response.GetType());
34 var fields = serializer.Serialize(this.response);
35 Assert.AreEqual(Protocol.OpenId2Namespace, fields["ns"]);
36 Assert.AreEqual("Some Error", fields["error"]);
37 Assert.AreEqual("Andrew Arnott", fields["contact"]);
38 Assert.AreEqual("http://blog.nerdbank.net/", fields["reference"]);
41 /// <summary>
42 /// Verifies that error messages are created as HTTP 400 errors.
43 /// </summary>
44 [TestMethod]
45 public void ErrorMessagesAsHttp400() {
46 var httpStatusMessage = (IHttpDirectResponse)this.response;
47 Assert.AreEqual(HttpStatusCode.BadRequest, httpStatusMessage.HttpStatusCode);