Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:55+00:00 2026-06-17T09:26:55+00:00

I’ve built a data access layer using a generic repository and the unit of

  • 0

I’ve built a data access layer using a generic repository and the unit of work pattern together with Entity Framwork Code First. Unit testing the repositories seems worthless to me so I’ve decided to create some integrations tests instead. To do that I’ve created a project dedicated to the intregrations test and added a custom database initializer, which is going to seed the database with some test data, using a different connection string of course.

My Question is: How and when do I Initialize the database in my test code? I’m using Nunit. Also I like to know – Since my repositories uses a generic implementation – should I test every repository In my Unit Of Work or just choose a random one?

My Code looks like this:

public interface IRepository<T> where T:class, IEntity
{
    void Add(T entity);
    T GetById(int id);
    IQueryable<T> All();
    IQueryable<T> Where(Expression<Func<T, bool>> filter);
    void Update(T entity);
    void Delete(T entity);
}

 public interface IUnitOfWork : IDisposable
 {
        IRepository<Album> Albums { get; }
        IRepository<Genre> Genres { get; }
        IRepository<Artist> Artists { get; }
        void Commit();
  }  

public class EFRepository<T> : IRepository<T> where T : class,IEntity
{
    private DbContext _context;
    private DbSet<T> _set;

    public EFRepository(IMvcStoreContext context)
    {
        if (context == null)
            throw new NullReferenceException("context is null");

        _context = context as DbContext;

        _set = _context.Set<T>();

    }

    public void Add(T newEntity)
    {
        _set.Add(newEntity);
    }

    public T GetById(int id)
    {
        return _set.Find(id);
    }

    public IQueryable<T> All()
    {
        return _set;
    }

    public IQueryable<T> Where(Expression<Func<T, bool>> filter)
    {
        return _set.Where(filter);
    }

    public void Update(T entity)
    {
        throw new NotImplementedException("method not implemented");
    }

    public void Delete(T entity)
    {
        _set.Remove(entity);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:26:56+00:00Added an answer on June 17, 2026 at 9:26 am

    I came here looking for the answer to your second question, so I don’t have the answer to that one.
    For database testing, I use NDBUnit.
    I put the setup and teardown in the TestFixureXXX methods so I only have to seed the database once per test; this makes the slow tests run a little faster. If you need help with NDBUnit let me know.

    Eric

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.