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
87
88
89
90
91
92
93
94
95
|
//-----------------------------------------------------------------------
// <copyright file="FetchResponseTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.OpenId.Extensions {
using System;
using System.IO;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.Test.OpenId;
using NUnit.Framework;
[TestFixture]
public class FetchResponseTests : OpenIdTestBase {
[TestCase]
public void AddAttribute() {
var response = new FetchResponse();
response.Attributes.Add(new AttributeValues("http://someattribute", "Value1"));
}
[TestCase]
public void AddTwoAttributes() {
var response = new FetchResponse();
response.Attributes.Add(new AttributeValues("http://someattribute", "Value1"));
response.Attributes.Add(new AttributeValues("http://someOtherAttribute", "Value2"));
}
[TestCase, ExpectedException(typeof(ArgumentException))]
public void AddAttributeTwice() {
var response = new FetchResponse();
response.Attributes.Add(new AttributeValues("http://someattribute", "Value1"));
response.Attributes.Add(new AttributeValues("http://someattribute", "Value1"));
}
[TestCase, ExpectedException(typeof(ArgumentNullException))]
public void AddAttributeNull() {
var response = new FetchResponse();
response.Attributes.Add(null);
}
[TestCase]
public void GetAttributeValue() {
var response = new FetchResponse();
// Verify that null is returned if the attribute is absent.
Assert.IsNull(response.GetAttributeValue("http://someattribute"));
// Now add an attribute with no values.
response.Attributes.Add(new AttributeValues("http://someattribute2"));
Assert.IsNull(response.GetAttributeValue("http://someattribute2"));
// Now add an attribute with many values.
response.Attributes.Add(new AttributeValues("http://someattribute3", "a", "b", "c"));
Assert.AreEqual("a", response.GetAttributeValue("http://someattribute3"));
}
[TestCase]
public void EqualityTests() {
var response1 = new FetchResponse();
var response2 = new FetchResponse();
Assert.AreEqual(response1, response2);
response1.UpdateUrl = new Uri("http://updateurl");
Assert.AreNotEqual(response1, response2);
response2.UpdateUrl = new Uri("http://updateurl");
Assert.AreEqual(response1, response2);
// Add attributes in different orders deliberately.
response1.Attributes.Add(new AttributeValues("http://att1"));
Assert.AreNotEqual(response1, response2);
response2.Attributes.Add(new AttributeValues("http://att2"));
Assert.AreNotEqual(response1, response2);
response1.Attributes.Add(new AttributeValues("http://att2"));
Assert.AreNotEqual(response1, response2);
response2.Attributes.Add(new AttributeValues("http://att1"));
Assert.AreEqual(response1, response2);
}
/// <summary>
/// Verifies that the class is serializable.
/// </summary>
[TestCase]
public void Serializable() {
var fetch = new FetchResponse();
fetch.Attributes.Add("http://someAttribute", "val1", "val2");
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
var ms = new MemoryStream();
formatter.Serialize(ms, fetch);
ms.Position = 0;
var fetch2 = formatter.Deserialize(ms);
Assert.AreEqual(fetch, fetch2);
}
}
}
|