blob: 7f4ec265b3cfe3d4402b2d700261f7af81b9a763 (
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
|
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Threading;
namespace DotNetOpenId.Test {
[TestFixture]
public class AssociationsTest {
byte[] sha1Secret = new byte[CryptUtil.Sha1.HashSize / 8];
Associations assocs;
[SetUp]
public void SetUp() {
assocs = new Associations();
}
[Test]
public void GetNonexistentHandle() {
Assert.IsNull(assocs.Get("someinvalidhandle"));
}
[Test]
public void RemoveNonexistentHandle() {
Assert.IsFalse(assocs.Remove("someinvalidhandle"));
}
[Test]
public void HandleLifecycle() {
Association a = new HmacSha1Association("somehandle", sha1Secret, TimeSpan.FromDays(1));
assocs.Set(a);
Assert.AreSame(a, assocs.Get(a.Handle));
Assert.IsTrue(assocs.Remove(a.Handle));
Assert.IsNull(assocs.Get(a.Handle));
Assert.IsFalse(assocs.Remove(a.Handle));
}
[Test]
public void Best() {
Association a = new HmacSha1Association("h1", sha1Secret, TimeSpan.FromHours(1));
Association b = new HmacSha1Association("h2", sha1Secret, TimeSpan.FromHours(1));
assocs.Set(a);
assocs.Set(b);
// make b the best by making a older
a.Issued -= TimeSpan.FromHours(1);
Assert.AreSame(b, assocs.Best);
// now make a the best
b.Issued -= TimeSpan.FromHours(2);
Assert.AreSame(a, assocs.Best);
}
}
}
|