logo
down
shadow

No connectionString could be found in the test project application config file


No connectionString could be found in the test project application config file

Content Index :

No connectionString could be found in the test project application config file
Tag : chash , By : kennystone
Date : November 23 2020, 12:01 PM

may help you . It is not the case that it will pick it up from your Web application by default.
It will be looking for it in the current project where it is running.
public class RoleController : Controller
   {
      private IRoleRepository roleRepository;

      // This constructor would not be needed if you were to use IOC container
      public RoleController ()
      {
         this.roleRepository = new RoleRepository(new RoleContext());
      }

      public RoleController(IRoleRepository studentRepository)
      {
         this.roleRepository = roleRepository;
      }
      ....
[TestClass]
public class RoleControllerTest
{
    private Mock<IRoleRepository> _roleRepository;

    [SetUp]
    public void SetUp()
    {
    _roleRepository = new Mock<IRoleRepository>();

    }



    [TestMethod]
    public void IndexRoleController()
    {
    }
    [TestMethod]
    public void DetailsRoleController()
    {
        RoleController RC = new RoleController(_roleRepository.Object);
        var result = RC.Delete(1);
        Assert.IsNotNull(result);
    }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Can a unit test project load the target application's app.config file?


Tag : chash , By : firebasket
Date : March 29 2020, 07:55 AM
like below fixes the issue The simplest way to do this is to add the .config file in the deployment section on your unit test.
To do so, open the .testrunconfig file from your Solution Items. In the Deployment section, add the output .config files from your project's build directory (presumably bin\Debug).

appharbor test project app.config file does not change its connectionstring


Tag : unit-testing , By : Ir0nh1de
Date : March 29 2020, 07:55 AM
I hope this helps . The connectionstring is only inserted when your code is deployed. In general, you shouldn't hit your database or do other external I/O during unit testing.

No connectionstring named '' could be found in the application config file


Tag : chash , By : Sandip
Date : March 29 2020, 07:55 AM
this one helps. I've found a simple solution for that. You have to remove "name=" from the parameter string when you call entities constructor's base constructor. So you have to change this:
public partial class SalesContext : DbContext 
{ 
    public SalesContext() 
        : base("name=SalesContext") 
    { 
    }
public partial  class SalesContext : DbContext 
{ 
    public SalesContext() 
        : base("SalesContext") 
    { 
    }

After EXE installed 'No connection string named 'ConnectionString' could be found in the application config file'


Tag : winforms , By : user180941
Date : March 29 2020, 07:55 AM
this one helps. Is there two connection string in web.config. if is there remove one.

Unit Test Project: "No connection string could be found in the application config file"


Tag : asp.net , By : Andrew
Date : March 29 2020, 07:55 AM
To fix this issue When you are executing a unittest, that project is your running application. So that is where the configuration file is read from. And note that you need an app.config, not a web.config.
Related Posts Related QUESTIONS :
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com