We are using AutoMapper to map from IDataReader to List of Entities.
One Problem that i noticed while unit testing was the following. If we read an bool value from database (bit), AutoMapper does verry fine. But when we us FluentAssertions for UnitTesting there is a problem with the ShouldAllBeEquivalentTo function. It says True expected but True returned on the bool property of the entity.
So i tried to check the bool properties and noticed that expected == returnd
works (returns true
) but expected.Equals(returned)
does not work (returns false
)?!
I thought ==
and equals
should be almost the same for bool type?
What could cause this strange behaviour?
Here some code:
using (var connection = new SqlConnection("server=someServer;user id=someUser;password=***;database=someDatabase;MultipleActiveResultSets=True"))
using (var command = connection.CreateCommand())
{
connection.Open();
var itemsBefore = new List<Item> { new Item { CheckDispo = true } };
command.CommandText = "SELECT CheckDispo FROM Items WHERE ItemId = 1814";
var itemsAfter = Mapper.DynamicMap<List<Item>>(command.ExecuteReader());
var a = itemsAfter[0].CheckDispo.Equals(true); // false
var b = itemsAfter[0].CheckDispo == true; // true
}
public class Item
{
public bool CheckDispo { get; set; }
}