Commit 0ac81457 0ac8145730a637fe8e3ae6bf28431d5768258ffb by Christian Gerdes

Added support in a unittest to avoid errors if using begin timer and run as a local unit test.

1 parent 55f0f128
......@@ -49,7 +49,9 @@
<Reference Include="Microsoft.VisualStudio.QualityTools.LoadTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Core">
......@@ -76,6 +78,9 @@
<None Include="LoadTest3.loadtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="LoadTest4.loadtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WebTest22.webtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
......@@ -85,10 +90,9 @@
<None Include="WebTest3.webtest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Shadow Include="Test References\LIL_VSTT_Plugins.accessor" />
<None Include="Userdata.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Resource Include="Userdata.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<None Include="WebTest1.webtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
......
......@@ -19,39 +19,37 @@ namespace TestProject1
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
private bool inLoadTest = false;
private bool dontKnow = true;
[TestInitialize()]
public void CheckTestContextType() {
if (dontKnow)
{
// Check if the TestContext type is the one that a loadtest provides
if (TestContext.GetType().ToString().Equals("Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext"))
inLoadTest = true;
else
inLoadTest = false;
dontKnow = false;
TestContext.WriteLine("We have a loadtest TestContext: " + inLoadTest);
}
}
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
......@@ -62,11 +60,33 @@ namespace TestProject1
[TestMethod]
public void TestMethod1()
{
TestContext.WriteLine("Current Test Context parameters:");
// Parameters
int myThinkTime = 5;
TestContext.WriteLine("# Current Test Context parameters:");
IDictionary<string, object> dic = (IDictionary<string, object>)TestContext.Properties;
foreach (KeyValuePair<string, object> pair in dic)
TestContext.WriteLine(pair.Key + ": " + pair.Value.ToString());
TestContext.WriteLine("End of Current Test Context parameters.");
TestContext.WriteLine("# End of Current Test Context parameters.");
// Get think time from load test provided test context if set
if (TestContext.Properties.Contains("ThinkTime"))
{
myThinkTime = int.Parse(TestContext.Properties["ThinkTime"].ToString());
TestContext.WriteLine("Using thinktime " + myThinkTime + " from test context");
}
// Dummy transaction
TestContext.WriteLine("Starting transaction UnitTestTransaction1");
if (inLoadTest) TestContext.BeginTimer("UnitTestTransaction1");
// Think time
System.Threading.Thread.Sleep(myThinkTime * 1000);
// End transaction
TestContext.WriteLine("Ending transaction UnitTestTransaction1");
if (inLoadTest) TestContext.EndTimer("UnitTestTransaction1");
}
}
}
......