Mocking LINQ To SQL data provider, NotSupportedException in live code

Another “simple” question is about the objects of the unified testing model that use the level of access to data.

When I make fun of my Table<Customer>up IQuerable<ICustomer>, where it is new List<FakeCustomer>().AsQuerable()used as a data store in memory, the following code passes unit test perfectly:

var filteredCustomers = from c in dal.Customers
                        where c.Code.ToUpperInvariant() == "ABC"
                        select c;

When I start the application, I certainly get NotSupportedException(because of ToUpperInvariant()). Perhaps this is a rather lame example, because the problem can be fixed by replacing it ToUpperInvariant()with ToUpper(), but you got this point.

Question: is such inconsistency a “payment” for recording a real unit, but not integration tests? Or maybe I'm doing something wrong, for example. should there be another way to mock the DataContext in such a way as to fully mimic the Linq To SQL DataContext?

I am currently running a test database instead of a layout in memory to catch such errors.

Thanks for your suggestions.

+3
source share
1 answer

Yes, this is exactly the fee that you pay for it, and not for the integration test. Of course, it’s nice to have integration tests, as well as unit tests.

ORM, - SQL Server SQL Server? , ORM - - .

+4

Source: https://habr.com/ru/post/1763160/


All Articles