Skip to content

Commit 89c100d

Browse files
committed
updated unit tests
1 parent 6ef7de2 commit 89c100d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tests/KeyVaultCli.Domain.UnitTests/Entities/VaultTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using KeyVaultCli.Domain.Entities;
2+
using KeyVaultCli.Domain.Exceptions;
23
using KeyVaultCli.Domain.UnitTests.Fakes;
34

45
namespace KeyVaultCli.Domain.UnitTests.Entities;
@@ -36,6 +37,9 @@ public void TestUpdateMasterPassword_Success()
3637
var result = _vault.UpdateMasterPassword("masterPassword", "newMasterPassword");
3738

3839
Assert.IsTrue(result, "Master password should have been updated successfully.");
40+
41+
var oldPasswordWorks = _vault.UpdateMasterPassword("masterPassword", "someOtherPassword");
42+
Assert.IsFalse(oldPasswordWorks, "Old master password should no longer work.");
3943
}
4044

4145
[TestMethod]
@@ -64,12 +68,23 @@ public void TestUpdatePasswordEntry_Success()
6468
var result =
6569
_vault.UpdateAndSavePasswordEntry("testService", "testAccount", "newService", "newAccount", 10,
6670
"newPassword");
67-
var password = _vault.DecryptAndRetrievePassword("newService", "newAccount");
6871

6972
Assert.IsTrue(result, "Password entry should have been updated successfully.");
73+
74+
var password = _vault.DecryptAndRetrievePassword("newService", "newAccount");
7075
Assert.AreEqual("newPassword", password, "Password should have been updated successfully.");
76+
77+
try
78+
{
79+
var oldPassword = _vault.DecryptAndRetrievePassword("testService", "testAccount");
80+
}
81+
catch (PasswordNotFoundException)
82+
{
83+
Assert.IsTrue(true, "Old password entry should no longer exist and thus throw exception.");
84+
}
7185
}
7286

87+
7388
[TestMethod]
7489
public void TestDeleteAllPasswordEntries_Success()
7590
{
@@ -105,5 +120,8 @@ public void TestSearchPasswordEntries_Success()
105120
"Searched password entry should match the service name.");
106121
Assert.AreEqual("testService3", expectedResult2.First().ServiceName,
107122
"Searched password entry should match the service name.");
123+
124+
var nonExistentResult = _vault.SearchPasswordEntries("nonExistentService");
125+
Assert.AreEqual(0, nonExistentResult.Count, "Search result for non-existent service should be an empty list.");
108126
}
109127
}

tests/KeyVaultCli.Domain.UnitTests/Factories/VaultFactoryTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ public void TestCreateVault_withValidMasterPassword_ReturnsVault()
3434

3535
Assert.IsInstanceOfType(result, typeof(IVault),
3636
"Should not create a Vault instance if the master password is incorrect.");
37+
38+
var wrongResult = _vaultFactory.CreateVault("wrongPassword");
39+
Assert.IsNull(wrongResult, "Should not create a Vault instance if the master password is incorrect.");
3740
}
3841
}

0 commit comments

Comments
 (0)