summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OpenId/Extensions/AttributeExchange/StoreRequestTests.cs
blob: fc486aab32e556be51ea562343e0bc7934e70608 (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
86
//-----------------------------------------------------------------------
// <copyright file="StoreRequestTests.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Test.OpenId.Extensions.AttributeExchange {
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Linq;
	using System.Text;
	using DotNetOpenAuth.Messaging;
	using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
	using NUnit.Framework;

	[TestFixture]
	public class StoreRequestTests {
		/// <summary>
		/// Verifies the constructor behavior.
		/// </summary>
		[TestCase]
		public void Ctor() {
			var req = new StoreRequest();
			Assert.IsFalse(req.Attributes.Any());
		}

		/// <summary>
		/// Verifies the AddAttribute method.
		/// </summary>
		[TestCase]
		public void AddAttributeByValue() {
			var req = new StoreRequest();
			AttributeValues value = new AttributeValues();
			req.Attributes.Add(value);
			Assert.AreSame(value, req.Attributes.Single());
		}

		/// <summary>
		/// Verifies the AddAttribute method.
		/// </summary>
		[TestCase]
		public void AddAttributeByPrimitives() {
			var req = new StoreRequest();
			req.Attributes.Add("http://att1", "value1", "value2");
			AttributeValues value = req.Attributes.Single();
			Assert.AreEqual("http://att1", value.TypeUri);
			Assert.IsTrue(MessagingUtilities.AreEquivalent(new[] { "value1", "value2" }, value.Values));
		}

		/// <summary>
		/// Verifies the Equals method.
		/// </summary>
		[TestCase]
		public void EqualityTests() {
			var req1 = new StoreRequest();
			var req2 = new StoreRequest();
			Assert.AreEqual(req1, req2);

			// Add attributes in different orders deliberately.
			req1.Attributes.Add("http://att1");
			Assert.AreNotEqual(req1, req2);
			req2.Attributes.Add("http://att2");
			Assert.AreNotEqual(req1, req2);
			req1.Attributes.Add("http://att2");
			Assert.AreNotEqual(req1, req2);
			req2.Attributes.Add("http://att1");
			Assert.AreEqual(req1, req2);
		}

		/// <summary>
		/// Verifies that the class is serializable.
		/// </summary>
		[TestCase]
		public void Serializable() {
			var store = new StoreRequest();
			store.Attributes.Add("http://someAttribute", "val1", "val2");
			var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
			var ms = new MemoryStream();
			formatter.Serialize(ms, store);
			ms.Position = 0;
			var store2 = formatter.Deserialize(ms);
			Assert.AreEqual(store, store2);
		}
	}
}