summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenId.Test/Extensions/SimpleRegistrationTests.cs
blob: f08a047659cd41e52abf6e8905c938cbd50e51e2 (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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using DotNetOpenId.Extensions.SimpleRegistration;
using NUnit.Framework;

namespace DotNetOpenId.Test.Extensions {
	[TestFixture]
	public class SimpleRegistrationTests : ExtensionTestBase {
		[Test]
		public void None() {
			var response = ParameterizedTest<ClaimsResponse>(
				TestSupport.Scenarios.ExtensionFullCooperation, Version, null);
			Assert.IsNull(response);
		}

		[Test]
		public void Full() {
			var request = new ClaimsRequest();
			request.FullName = DemandLevel.Request;
			request.Email = DemandLevel.Require;
			var response = ParameterizedTest<ClaimsResponse>(
				TestSupport.Scenarios.ExtensionFullCooperation, Version, request);
			Assert.AreEqual("Andrew Arnott", response.FullName);
			Assert.AreEqual("andrewarnott@gmail.com", response.Email);
		}
		[Test]
		public void Partial() {
			var request = new ClaimsRequest();
			request.FullName = DemandLevel.Request;
			request.Email = DemandLevel.Require;
			var response = ParameterizedTest<ClaimsResponse>(
				TestSupport.Scenarios.ExtensionPartialCooperation, Version, request);
			Assert.IsNull(response.FullName);
			Assert.AreEqual("andrewarnott@gmail.com", response.Email);
		}

		[Test]
		public void Birthdates() {
			var response = new ClaimsResponse();
			// Verify that they both start out as null
			Assert.IsNull(response.BirthDateRaw);
			Assert.IsFalse(response.BirthDate.HasValue);

			// Verify that null can be set.
			response.BirthDate = null;
			response.BirthDateRaw = null;
			Assert.IsNull(response.BirthDateRaw);
			Assert.IsFalse(response.BirthDate.HasValue);

			// Verify that the strong-typed BirthDate property can be set and that it affects the raw property.
			response.BirthDate = DateTime.Parse("April 4, 1984");
			Assert.AreEqual(4, response.BirthDate.Value.Month);
			Assert.AreEqual("1984-04-04", response.BirthDateRaw);

			// Verify that the raw property can be set with a complete birthdate and that it affects the strong-typed property.
			response.BirthDateRaw = "1998-05-08";
			Assert.AreEqual("1998-05-08", response.BirthDateRaw);
			Assert.AreEqual(DateTime.Parse("May 8, 1998", CultureInfo.InvariantCulture), response.BirthDate);

			// Verify that an partial raw birthdate works, and sets the strong-typed property to null since it cannot be represented.
			response.BirthDateRaw = "2000-00-00";
			Assert.AreEqual("2000-00-00", response.BirthDateRaw);
			Assert.IsFalse(response.BirthDate.HasValue);
		}

		[Test, ExpectedException(typeof(ArgumentException))]
		public void InvalidRawBirthdate() {
			var response = new ClaimsResponse();
			response.BirthDateRaw = "2008";
		}
	}
}