ict.ken.be

 

Posts in Category: Visual Studio

Disabling Missing XML Comment Warnings 

Categories: Visual Studio

Possible solutions to disable missing comment warnings in Visual Studio:

  • Suppress the warning by changing the project settings => Build tab => Errors and warnings => Suppress warnings by entering 1591
  • Uncheck the "XML documentation file" checkbox in project settings => Build tab => Output
  • Suppress the warning via compiler options, in beginning of file: #pragma warning disable 1591 and at end of file: #pragma warning restore 1591
  • Use GhostDoc
  • Add an empty comment :) ///<Summary></Summary>

NuGet install missing references when you have a packages.config 

Categories: Visual Studio
  1. using the PM console, make a copy of your packages.config file
    [xml]$packages = gc packages.config
  2. delete packages.config
  3. install each package
    $packages.packages.package | % { Install-Package -id $($_.id) -Version $($_.version) }

Remember to put the full path to the packages.config and select the correct project from the PM console dropdown !

xcopy exit with code 9009 in Visual Studio post-build 

Categories: Visual Studio

Yep, you probably did some windows updates. Things got a bit more strict, when you are not running command windows as administrator some executables are no longer found. And this is also for your visual studio post build events.

I just added C:\Windows\System32\ in front of the xcopy command and it solved things. In mean time also check that you didn't at some additional line breaks on accident. But if you like, you can also add the system directory back to your windows path. You can find this at computer - properties - advanced system settings - environment variables - system variables - path. 

So for example:
C:\Windows\System32\xcopy /s /y "$(ProjectDir)bin\ken.MojoPortal.HtmlTools.Web.dll" "$(SolutionDir)Web\bin\"

Unit Testing with MSTest - Notes 

by Phani Tipparaju

Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

[TestClass]

[TestMethod]
public void AnEmptyTest() {}

Arrange, Act, Assert (3 A's pattern)

Test Run Configuration:
.testsettings files
Test - Select Active Test Setting

\Common7\IDE\MSTest.exe
/testcontainer:[filename]
/test:[testname]
/testlist:[testlistpath]
/testsettings
http://msdn.microsoft.com/en-us/library/ms182489.aspx#test

Asserts and Testing Lifecycle

Configure a resource shared among your tests (db, object, log)

// once before and after each unit tests.
[TestInitialize]
public void TestInitialize() {}
[TestCleanup]
public void TestCleanUp() {}
//once before and after all tests in the class
[ClassInitialize]
public static void ClassInitialize(TestContext context) {}
[ClassCleanup]
public static void ClassCleanup() {}

//once before and after all tests in assembly
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext context) {}
[AssemblyCleanup]
public static void AssemblyCleanUp() {}

Asserting

Assert.AreEqual(expected, actual, failMessage); // objectOne.Equals(objectTwo)
Assert.AreEqual(expected, actual, delta, failMessage);
Assert.AreEqual(expected, actual, true); // ignore case with strings
Assert.AreSame(a, b); // checks reference then value

CollectionAssert.AllItemsAreNotNull(collection, failMessage);
CollectionAssert.AllItemsAreUnique(collection, failMessage);
CollectionAssert.AreEqual(expected, actual); // compares element by element on reference base
CollectionAssert.AreEquivalent(expected, actual); // order of elements not important
CollectionAssert.IsSubsetOf(subset_collection, collection, failMessage);
StringAssert.Contains("string","find");
StringAssert.Matches("Search for whitespaces", new System.Text.RegularExpressions.Regex(@"\s"));
StringAssert.StartsWith("string","start string");
StringAssert.EndsWith("string","end string");

TestContext

  • Set by runtime
  • Provides information about the unit test run environment
  • Path to deployment directory
  • Test name
  • URL of the web service
  • Page object of asp.net apps
  • Access to data source with data rows
public TestContext TestContext { get; set; }
TestContext.WriteLine("TestRunDirectory: {0}", TestContext.TestRunDirectory);
TestContext.WriteLine("TestName: {0}", TestContext.TestName);
TestContext.WriteLine("Outcome: {0}", TestContext.CurrentTestOutcome);

Data driven unit-test

Test View - RightClick Properties - Data Connection String
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML"),
"|DataDirectory|\\UserDetails.xml", "User", DataAccessMethod.Sequential),
DeploymentItem("UserDetailsEntryTest\\UserDetails.xml"), TestMethod]

string email = Convert.ToString(TestContext.DataRow["email"]);

Web Performance Test 

(since it is not part of the standard visual studio I use Selenium)
Create Web App > Create a test project & add web test > Record the web test > Parameterize - Insert Rules - Dynamic Params - Loops > Run Web Test > Analyse results
Web Tests work at HTTP Layer
Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
Microsoft.VisualStudio.TestTools.WebTesting.ValidationRule
public class MyCustomWebTest : WebTest {}

Unit Test Features

Ordered Tests

  • Appears as a single test in the Test Window (double click to see individual results)
  • Can execute one test many times
  • Used to group tests together, can contain other ordered tests but no load tests.

Generic Tests

  • Integrate Non-VS automated testing tools
  • Can be run from command line
  • Must return a value of Pass or Fail (return 0 is pass all else is fail)
  • Uses your credentials (trust the author and know what the program will do)

Test Attributes (will show up in .trx xml file)

[Owner("Ken")]
[Description("This is for testing")]
[TestProperty("MyCustomVersion","1.0.1.2")]
[TimeOut(1000)] // in milliseconds
[Priority(1)] // not used by the system, but you can use to sort them in the test list editor
[Ignore] // do not run test
[TestCategory("MyCategory")]
[ExpectedException(typeof(DivideByZeroException))]

Relate to Team Foundation Server
[CssIteration] // Classification.Iteration
[CssProjectStructure] // Classification.Area
[WorkItem] // User Story

WebServiceHelper

[Microsoft.VisualStudio.TestTools.UnitTesting.Web.AspNetDevelopmentServer("WcfService1", "path to service")]
public void TestMethod1()
{
var target = new WebServiceTesting.ServiceReference.ServiceClient();
var protocol = new System.Web.Services.Protocols.HttpGetClientProtocol();
protocol.Url = "http://myservice.svc";
Assert.IsTrue(WebServiceHelper.TryUrlRedirection(protocol, testContextInstance, "WcfService1"));
actual = target.GetData(1);
Assert.AreEqual(1,actual);
}

TestConfigurationSection

  • Instead of providing values in code, depend on configuration files
  • Allows flexibility for regions and file formats.

1. Create a app.config
2. Define "TestConfigurationSection"
<configSections>
<section name="microsoft.visualstudio.testtools" type="..." />
</configSections>
3. Define connectionstrings
<connectionStrings>
<add name="MyExcel" connectionstring="Dsn=Excel ..." providerName="System.Data.Odbc" />
</connectionStrings>
4. Define data source
<microsoft.visualstudio.testtools>
<dataSources>
<add name="MyExcelDataSource" connectionstring="MyExcel" dataTable="Sheet1$" dataAccessMethod="Sequential" />
</dataSources>
</microsoft.visualstudio.testtools>
5. Use the "DataSourceAttribute" for the test method
[DataSource("MyExcelDataSource")] instead of using [DataSource]

VisualHG install on Visual Studio 2012 issue 

Categories: Mercurial Visual Studio

After installation you need a “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv/setup, this will bring the VisualHG to your Options - SourceControl - Current Source Control in Visual Studio 2012.

More about Devenv Command Line Switches at Microsoft.

Devenv Command Line Switches

Page 2 of 4 << < 1 2 3 4 > >>