I have a test project which uses MSTest. And I have a testsettings file and have a properties in that file. as below.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="local" id="77572268-dd99-4f8c-a660-f5c8c1eec977"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Execution>
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
</TestTypeSpecific>
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
<Properties >
<Property name="AAA" value="val1"></Property>
<Property name="BBB" value="val2"></Property>
</Properties>
</TestSettings>
But how can I access these properties in testsettings file values by name in runtime. How can I do that?
This is what currently I'am trying..
[ClassInitialize]
public static void TestClassInitialize(TestContext context)
{
var sad = context.Properties["AAA"].ToString();
}
And it gives following exception
An exception of type 'System.NullReferenceException' occurred in
TestAutomation.dll but was not handled in user code
Additional information: Object reference not set to an instance of an
object.
And this is not about the System.NullReferenceException and this is about how to access a property in a Test settings file in runtime. So this question is not a duplicate.
I suspect you have not properly configured your .runsettings file.
Follow this link .runsettings file configuration and configure the "SettingsFile" section properly.
Alternatively you can also try "TestRunParameters" section to get this working.
The way you are accessing the properties is not correct. You need to use runsettings file instead.
You were close but you dont need the ending tag of the property tag, here is an example:
<Properties>
<Property name="test" value="testValue"/>
</Properties>
Once that is done you can use the same code to access the data:
context.Properties["AAA"].ToString()
Related
I have set up a .nunit file to specify a local and remote test suite App.config. Here is my code :
<NUnitProject>
<Settings activeconfig="local"/>
<Config name="local" configfile="App.config">
<assembly path="bin\Debug\Proj.dll"/>
</Config>
<Config name="remote" configfile="App.Remote.config">
<assembly path="bin\Debug\Proj.dll"/>
</Config>
</NUnitProject>
Now, when I run the following command in my command line
"nunit3-console" "test_runner.nunit" /config:remote
It is still running off of the App.config and not the App.Remote.config file I specified in the Config block.. Am I missing something here? Do I need to have some sort of referance in my App.config?
I missed the reply to my comment! In case you haven't already done so, you should ensure that the config file is copied to the output directory.
I've recently obfuscated a DLL using Dotfuscator CE with Visual Studio 2015 Update 3. Here is the Dotfuscator.xml file I used.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE dotfuscator SYSTEM "http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.3.dtd">
<dotfuscator version="2.3">
<propertylist>
<property name="SourceDirectory" value="This Path Will Be Replaced By Visual Studio" />
<property name="SourceFile" value="This Filename Will Be Replaced By Visual Studio" />
</propertylist>
<input>
<asmlist>
<inputassembly>
<option>library</option>
<file dir="${SourceDirectory}\" name="${SourceFile}" />
</inputassembly>
</asmlist>
</input>
<output>
<file dir="${SourceDirectory}\" />
</output>
</dotfuscator>
Now the problem is, the obfuscated assembly contains some information stored in Settings.settings. file, when my code tries to access data from settings file it fails with this following exception.
The settings property 'ProxyTestURL' was not found
Here is the syntax to read setting:
Dim strURI As String = My.Settings.ProxyTestURL
I know there is a similar question "Dotfuscator : Error after obfuscation" but it doesn't seems to be either complete or robust, though I put my comments there too but here I would expect a second opinion and more robust solution instead of renaming my settings file literals to obfuscated names(as mentioned there).
You should exclude My.Settings from renaming. Instructions for doing so are in the docs.
I am trying to setup a test environment for Orleans that uses SQL Server for liveness. This is my server config file:
<?xml version="1.0" encoding="utf-8" ?>
<OrleansConfiguration xmlns="urn:orleans">
<Globals>
<Liveness LivenessType="SqlServer" DeploymentId="42783519-d64e-44c9-9c29-111111111133" DataConnectionString="Data Source=.\\SQLEXPRESS;Initial Catalog=Orleans;Integrated Security=True;" />
<!--<SeedNode Address="localhost" Port="11111" />-->
</Globals>
<Defaults>
<Networking Address="localhost" Port="11111" />
<ProxyingGateway Address="localhost" Port="30000" />
<Tracing DefaultTraceLevel="Info" TraceToConsole="true" TraceToFile="{0}-{1}.log">
<TraceLevelOverride LogPrefix="Application" TraceLevel="Info" />
</Tracing>
<Statistics MetricsTableWriteInterval="30s" PerfCounterWriteInterval="30s" LogWriteInterval="300s" WriteLogStatisticsToTable="true" />
</Defaults>
<Override Node="Primary">
<Networking Address="localhost" Port="11111" />
<ProxyingGateway Address="localhost" Port="30000" />
</Override>
</OrleansConfiguration>
When I use this config I get this error when running:
MembershipTableGrain cannot run without Seed node - please check your
silo configuration file and make sure it specifies a SeedNode element.
Alternatively, you may want to use AzureTable for LivenessType.
Parameter name: grain = MembershipTableGrain Exception =
System.ArgumentException: MembershipTableGrain cannot run without Seed
node - please check your silo configuration file and make sure it
specifies a SeedNode element. Alternatively, you may want to use
AzureTable for LivenessType.
and further up, the logs say that the Liveness is MembershipTableGrain (which is the default and requires a SeeNode). What am I missing here?
My silo config for SQLServer membership looks like this
<?xml version="1.0" encoding="utf-8"?>
<OrleansConfiguration xmlns="urn:orleans">
<Globals>
<SystemStore SystemStoreType="SqlServer" DeploymentId="YYYYY" DataConnectionString="Server=THESERVER;Database=Orleans;User ID=USER;password=PASSWORD;"/>
</Globals>
<Defaults>
<Networking Address="" Port="11111"/>
<ProxyingGateway Address="" Port="30000"/>
</Defaults>
</OrleansConfiguration>
No need to specify the liveness type. It figures it out by looking at the SystemStoreType.
The client config does need the gateway specified
<ClientConfiguration xmlns="urn:orleans">
<SystemStore SystemStoreType ="SqlServer"
DeploymentId="YYY"
DataConnectionString="Server=THESERVER;Database=Orleans;User ID=USER;password=PASSWORD;" />
<GatewayProvider ProviderType="SqlServer"/>
</ClientConfiguration>
You can also use programmable API for configuration, instead of XML.
I found the problem. That is not how to change the Liveness type. It should be like this:
<SystemStore SystemStoreType="SqlServer" DeploymentId="42783519-d64e-44c9-9c29-111111111133" DataConnectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Orleans;Integrated Security=True;" />
<Liveness LivenessType="SqlServer" />
Also, you must make sure to ref "Microsoft.Orleans.OrleansSqlUtils" NuGet package and run this SQL Create Script
I am writing a test using version 1.2 of Nancy and Nancy.Testing via NuGet. My test is written with NUnit 2.6.4 and looks like this:
[Test]
public async Task ShouldReturnSuccessfullyAuthenticatedUser()
{
// arrange
var request = CreateRequest();
var userDocument = CreateUserDocumentFrom(request);
await userRepository.AddAsync(userDocument);
// act
var response = browser.Post(Paths.Login, with => with.JsonBody(request));
// assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
I have this exception:
System.TypeInitializationException : The type initializer for 'Nancy.Bootstrapper.AppDomainAssemblyTypeScanner' threw an exception.
----> System.IO.DirectoryNotFoundException : Could not find a part of the path 'E:\myProject\bin\Debug\bin\Debug'.
And I think there's something wrong when using Nancy.Testing with NUnit, because the equivalent test in xUnit runs just fine.
It looked like NUnit was tryging to automatically add bin\Debug to the bin path. The way I solved it is to specify explicitly what kind of bin path to use. Here is the .nunit project file:
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" binpathtype="Manual">
<assembly path="bin/Debug/MyUnitTests1.dll" />
<assembly path="bin/Debug/MyUnitTests2.dll" />
</Config>
<Config name="Release" binpathtype="Manual">
<assembly path="bin/Release/MyUnitTests1.dll" />
<assembly path="bin/Release/MyUnitTests2.dll" />
</Config>
</NUnitProject>
The XML attribute NUnitProject\Config\binpathtype had previously a value of Auto. When I changed it to Manual as above the exception was gone and my tests ran successfully.
I'm creating a Custom tag in my web.config. I first wrote the following entry under the configSections section.
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
Castle.Windsor" />
But, when I try to create a castle node inside the configuration node as below
<castle>
<components>
</components>
</castle>
I get the following error message:"*Could not find schema information for the element '**castle'*." "***Could not find schema information for the element '**components'***."
Am I missing something? I can't find why. And, if I run the application anyway, I get the following error "Could not find section 'Castle' in the configuration file associated with this domain."
Ps.// The sample comes from "Pro ASP.NET MVC Framework"/Steven Sanderson/APress ISBN-13 (pbk): 978-1-4302-1007-8" on page 99.
Thank you for the help
============================================================
Since I believe to have done exactly what's said in the book and did not succed, I ask the same question in different terms. How do I add a new node using the above information?
=============================================================================
Thank you. I did what you said and do not have the two warnings. However, I've go a big new warning:
"The element 'configuration' in namespace 'MyWindsorSchema' has invalid child element 'configSections' in namespace 'MyWindsorSchema'. List of possible elements expected: 'include, properties, facilities, components' in namespace 'MyWindsorSchema'."
What you get is not an error that will prevent you from running your application. It is just a warning that Visual Studio emits because it does not know the castle node in a config file. You could use a schema to enable intellisense. Download the Castle Windsor Schema file and take a look at the readme.txt inside. It tells you to put windsor.xsd somewhere on your hard drive and then reference it in the config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="MyWindsorSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="MyWindsorSchema file://S:\Common\Windsor\windsor.xsd">
<configSections>
<section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<components>
</components>
</castle>
</configuration>