summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/AttributeRequestTests.cs
blob: 48b57279fd360847f55092650ea0c24d8be1c3c6 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//-----------------------------------------------------------------------
// <copyright file="AttributeRequestTests.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Test.OpenId.Extensions {
	using System;
	using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
	using DotNetOpenAuth.Test.OpenId;
	using Microsoft.VisualStudio.TestTools.UnitTesting;

	[TestClass]
	public class AttributeRequestTests : OpenIdTestBase {
		[TestMethod]
		public void CtorDefault() {
			AttributeRequest req = new AttributeRequest();
			Assert.AreEqual(1, req.Count);
			Assert.IsNull(req.TypeUri);
			Assert.IsFalse(req.IsRequired);
		}

		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void CtorEmptyTypeUri() {
			new AttributeRequest(string.Empty);
		}

		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void CtorNullTypeUri() {
			new AttributeRequest(null);
		}

		[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void CtorCountZero() {
			new AttributeRequest(WellKnownAttributes.Contact.Email, false, 0);
		}

		[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void CtorCountNegative() {
			new AttributeRequest(WellKnownAttributes.Contact.Email, false, -1);
		}

		[TestMethod]
		public void CtorFull() {
			var req = new AttributeRequest(WellKnownAttributes.Contact.Email, true, 5);
			Assert.AreEqual(WellKnownAttributes.Contact.Email, req.TypeUri);
			Assert.IsTrue(req.IsRequired);
			Assert.AreEqual(5, req.Count);
		}

		[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void SetCountZero() {
			var req = new AttributeRequest();
			req.Count = 0;
		}

		[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void SetCountNegative() {
			var req = new AttributeRequest();
			req.Count = -1;
		}

		[TestMethod]
		public void EqualityTests() {
			var req1 = new AttributeRequest();
			var req2 = new AttributeRequest();
			Assert.AreEqual(req1, req2);

			req1.IsRequired = true;
			Assert.AreNotEqual(req1, req2);
			req2.IsRequired = true;
			Assert.AreEqual(req1, req2);

			req1.Count = 3;
			Assert.AreNotEqual(req1, req2);
			req2.Count = 3;
			Assert.AreEqual(req1, req2);

			req1.TypeUri = "http://hi";
			Assert.AreNotEqual(req1, req2);
			req2.TypeUri = "http://hi";
			Assert.AreEqual(req1, req2);
		}
	}
}