summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OAuth/ServiceProviderTests.cs
blob: ae74376ee206c01f9e1ea840ad6eeb1f367be11c (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
//-----------------------------------------------------------------------
// <copyright file="ServiceProviderTests.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Test.OAuth {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using DotNetOpenAuth.Messaging;
	using DotNetOpenAuth.OAuth;
	using NUnit.Framework;

	[TestFixture]
	public class ServiceProviderTests : TestBase {
		/// <summary>
		/// Verifies the CreateVerificationCode method.
		/// </summary>
		[TestCase]
		public void CreateVerificationCode() {
			this.TestCode(VerificationCodeFormat.Numeric, 3, MessagingUtilities.Digits);
			this.TestCode(VerificationCodeFormat.AlphaLower, 5, MessagingUtilities.LowercaseLetters);
			this.TestCode(VerificationCodeFormat.AlphaUpper, 5, MessagingUtilities.UppercaseLetters);
			this.TestCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 8, MessagingUtilities.AlphaNumericNoLookAlikes);
		}

		private void TestCode(VerificationCodeFormat format, int length, string allowableCharacters) {
			string code = ServiceProvider.CreateVerificationCode(format, length);
			TestUtilities.TestLogger.InfoFormat("{0} of length {2}: {1}", format, code, length);
			Assert.AreEqual(length, code.Length);
			foreach (char ch in code) {
				Assert.IsTrue(allowableCharacters.Contains(ch));
			}
		}
	}
}