app.config in nunit test for acceptance testing - nunit

I have written some specflow tests. To get those test to run I need to configure some parts in App.config. Running the test with resharper as test runner in visual studio it works perfectly fine, but when running the test with the NUnit test runner it seems like the App.config is not read and all tests that depends on it fails (in my case that is every test).
Is there possible to get the NUnit test runner to read the app.config specified for a .dll?
UPDATE: I'm using the 2.5.10 version of NUnit.
My app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityMappingsConfiguration" type="OPF.KP.Business.EntitySettings, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<entityMappingsConfiguration>
<entityMappings>
<entityMapping entityShortTypeName="ValidationResult" entityFactoryFullTypeName="OPF.KP.Business.Tests.ValidationResultStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<entityMapping entityShortTypeName="Stillingsmelding" entityFactoryFullTypeName="OPF.KP.Business.FitNesseTests.StillingsmeldingFitNesseStubFactory, OPF.KP.Business.FitNesseTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<entityMapping entityShortTypeName="Stillingsmeldingsfelter" entityFactoryFullTypeName="OPF.KP.Business.StillingsmeldingsfelterFactory, OPF.KP.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<entityMapping entityShortTypeName="IInputModeSettings" entityFactoryFullTypeName="OPF.KP.Business.Tests.SettingsStubFactory, OPF.KP.Business.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</entityMappings>
</entityMappingsConfiguration>
<appSettings>
<add key="ShouldExecuteHistoricValidation" value="true" />
<add key="Kontrollstasjon.ValidatorService.Validate.ExecuteNoEnhetDuplicationVerification" value="false" />
</appSettings>
<specFlow>
<language feature="no" />
</specFlow>
</configuration>

Related

devexpress xaf database from SQL SERVER to POSTGRESQL

I'm trying to execute the most basic XAF example from devexpress website with PostgreSQL. How can I do it? I've added Entityframework6.Npgsql (from https://www.nuget.org/packages/EntityFramework6.Npgsql/) to sampleErp.Module project and changed the file app.config in project sampleErp.Win. I've also added EntityFramework6.Npgsql to the GAC.
Here is my app.config file:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="Modules" value="" />
<add key="NewVersionServer" value="" />
<add key="EnableDiagnosticActions" value="False" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<connectionStrings>
<add name="EasyTestConnectionString" connectionString="Server=127.0.0.1;User Id=postgres;Password=postgres;Database=mobi03xaf;" providerName="System.Data.EntityClient" />
<add name="ConnectionStringEF" connectionString="Server=127.0.0.1;User Id=postgres;Password=postgres;Database=mobi03xaf;" providerName="System.Data.EntityClient" />
<add name="ConnectionString" connectionString="Server=127.0.0.1;User Id=postgres;Password=postgres;Database=mobi03xaf;" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider"
invariant="Npgsql"
support="FF"
description=".Net Framework Data Provider for Postgresql"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<system.diagnostics>
<switches>
<add name="eXpressAppFramework" value="3" />
</switches>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
I've also installed Npgsql.dll to the GAC by command gacutil /i path\npgsql.dll.
Here is log of the command:
gacutil /l
Npgsql, Version=3.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL.
But when I try execute project, I'm getting the following error:
InnerException:
Type: InvalidOperationException
Message: The Entity Framework provider type 'Npgsql.NpgsqlServices, EntityFramework6.Npgsql' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Data: 0 entries
Stack trace:
How can I solve this problem?

Why is Migrations looking for Sql Server Provider?

Here is my config...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DataContext" connectionString="Server=localhost;Port=5432;Database=myDatabase;User Id=postgres;Password=password;Preload Reader = true;" providerName="Npgsql" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
</configuration>
When I run update-database it gives at the end of the stack trace...
No Entity Framework provider found for the ADO.NET provider with
invariant name 'System.Data.SqlClient'. Make sure the provider is
registered in the 'entityFramework' section of the application config
file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more
information.
Another error I'm running into when I add to the entityFramework section..
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
Failed to set Database.DefaultConnectionFactory to an instance of the
'Npgsql.NpgsqlFactory, Npgsql' type as specified in the application
configuration.
What am I missing?
You could try using a DbProvidersFactories instead of the connection string:
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
I got this working by adding Entityframework, Npgsql and Npgsql.Entityframework as three individual installs using Nuget. Then the following config...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="[Name of EF Context class]" connectionString="Server=localhost;Port=5432;Database=[Name of existing database];User Id=[username];Password=[password];" providerName="Npgsql" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"></provider>
</providers>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql.EntityFramework" />
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
</configuration>

Unable to find the requested .Net Framework Data Provider. It may not be installed

This morning I suddenly got this exception when trying to add a custom migration step to our EF Code-first migrations:
The ADO.NET provider with invariant name '.NET Framework Data Provider for SQL Server' is either not registered in the machine or application config file, or could not be loaded.
I have no problem executing a update-database against our SQL Server but the add-migration command fails.
We are using.Net 4.5.1 with EF Code First 6.0.1 against SQL Server 2012.
Our configuration file for our data project is this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="Data.StorageContext" connectionString="server=.\MSSQL01;Database=OutageTracking; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Note that Visual Studio 2012 complains about the -element in the -section.
Any thoughts?
Thanks,
/Jesper
".NET Framework Data Provider for SQL Server" is not an invariant name, so some .config file somewhere must be in a bad state

How to tell if using EF5

Am taking a Silverlight / WCF RIA Service project from EF4 to EF5. Target is .NET4.5
Here is a spike - am using a DB First approach. ie create edmx, then use the Domain Services Classes Wizard
So looking good so far as have
EntityFramework (5.0.0.0)
Microsoft.ServiceModel.DomainServices.EntityFramework (4.0.0.0) DbDomainService in here
System.Data.Entity (4.0.0.0)
as opposed to old way of:
EntityFramework (5.0.0.0)
System.Data.Entity (4.0.0.0)
System.ServiceModel.DomainServices.EntityFramework (4.0.0.0) LinqToEntitiesDomainService in here
then have put a simple UI on to access the 2 table db and it worked
Problem: This web.config isn't what I expected:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.serviceModel">
<section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<!-- profile stuff commented out-->
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=aspnet-BusinessApplication5.Web-20130603151851;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="TestDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
I was expecting to have to put in:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Got these bits of config from the following. Perhaps they are all codefirst specific.
https://github.com/jeffhandley/riabooks
http://jeffhandley.com/archive/2012/12/10/RIA-Services-NuGet-Package-Updates-ndash-Including-Support-for-EntityFramework.aspx
http://mcasamento.blogspot.co.uk/2012/10/entity-framework-5-code-first-and-wcf.html
The RIA Services dll is compiled against EF 4, not EF5, so the binding Redirect is used to make everything work. If/when RIA Services is open sourced there will be a new release of RiaServices.EntityFramework that will be compiled against EF 5 and EF 6. One of the benefits of open source will be the ability to put out as many NuGet packages as I want to support all combinations.

When I add FormsAuthentication to ASP.NET MVC2 site in IIS7.5 I get HTTP 403.14 error

I have written a custom forms authentication module and when I add it to the web.config of my MVC2 application and run under IIS7.5 I get the HTTP 403.14 error. If I try to navigate to any of the routed Urls then I simply get a 404 error. The annoying thing is that I did all the testing using Cassini with no problems at all. I have applied all of the fixes from all similar issues to no avail. The problem seems to be that with my module registered Mvc Routing stops working. Clearly it would seem to implicate my module but why has it worked all this time using the built-in webserver? Here is the System.x parts of my web.config:
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Ewdev.Gatekeeper.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=02ca582b160d0e09" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms defaultUrl="/" loginUrl="/Authentication/Login" enableCrossAppRedirects="true" name=".GKAUTH" path="/" requireSSL="false" timeout="1440" />
</authentication>
<membership defaultProvider="GatekeeperMembershipProvider" userIsOnlineTimeWindow="120">
<providers>
<clear />
<add name="GatekeeperMembershipProvider" type="Ewdev.Security.MembershipProviders.GatekeeperMembershipProvider, Ewdev.Gatekeeper.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=02ca582b160d0e09" connectionStringName="Ewdev Database" minRequiredPasswordLength="7" minRequiredAlphabeticCharacters="3" minRequiredAlphabeticCaseChanges="1" minRequiredNumericCharacters="1" minRequiredNonAlphanumericCharacters="0" passwordWordsPolicy="true" passwordHistoryPolicy="13" enablePasswordRetrieval="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" minRequiredUserNameLength="6" minRequiredUserNameAlphabeticCharacters="1" minRequiredUserNameNumericCharacters="0" userNameEnableNonAlphanumeric="true" userNameWordsPolicy="true" />
</providers>
</membership>
<customErrors mode="On" />
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Linq" />
<add namespace="System.Collections.Generic" />
</namespaces>
</pages>
<trace enabled="false" mostRecent="true" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="true" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="Ewdev.Security.GatekeeperFormsAuthenticationModule" preCondition="" />
</modules>
<handlers>
<remove name="MvcHttpHandler" />
<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler" />
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
This is all running on my Windows 7 x64 desktop with VS2010, .NET 4 and Mvc2. I have ASP.NET4 installed/registered in IIS. I suspect you will probably want to know what is in the module but the source is rather long so I do not know which bit would be relevant. It is built to the same API specification as the built-in one but apart from redirecting to the Login page when needed there are no other alterations to the request Url and the error appears when trying to display the home page which is open to everyone. I have read that it might be something to do with non-aspx resources such as script, css, image files as modules are set to be applied to all resource types? Other ideas have been along the lines of my module being called after the Url routing module, but I am not convinced about that one, and thirdly that the Global.asax might not be being called? I am in my 3rd day tearing my hair out on this one, mainly because I estimated 1hr to install the website onto IIS... Doh!
Would appreciate any help I can get and quite happy to rewrite my module if only I could work out what bit IIS does not like. Cassini loves it :-(
I have a solution at last! But it was obscure to the extreme and has taken me best part of a week to guess.
I was convinced the problem had something to do with routing and many people were saying that you needed to add the HTTP Redirection special role. I had already added that as well as HTTP Error and Static Content Compression. The solution in the end was to re-install these 3 roles! It would suggest that the order of installing things in the IIS world is very important because I had already set up IIS7.5 before installing MVC2 (via VS2010 install) and even though I had done the other fix many many times (aspnet_regiis -i for ASP.NET 4.0 x86 and x64) this had not fixed the routing issue. Had I installed VS2010 first (with MVC2 included) and then installed IIS7.5 I suspect I would not have had the problem. Except that, believe it or not, a full re-install of IIS7.5 did NOT fix the problem as I had already tried that several days ago. So to recap and include any other necessary configuration the following are the important fixes:
Ensure you have run aspnet_regiis -i
for both Framework/v4... and
Framework64/v4...
Ensure you have allowed ASP.NET v4
for both 32-bit and 64-bit in IIS
(via the IIS Manager, click on the
Server entry in the tree and go to
ISAPI and CGI Restrictions)
Ensure you have HTTP Error and HTTP
Redirection common HTTP IIS special
roles and Static Content Compression
performance IIS special role
installed. And if you have then
un-install and re-install, this is
what eventually fixed the issue for
me.
Please note: This is also the case for IIS7 as I had to do exactly the same procedure on the production Windows 2008 server. I hope that this helps others to a speedy solution. I will probably now lose my contract as I am so far behind because of this problem.
My original web.config turned out to have several uneccessary entries in it, because I was trying any and every solution that people were coming up with, so the following is the System.x parts of my current and working web.config:
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Ewdev.Gatekeeper.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=02ca582b160d0e09" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms defaultUrl="/" loginUrl="/Authentication/Login" enableCrossAppRedirects="true" name=".GKAUTH" path="/" requireSSL="false" timeout="1440" />
</authentication>
<membership defaultProvider="GatekeeperMembershipProvider" userIsOnlineTimeWindow="120">
<providers>
<clear />
<add name="GatekeeperMembershipProvider" type="Ewdev.Security.MembershipProviders.GatekeeperMembershipProvider, Ewdev.Gatekeeper.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=02ca582b160d0e09" connectionStringName="Ewdev Database" minRequiredPasswordLength="7" minRequiredAlphabeticCharacters="3" minRequiredAlphabeticCaseChanges="1" minRequiredNumericCharacters="1" minRequiredNonAlphanumericCharacters="0" passwordWordsPolicy="true" passwordHistoryPolicy="13" enablePasswordRetrieval="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" minRequiredUserNameLength="6" minRequiredUserNameAlphabeticCharacters="1" minRequiredUserNameNumericCharacters="0" userNameEnableNonAlphanumeric="true" userNameWordsPolicy="true" />
</providers>
</membership>
<customErrors mode="On" />
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Linq" />
<add namespace="System.Collections.Generic" />
</namespaces>
</pages>
<trace enabled="false" mostRecent="true" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="true" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="Ewdev.Security.GatekeeperFormsAuthenticationModule" />
</modules>
</system.webServer>
I can't add a comment to the users own answer (rating too low?). Anyway, after fighting with my server for a long time trying to resolve the 403.14 messages I stumbled across this question. The steps in the answer fixed the issue for me finally.
I'm guessing the part that worked was the installation of the roles as I had tried everything else suggested here and elsewhere.
Much thanks to the user and stackoverflow :)
My guess is that you set your MvcHttpHandler wrong. The path attribute should be * instead of *.mvc