Hi
I have a function:
Public Function UpdatePasswordHistory(ByVal mods As DataSource, ByVal StaffCode As String, ByVal Password As String) As Integer
Dim strSQl As New StringBuilder("Insert into [dbo].[PasswordHistory]([StaffCode],[Password],[DateSet])")
strSQl.Append($"values('{StaffCode}','{EncryptPassword(UCase(Password))}','{System.DateTime.Today.ToString("yyyy-MM-dd")}')")
Return mods.SqlDB.ExecuteNonQuery(strSQl.ToString())
End Function
I want to create 2 tests.
The staffcode is a foreign key so must exists.
If no issues it should return 1. else 0.
My 2 tests always return 0.
I probably done this all wrong
public void UpdatePasswordHistory_Staffcodeexists(){
// Arrange
var mockDS = Mock.Create<DataSource>();
clsSecurity clsSecurity = Mock.Create<clsSecurity>();
string Staffcode = "sahmed";
string password = "test";
Int32 rowsaffetced = 1;
Int32 actualRowsaffected;
Mock.Arrange(() => clsSecurity.UpdatePasswordHistory(mockDS, Staffcode, password)).Returns(rowsaffetced);
actualRowsaffected = new clsSecurity().UpdatePasswordHistory(mockDS, Staffcode, password);
Assert.AreEqual(rowsaffetced,actualRowsaffected);
}
[TestMethod]
public void UpdatePasswordHistory_Staffcodedoesnotexist()
{
// Arrange
var mockDS = Mock.Create<DataSource>();
clsSecurity clsSecurity = Mock.Create<clsSecurity>();
string Staffcode = "InvalidUser";
string password = "test";
Int32 rowsaffetced = 0;
Int32 actualRowsaffected;
Mock.Arrange(() => clsSecurity.UpdatePasswordHistory(mockDS, Staffcode, password)).Returns(rowsaffetced);
actualRowsaffected = new clsSecurity().UpdatePasswordHistory(mockDS, Staffcode, password);
Assert.AreEqual(rowsaffetced, actualRowsaffected);
}