c# - Integration Test for Data access Layer with Entity Framework code-first -


iam is starting to write tests for my data access layer and I'm looking for the best practice.

Now iam testing with an actual DB which is an auto generated from EF, every time my model meets some differences (code-defined with fluent mapping before) but it is difficult to do so with many developers Each individual has different objects developed.

> 1) So is there a way to use something in the memory database?
a) If no connection string has been used in my test project, then it is seen that all the work is fine but where is the DB made?
B) EF make it once for each test or only when the first test is started? Can I make it clear?
c) How can DB be removed?

2) What do I have to do?
a) In my previous application, I have made many mistakes in the DB column in Mapping Object Property, so there is one thing to test it: maybe I can make an object, save it in DB, DB I can read it and check that I have written what I have written to read all the properties
b) I think I will use the repository pattern, so with every operation of CRYOUD operation GJ will have a retail repository, I have to test this CRUD or does it mean IITFrimKarkwork test?
c) After some time, I get many inventory. There is a method in my repository so I have to include some fake figures in my DB and try to ask against them to test my method?
D) Other things for testing?

Thanks

Edit: I have a small example:

If I map to my class:

  MyClass { Public integer MyClassIdField public string MyClassDescriptionField} table with field  int_T01_Table1Id 
nvc_T01_Table1Descri

Other questions:

Strong> When IIM is inserted into DB, can I use my domain layer object directly or do I have to duplicate them?


Edit 2: is to use an object constructor that could not work using a local DB in IIM and To find other issues: i Create a class like this:

  var fixture = new fixture (); MyClass c = New MyClass (); C.id = stability Create & lt; Int & gt; (); C.endDate = fixture.Create & lt; DateTime? & Gt; (); Context.MyClass.Add (c); Context.SaveChanges (); Context.Dispose (); // DB to emphasize EF queries on context = New Mycotex (); MyClass Real = Reference MyClass.Find (c.Id); // convinced real. Datafin value. (). (Target DataFine.Value);  

But the test failed with this error:
Failure: expected date and time <2014-02-22 16: 14: 53.901>, but found & lt; 2014- 02-22 16: 14: 53.900>.

If the test of the subject is not successful, then how can the data change?

A good rule of thumb is not to test outside the unit test code. Your scope means the database Do not test, but for example duplicate the database with a funny library.

EDIT: If you want to test the database for integration testing, you have to use the actual database, otherwise you will not check the database engine, but will make a joke, which will test your test. Will not miss the target. To use an MDF-file, as you mention, it is an approach that will work.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -