I have this class with its constructor
public class BankAccount
{
public int Id { get; private set; }
public int BankAccountNo { get; private set; }
public decimal Balance { get; private set; }
public BankAccount(int BankAccountNo, decimal Balance)
{
this.BankAccountNo = BankAccountNo;
if(Balance <= 0)
{
throw new ArgumentException("Create bank account failed. Balance should be more than zero.");
}
this.Balance = Balance;
}
}
I have created xunit unit test for check object equality
public class BankAccountTest { private BankAccount _bankAccount;
public BankAccountTest()
{
_bankAccount = new BankAccount();
}
[Theory, MemberData(nameof(BankAccountConstructorShouldPass_Data))]
public void BankAccountConstructorShouldPass(BankAccount account, BankAccount accountExpected)
{
// Act
_bankAccount = new BankAccount(account.BankAccountNo, account.Balance);
// Assert
Assert.Equal<BankAccount>(accountExpected,_bankAccount);
}
public static TheoryData<BankAccount, BankAccount> BankAccountConstructorShouldPass_Data()
{
return new TheoryData<BankAccount, BankAccount>
{
{
new BankAccount(123, 250.00M),
new BankAccount(123, 250.00M)
},
{
new BankAccount(321, 150.50M),
new BankAccount(321, 150.50M)
}
};
}
}
When I run the test, it failed with error
Assert.Equal() Failure
Expected: BankAccount { Balance = 250.00, BankAccountNo = 123, Id = 0 }
Actual: BankAccount { Balance = 250.00, BankAccountNo = 123, Id = 0 }
I tried with Assert.True(accountExpected.Equals(_bankAccount));
but no success still.