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

  • SEARCH
  • Home
  • 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 7856479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:43:41+00:00 2026-06-02T20:43:41+00:00

Suppose we have typical repository public class Repository:IRepository<Entity> { public Entity GetById(int id) {

  • 0

Suppose we have typical repository

 public class Repository:IRepository<Entity>
    {
            public Entity GetById(int id)
            {
                //blah
            }

            public IEnumerable<Entity> All()
            {
                //blah
            }

            public void Insert(Entity entity)
            {

            }

            public void Update(Entity entity)
            {
                //blah
            }

            public void Delete(Entity entity)
            {
                //blah
            }
    }

Using MSTest, I want to test repository’s ability to insert and update entities. As soon as it’s concrete Repository, I’m testing against a real DB.

So, when I test Insert method – the strategy is clear

  1. Create new entity
  2. Save it
  3. Fetch entity by id
  4. Assert entity is returned by Repository

But when I’m thinking of Update method test it all gets somewhat tricky.
The main questions are

  • How to ensure DB has already stored objects, that I can fetch and try
    to update?
  • How to test update against an empty database?

Looks like workaround would require some not necessary code and test will get bloated.
Is there any gracious solution?

  • 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-02T20:43:42+00:00Added an answer on June 2, 2026 at 8:43 pm

    Use ClassInitialize TestInitialize, along with ClassCleanup and TestCleanup to pre-populate the database with well-known entities. Then run your Update() tests against them.

    Not sure how to interpret “not necessary code”… It looks like you are going to have to do something to populate your database in order to test the Update() method; at least the use of the attributes listed above allow you to implement the logic required to initialize and clean-up the database without polluting the actual test methods.

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

Sidebar

Related Questions

Suppose I have this class: class Int{ private: int x; public: Int(int i) :
Suppose you have the following Generic class heirarchy: public abstract class GenericBase<T> { T
Suppose I have some code like this: public string SomeMethod(int Parameter) { string TheString
Suppose you have the following object hierarchy: class Vehicle { public: virtual ~Vehicle() {}
Suppose I have a class that looks like this: class Derived : // some
Suppose I have a class that doesn't support memberwise copying so I don't want
Let's suppose I have a struct like this: struct my_struct { int a; int
Suppose you have this table structure: Patient -> PatientTag -> Tag A typical N:M
I have an entity in EF called Registry that I use for throwing all
Suppose I have a macro defined as this: #define FOO(x,y) \ do { int

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.