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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:16:57+00:00 2026-06-03T03:16:57+00:00

I created a simple Asp.net MVC 4 application I created the NUnit test project

  • 0
  • I created a simple Asp.net MVC 4 application
  • I created the NUnit test project using the visula studio 2010 extension
  • I add a couple of controllers (with the models and views) and the website works fine. It works with Sql Server CE

Now I need to test a controller. I wrote this simple class:

namespace SkateboardShop.Tests.Controllers
{
    [TestFixture]
    class BrandControllerTest
    {

        [Test]
        public void TestDetailsView()
        {

            var controller = new BrandController();
            var result = controller.Details(2) as ViewResult;
            Assert.AreEqual("Details", result.ViewName);

        }

    }
}

When I run this test the NUnit return me this error:

SkateboardShop.Tests.Controllers.BrandControllerTest.TestDetailsView:
System.Data.ProviderIncompatibleException : An error occurred while
getting provider information from the database. This can be caused by
Entity Framework using an incorrect connection string. Check the inner
exceptions for details and ensure that the connection string is
correct. —-> System.Data.ProviderIncompatibleException : The
provider did not return a ProviderManifestToken string. —->
System.Data.SqlClient.SqlException : A network-related or
instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify
that the instance name is correct and that SQL Server is configured to
allow remote connections. (provider: SQL Network Interfaces, error: 26
– Error Locating Server/Instance Specified)

Sure, where the test project get the data provider information?
I add into the app.config file (of the test project) the connection string like this:

<connectionStrings>
    <add name="SkateboardEntities" connectionString="Data Source=d:\Basic\project\asp\SkateboardShop\SkateboardShop\App_Data\SkateboardShop.sdf" providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>

But nothing to do.
Since I’m new in MVC and NUnit, I’m asking, in the first place, if the Unit Test should test real database data and if it’s a good way, how to do that.

Thanks.

  • 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-03T03:16:58+00:00Added an answer on June 3, 2026 at 3:16 am

    In my opinion – you should be having a mock repository/persistance layer for testing.
    In that way – you can have a predictable result set to work against & write tests to.

    An example of this could be your controllers accepting an instance of a repository with code like:

    public class BrandController{
     public BrandController(IBrandRepository repository){...}
    }
    

    You can use any DI + Mock framework to inject the IBrandRepository for unit testing

    But, there are situations where the mock is not sufficient & you do need a physical database for testing.

    In such cases, I would recommend to have a test database which has the same structure, but test data which can be re-seeded/initialized as needed for your unit testing.

    In this case, you could point your config file to the test database for testing & some sort of script or DbInitializer to initialize the database back to the original state etc.

    HTH.

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

Sidebar

Related Questions

using VS 2008 i created a clean asp.net MVC application project and changed nothing
I have created a sample project using ASP.NET MVC 3 Web Application (Razor) template.
I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
I created a sample MVC application using following Template. ASP.NET MVC2 Empty Web Application
I have opened a sample ASP.NET MVC project. In HomeController I have created a
I have a simple ASP.NET MVC 3 application. I have the database I designed
I have written a simple ASP.NET MVC 2 application that stores data and can
I have an ASP.NET MVC (using the release candidate) application that works with a
I'm building an ASP.NET MVC 2 application in C# and i am successfully using

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.