I wish to unit test my business logic is loading the correct data by loading an entity via the business logic and comparing it to an entity loaded directly from the dbcontext.
Assert.AreEqual fails I’m guessing because the entities are loaded as tracked.
I thought that I could possibly use AsNoTracking(), but it didn’t work.
Is there a way of “unwrapping” the entity from entity framework to a POCO?
I’ve read about disabling proxycreation, but is this the only option?
I’m hoping there is something similar (although I realise a completely different concept), to ko.utils.unwrapObservable() in the knockout javascript library.
It is strange integration test (it is not unit test at all because it uses database) – it should be enough to simply define static expectation instead of loading it again from the database. Dynamic tests are more error prone and can hide issues.
To make it work you must override
Equalto compare data not references. Disabling proxy creation will not work because you will still have different reference from your business logic and different reference from tested context (unless you share the context but in such case the test will be even more strange).