Was writing some units using XUnit until that at some points I bumped into something surprising:
let id = Guid.Empty
let contact = {
Name = {
FirstName = "Marcel"
MiddleInitial = None
LastName = "Patulacci"
}
DateOfBith = new DateTime(1850, 12, 25)
Address = {
Address1 = "41 av 8 Mai 1945"
Address2 = None
City = "Sarcelles"
State = None
Zip = "95200"
}
PhoneNumber = {
DialOutCode = 33
LocalNumber = "766030703"
}
Email = "marcel.patulacci@outlook.com"
}
[<Fact>]
let ``Open an account...``() =
let event = Event.AccountOpened({
AccountId = id
Contact = contact
})
let a = [event]
let b = seq { yield event }
Assert.Equal(a, b)
System.NullReferenceException
: Object reference not set to an instance of an object.
It seems surprising especially since considering that the overload used by Assert
is:
public static void Equal<T>(IEnumerable<T> expected, IEnumerable<T> actual)
Which states that:
Verifies that two sequences are equivalent, using a default comparer.
Why are they considered different, and why does Assert.Equal
raise a System.NullReferenceException
?
[EDIT]
System.NullReferenceException
: Object reference not set to an instance of an object. atDomain.Events.AccountOpenedEvent.Equals(Object obj, IEqualityComparer comp)
atDomain.Events.Event.Equals(Object obj, IEqualityComparer comp)
Seems
type PersonalName = {
FirstName: string;
MiddleInitial: string option;
LastName: string;
}
type Address = {
Address1: string;
Address2: string option ;
City: string;
State: string option;
Zip: string;
}
type PhoneNumber = {
DialOutCode : int;
LocalNumber: string
}
type Contact = {
Name: PersonalName;
DateOfBith: DateTime
Email: string;
Address: Address;
PhoneNumber: PhoneNumber
}
type AccountOpenedEvent = {
AccountId: Guid
Contact: Contact
}
type Event =
| AccountOpened of AccountOpenedEvent
It turns out one of the fields of event
was null
, but not event
itself.