I have a nullable database field of type varchar. I am writing a unit test for a service method that retrieves the value of this field. The service method uses a custom DAL that returns a value of String.Empty if the database field is Null (this is desired behaviour).
In my unit test, I am using a Linq To SQL autogenerated class in order to fetch the actual database value and test it against my service method value. The L2S class assigns the string a value of Nothing if the database field is Null. I am using Assert.Equal to compare the two values, however the assertion fails because a string value of Nothing is not equivalent to an empty String. I want this assertion to pass because they both represent a null database value!
For most database types, the L2S class will expose nullable fields as a Nullable (of T) type, so I would normally test equality simply like this (VB code):
Assert.AreEqual(l2sValue.GetValueOrDefault, myValue, "Values not equivalent.")
However nullable varchars are just exposed as Strings so I can't use GetValueOrDefault on them. So my question is, what is the most elegant way to alter my code to recognise that a string value of Nothing and String.Empty are equivalent for the purposes of this test?