Skip to content

Commit

Permalink
updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeierKevin committed Apr 30, 2024
1 parent 6ef7de2 commit 89c100d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/KeyVaultCli.Domain.UnitTests/Entities/VaultTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KeyVaultCli.Domain.Entities;
using KeyVaultCli.Domain.Exceptions;
using KeyVaultCli.Domain.UnitTests.Fakes;

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

Assert.IsTrue(result, "Master password should have been updated successfully.");

var oldPasswordWorks = _vault.UpdateMasterPassword("masterPassword", "someOtherPassword");
Assert.IsFalse(oldPasswordWorks, "Old master password should no longer work.");
}

[TestMethod]
Expand Down Expand Up @@ -64,12 +68,23 @@ public void TestUpdatePasswordEntry_Success()
var result =
_vault.UpdateAndSavePasswordEntry("testService", "testAccount", "newService", "newAccount", 10,
"newPassword");
var password = _vault.DecryptAndRetrievePassword("newService", "newAccount");

Assert.IsTrue(result, "Password entry should have been updated successfully.");

var password = _vault.DecryptAndRetrievePassword("newService", "newAccount");
Assert.AreEqual("newPassword", password, "Password should have been updated successfully.");

try
{
var oldPassword = _vault.DecryptAndRetrievePassword("testService", "testAccount");
}
catch (PasswordNotFoundException)
{
Assert.IsTrue(true, "Old password entry should no longer exist and thus throw exception.");
}
}


[TestMethod]
public void TestDeleteAllPasswordEntries_Success()
{
Expand Down Expand Up @@ -105,5 +120,8 @@ public void TestSearchPasswordEntries_Success()
"Searched password entry should match the service name.");
Assert.AreEqual("testService3", expectedResult2.First().ServiceName,
"Searched password entry should match the service name.");

var nonExistentResult = _vault.SearchPasswordEntries("nonExistentService");
Assert.AreEqual(0, nonExistentResult.Count, "Search result for non-existent service should be an empty list.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ public void TestCreateVault_withValidMasterPassword_ReturnsVault()

Assert.IsInstanceOfType(result, typeof(IVault),
"Should not create a Vault instance if the master password is incorrect.");

var wrongResult = _vaultFactory.CreateVault("wrongPassword");
Assert.IsNull(wrongResult, "Should not create a Vault instance if the master password is incorrect.");
}
}

0 comments on commit 89c100d

Please sign in to comment.