I have a class called HandRank which has an Id property. The Id property is generated by my database.
public class HandRank
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Rank { get; set; }
}
I have a method called GetHandRanks which returns a Dictionary<string, HandRank>
.
In my tests, I am seeding an in memory database. As the Id property is determined by the database, I wish to exclude it from my assertion.
Below is my test but it fails because The Id property is not set in the expectedResult. I am not setting the Id because I do not know what the Id will be when generated by the database.
[Test]
public void Test()
{
// arrange
var expectedResult = new Dictionary<string, HandRank>
{
{ "aaa", new HandRank { Rank = 1} },
{ "bbb", new HandRank { Rank = 2} }
};
// act
var actualResult = _handRankManager.GetHandRanks();
// Assert
actualResult.Should().BeEquivalentTo(expectedResult);
}
I expect that the assertion will need to be something like the below but I cannot get the lambda in the Excluding method correct.
actualResult.Should().BeEquivalentTo(expectedResult, options => options.Excluding(x => x.Values.Id));