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 6377857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:55:44+00:00 2026-05-25T01:55:44+00:00

I am trying to test my real data by actually hitting the database. I

  • 0

I am trying to test my real data by actually hitting the database. I am actually testing my Repository classes. Here is an example of what I am doing;

/// <summary>
/// Summary description for Country
/// </summary>
[TestClass]
public class Country {

    public Country() {
        _countryRepo = new CountryRepository();
    }

    private ICountryRepository _countryRepo;

    [TestMethod]
    public void db_should_return_at_least_one_country_as_approved_all() {

        //Act
        var model = _countryRepo.GetAll();

        //Assert
        Assert.IsTrue(model.Count() >= 1);
    }

    [TestMethod]
    public void db_should_return_at_least_one_country_as_approved_true() { 

        //Act
        var model = _countryRepo.GetAll(ApprovalStatus.Approved);

        //Assert
        Assert.IsTrue(model.Count() >= 1);
    }

    [TestMethod]
    public void db_should_return_Turkey_as_country_name_by_id() {

        //Act
        var model = _countryRepo.GetSingle(1000);

        //Assert
        Assert.AreEqual<string>("Turkey", model.CountryName);

    }

    [TestMethod]
    public void db_should_return_Turkey_as_country_name_by_countryISO3166Code() {

        //Act
        var model = _countryRepo.GetSingle("TR");

        //Assert
        Assert.AreEqual<string>("Turkey", model.CountryName);

    }

    [TestMethod]
    public void db_should_return_Turkey_as_country_name_by_GUID() {

        //Act
        var model = _countryRepo.GetSingle(Guid.Parse("9AF174A6-D0F7-4393-AAAD-B168BADEDB30"));

        //Assert
        Assert.AreEqual<string>("Turkey", model.CountryName);

    }

}

This works pretty well for my needs but wondering if I am doing it right by the book. Is there any other patterns that I really should be following here. I do not want to fake my data, my real intense here is to test my DAL and real production data.

  • 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-05-25T01:55:45+00:00Added an answer on May 25, 2026 at 1:55 am

    Your tests will fail if someone else (or even you) go to your database and create a new approved country or change your country name. You are going to think: “WTH is wrong with my repository, why is it not working as expected?” But yeah, the problem isn’t with the repository.

    When I write tests that hit the database I like to create the DB and load default values at startup and destroy then all right after that. I’m not sure if this is the best alternative, but it works pretty well. The problem with this approach is that it’s slower and there is more to code.

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

Sidebar

Related Questions

I am trying to test a class that manages data access in the database
I am trying to test the likelihood that a particular clustering of data has
I am trying to export an sqlite database to the sdcard. When I test
I have a url in javascript, set as a variable. Like: var imageurl='example.com/test/real/image.jpg'; I
Here is a typical URL I'm trying to rewrite: Example requested URL: http://topleveldomain/search?q=clause1+clause2+clause3&State=FL It
we've got a real confusing problem. We're trying to test an SQL Bulk Load
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
Im trying to test my successfully creates a new user after login (using authlogic).
I'm trying to test the DB2 adapter for BizTalk 2006 (not R2). While trying

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.