-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Eden
committed
Nov 28, 2016
1 parent
8e96533
commit 88af2cb
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace MartinEden.Quondam.Tests | ||
{ | ||
public class PasswordRecordTests | ||
{ | ||
[TestCase(0, ExpectedResult = true)] | ||
[TestCase(15, ExpectedResult = true)] | ||
[TestCase(30, ExpectedResult = true)] | ||
[TestCase(30.001, ExpectedResult = false)] | ||
[TestCase(60, ExpectedResult = false)] | ||
public bool RecordsOnlyRemainFreshForThirtySeconds(double elapsed) | ||
{ | ||
var noon = DateTime.Today.AddHours(12); | ||
var record = new PasswordRecord("abc", noon); | ||
return record.IsFresh(noon + TimeSpan.FromSeconds(elapsed)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace MartinEden.Quondam.Tests | ||
{ | ||
public class UserStoreTests | ||
{ | ||
private UserStore store; | ||
private const string user = "user"; | ||
|
||
[SetUp] | ||
public void CreateStore() | ||
{ | ||
store = new UserStore(); | ||
} | ||
|
||
[Test] | ||
public void GetPasswordReturnsNullForUnknownUser() | ||
{ | ||
Assert.IsNull(store.GetPassword(user)); | ||
} | ||
|
||
[Test] | ||
public void GetPasswordReturnsStoredPassword() | ||
{ | ||
string password = "swordfish"; | ||
var time = DateTime.Today; | ||
store.StorePassword(user, password, time); | ||
var record = store.GetPassword(user); | ||
checkRecord(password, time, record); | ||
} | ||
|
||
[Test] | ||
public void AfterClearPasswordGetPasswordReturnsNull() | ||
{ | ||
string password = "swordfish"; | ||
var time = DateTime.Today; | ||
store.StorePassword(user, password, time); | ||
store.ClearPassword(user); | ||
Assert.IsNull(store.GetPassword(user)); | ||
} | ||
|
||
[Test] | ||
public void CanStorePasswordsForMultipleUsers() | ||
{ | ||
string password1 = "cake"; | ||
string password2 = "cherry"; | ||
string user1 = "alice"; | ||
string user2 = "bob"; | ||
var time1 = DateTime.Now; | ||
var time2 = time1.AddSeconds(1); | ||
|
||
store.StorePassword(user1, password1, time1); | ||
store.StorePassword(user2, password2, time2); | ||
checkRecord(password1, time1, store.GetPassword(user1)); | ||
checkRecord(password2, time2, store.GetPassword(user2)); | ||
} | ||
|
||
[Test] | ||
public void StoringNewPasswordOverridesPrevious() | ||
{ | ||
string password1 = "hunter13"; | ||
string password2 = "fsdfeergf4"; | ||
var time1 = DateTime.Now; | ||
var time2 = time1.AddSeconds(1); | ||
|
||
store.StorePassword(user, password1, time1); | ||
store.StorePassword(user, password2, time2); | ||
var record = store.GetPassword(user); | ||
checkRecord(password2, time2, record); | ||
} | ||
|
||
private static void checkRecord(string expectedPassword, DateTime expectedTimestamp, PasswordRecord record) | ||
{ | ||
Assert.IsNotNull(record); | ||
Assert.AreEqual(expectedPassword, record.Password); | ||
Assert.AreEqual(expectedTimestamp, record.Timestamp); | ||
} | ||
} | ||
} |