NBi
NBi copied to clipboard
External management (config file)- Unable to feed connection string from config file. NUnit Console error / TC error.
Hi All. (Sorry for typing such long epos)
I was trying to configure test suite to feed ConnectionString from config file. Everything ended up working on NUnit GUI but failed when running from NUnit console and on TC build (probably also using console).
Documentation that I based upon: http://www.nbi.io/docs/connection-configuration/
Issues that I needed to find walkaround for:
By using default configuration as per below:
<connection-strings>
<clear />
<add name="def-sut"
connection-string="..." />
<add name="ref-one"
connection-string="..." />
<add name="ref-two"
connection-string="..." />
</connection-strings>
I got following error:
************** Exception Text ************** System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section connection-strings
-- for that reason I added it to the configSections in .config file as per below:
<section name="connection-strings" type="NBi.NUnit.Runtime.NBiSection, NBi.NUnit.Runtime"/>
By adding it to configSections it started to be recognised to the NUnit GUI. but I received other error
NBi.NUnit.Runtime.TestSuite.ExecuteTestCases: System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. Parameter name: Some connection-strings are provided through the config file but the default connection string is trying to reference a connection string named '@def-sut' which has not been found.
This error is bane of my existance (for the record ;) )
I have been trying different setups and noticed that it also worked on GUI upon not adding configSections but defining connections as per .NET documentation as per below format: (using: connectionStrings)
<connectionStrings>
<clear />
<add name="def-sut"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-one"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-two"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
</connectionStrings>
This solved issues on NUnit GUI. Since now on the SQL Server instance that I have tried to reach was being picked up and I was able to run whole test and it passed.
After that I merged my changes to local branch and run it via TC Buld with the same error as last time, that is:
NBi.NUnit.Runtime.TestSuite.ExecuteTestCases: System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. Parameter name: Some connection-strings are provided through the config file but the default connection string is trying to reference a connection string named '@def-sut' which has not been found.
I then investigated the error using NUnit console with the same error message. (on GUI everything is working fine still). Problem is that I need for it to be running on TC build for test purposes.
Whole solution - with all the code - it should be working with no issues on GUI
.Nbits part
<?xml version="1.0" encoding="utf-8" ?>
<testSuite name="MyTestSuite"
xmlns="http://NBi/TestSuite">
<settings>
<!--change settings according to your need-->
<default apply-to="system-under-test">
<connection-string>@def-sut</connection-string>
</default>
<!--<default apply-to="system-under-test"><connectionString>Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes</connectionString></default>-->
<default apply-to="assert">
<connectionString>Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes</connectionString>
</default>
</settings>
<!--define your tests here under-->
<test name="My first test">
<system-under-test>
<execution>
<query>select 'ok'</query>
</execution>
</system-under-test>
<assert>
<equalTo>
<column index="0" role="key" type="text"/>
<query>
SELECT 'ok'</query>
</equalTo>
</assert>
</test>
</testSuite>
Config file part:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nbi" type="NBi.NUnit.Runtime.NBiSection, NBi.NUnit.Runtime"/>
<section name="connection-strings" type="NBi.NUnit.Runtime.NBiSection, NBi.NUnit.Runtime"/>
</configSections>
<nbi testSuite="TestSuite.nbits"/>
<connection-strings>
<clear />
<add name="def-sut"
connection-string="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-one"
connection-string="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-two"
connection-string="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
</connection-strings>
<connectionStrings>
<clear />
<add name="def-sut"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-one"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
<add name="ref-two"
connectionString="Data Source=XXX;Initial Catalog=YYY;Trusted_Connection=yes" />
</connectionStrings>
</configuration>
Error Message from NUnit Console:
System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values.\nParameter name: No connection-string is provided through the config file. The default connection string stipulated in the nbits file is trying to reference a connection string named '@def-sut'
Versioning:
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup>
Project:
<NUnitProject>
<Settings activeconfig="Default" processModel="Default" domainUsage="Default" />
<Config name="Default" binpathtype="Auto" appbase="." configfile="LOCALCONFIG.config">
<assembly path="NBi.NUnit.Runtime.dll" />
</Config>
</NUnitProject>
Hope that above feels readable. Cheers,
There is an issue in the doc. The right synatx is indeed <connectionStrings>
and not <connection-strings>
in the config file. You can check at https://github.com/Seddryck/NBi/blob/develop/NBi.Testing/ConnectionString.config
I'd recommend to not have both <connectionStrings>
and <connection-strings>
in the config file and remove the section <section name="connection-strings" type="NBi.NUnit.Runtime.NBiSection, NBi.NUnit.Runtime"/>
Hi @Seddryck,
So if I only use <connectionStrings>
as you mentioned and if I delete <section name="connection-strings" type="NBi.NUnit.Runtime.NBiSection, NBi.NUnit.Runtime"/>
I will still have the error: (and now I have no clue how to get around it)
NBi.NUnit.Runtime.TestSuite.ExecuteTestCases: System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. Parameter name: Some connection-strings are provided through the config file but the default connection string is trying to reference a connection string named '@def-sut' which has not been found.
That error will appear on NUnit console - on GUI everything will be working fine though. We have tried investigating it with many configurations, couple of deelopers tried to help me with it with no success.
The config file is probably not found when using the console file. To help you I'd need the project file, config file and the folder structure.
Hi @Seddryck ,
Please see attached project with the folder structure. (I have removed 'Packages' folder as the zipped file was too big with it)
Packages file included:
NBI_Config_PoC.zip
Test is configured in such way that TC runs on files that are built to: NBI_Config_PoC\NBI_Config_PoC\bin\Debug
@Seddryck did you have a chance to take a look into that issue?