Refactored test helpers to remove TestSupport and move its functionality into OpenIdT...
[dotnetoauth.git] / src / DotNetOpenAuth.Test / OpenId / AssociationsTests.cs
blob65de3e025bbce9b26269c3703e0fc2cf9265df0e
1 //-----------------------------------------------------------------------
2 // <copyright file="AssociationsTests.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth.Test.OpenId {
8 using System;
9 using System.Collections.Generic;
10 using System.Linq;
11 using System.Security.Cryptography;
12 using System.Text;
13 using DotNetOpenAuth.OpenId;
14 using Microsoft.VisualStudio.TestTools.UnitTesting;
16 [TestClass]
17 public class AssociationsTests : OpenIdTestBase {
18 private static readonly HashAlgorithm sha1 = DiffieHellmanUtilities.Lookup(Protocol.Default, Protocol.Default.Args.SessionType.DH_SHA1);
19 private byte[] sha1Secret;
20 private Associations assocs;
22 [TestInitialize]
23 public override void SetUp() {
24 this.sha1Secret = new byte[sha1.HashSize / 8];
25 this.assocs = new Associations();
28 [TestMethod]
29 public void GetNonexistentHandle() {
30 Assert.IsNull(this.assocs.Get("someinvalidhandle"));
33 [TestMethod]
34 public void RemoveNonexistentHandle() {
35 Assert.IsFalse(this.assocs.Remove("someinvalidhandle"));
38 [TestMethod]
39 public void HandleLifecycle() {
40 Association a = HmacShaAssociation.Create(
41 Protocol.Default,
42 Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
43 "somehandle",
44 this.sha1Secret,
45 TimeSpan.FromDays(1));
46 this.assocs.Set(a);
47 Assert.AreSame(a, this.assocs.Get(a.Handle));
48 Assert.IsTrue(this.assocs.Remove(a.Handle));
49 Assert.IsNull(this.assocs.Get(a.Handle));
50 Assert.IsFalse(this.assocs.Remove(a.Handle));
53 [TestMethod]
54 public void Best() {
55 Association a = HmacShaAssociation.Create(
56 Protocol.Default,
57 Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
58 "h1",
59 this.sha1Secret,
60 TimeSpan.FromHours(1));
61 Association b = HmacShaAssociation.Create(
62 Protocol.Default,
63 Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
64 "h2",
65 this.sha1Secret,
66 TimeSpan.FromHours(1));
68 this.assocs.Set(a);
69 this.assocs.Set(b);
71 // make b the best by making a older
72 a.Issued -= TimeSpan.FromHours(1);
73 Assert.AreSame(b, this.assocs.Best);
74 // now make a the best
75 b.Issued -= TimeSpan.FromHours(2);
76 Assert.AreSame(a, this.assocs.Best);