I am using Entity Frameowrk 6.4.4 and I am calling a stored procedure which returns an ObjectResult and I tried to use NSubstitute and have not been able to mock ObjectResult. Has anybody been able to mock ObjectResult using NSubstitute?
Related
I am trying to execute a stored procedure in a Database First DB in EF Core 2. Can this be done by using the OnModelCreating method of the Context class?
Does anyone have any idea how to import a Postgres function into an ASP.NET MVC model using NPGSQL?
I tried but I get "value out of range" error as the result of executing stored procedure, I tried different version of npgsql and Entity Framework but still no success, any comment?
I have implemented Generic repository and UOW using this link
http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework-in-mvc/
Now I want to call stored procedure.I am using Entity Framework version 5.
Please advice me How to call a stored procedure
I'm creating some test using ms test for an already written routine that use entity framework, and I would like to use the [DataSource] attribute to generate a test routine for a set of data in the database.
My problem is that I can just select a Table and load the single fields in the test, but I would like to fetch directly a set ob ef entities and process directly in the test routine, in a way much more similar to the way the code to test is wrote.
Exist some kind of [EFDatasource] that let me express a Ef query as datasource and use the entity in the test?
thanks,
luca
You should just use a context instance (or service/repository, what have you) in your unit test method and get the entities from it. You can supply the connection string in a config file in the unit test project. This way the test methods will be totally relieved from any connection worries. They just instantiate objects and work with them.
Some will probably comment that this is not unit testing but integration testing and that you should mock the EF context, but that is virtually impossible. Testing EF should be done with... EF.
Is it possible to mock an EF model so that I can test code which uses the model classes without getting rid of LINQ to Entities code strewn throughout my project? Or will it be necessary to set up a test database for the model to hit instead?
You could wrap your LINQ code in Data Access Objects. The DAOs would have separate interface and implementation code. Your test code would mock the DAOs.
If you don't want to do that, you'll need a test DB.