Test that the models are correctly stored at any used level of access to the database or data, as well as in any business logic that is built into the models themselves.
I like to use NUnit + Fluent Assertions to compare the model before and after perseverance (for example, creating and saving a model and ensuring that it displays correctly with all values).
Please note that this is not necessarily a strict retention. Perhaps your model is a presentation model and is mapped to a business object using a mapping. I would also experience it. Basically, you want to verify that the model passed through some level or logic correctly, and not tested the model itself (in addition to any business logic built into it, of course). Testing the language or functions of the compiler framework / operation, as it would be when checking the operation of properties, seems to me a waste of time.
Example:
// arrange var expected = new PersonModel { FirstName = "John", LastName = "Doe", DateOfBirth = DateTime.Now // etc } // act var id = InsertModelAndReturnId(expected); var actual = RetrieveModelById(id); // assert actual.ShouldHave().AllProperties().EqualTo(expected); // ShouldHave is from Fluent Assertions. This line makes sure expected and actual have the same values after being persisted and retrieved
source share