How to data bind a Visual Studio 2013 Coded UI Test

Problem I need to run the same Coded UI Test with different data. Solution Data bind your Coded UI Test.  To data bind a test in Visual Studio you just need access to the data source and add attributes to the test. For this example we are going to use a simply CSV file.  So add a new text file to your project with a CSV extension. Create a comma delimited file of the desired data.  Make sure when you save it you first select “Advanced Save Options” from the File menu and select “Unicode (UTF-8 without signature) – Codepage 65001” before you save the file. Now right click on the item in Solution Explorer and select Properties. From the Properties window change the “Copy to Output Directory” to “Copy always”.   To your test you will need to add two attributes.  The first is the DeploymentItem attribute. This attribute takes a single string argument of the name of the CSV file. The second attribute is the DataSource attribute.  This attribute is where you define the class used to read the data, what table to read from and how the data should be accessed.  For a CSV file the first argument will be “Microsoft.VisualStudio.TestTools.DataSource.CSV” which identifies the correct class to use to load the CSV file.  Next we need to let the test know where to find the data with “|DataDirectory|\\data.csv”.  Then we have to identify the table to read the data from with “data#csv”. Finally we have to give it an access method “DataAccessMethod.Sequential”.  The final attribute will look like this: [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential)] With the attributes in place you can now use the DataRow property of the TestContext to access the columns in your CSV for example: TestContext.DataRow["FirstName"].ToString(); Good luck.

How to use string.Format with LINQ Select

When I project new data types using the Select operator I sometimes want to create new strings from the combination of existing properties.  Naturally I turn to string.Format.  However, if you attempt a call like the one below: public object Get(int id) {    return this.db.People.Where(p => p.Id == id)                                         .OrderBy(p => p.LastName)                                         .Select(p => new { FullName = string.Format(“{0} {1}”, p.FirstName, p.LastName) })                                         .ToArray(); } I will get the following error: "LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression." The problem is everything that happens before the .ToArray() is parsed and turned into a command that can be sent to the data source.  However, LINQ nor would the data source have any idea what to do with System.String.Format. There is a very simply solution.  Simply call .ToArray() before you use the Select operator. public object Get(int id) {    return this.db.People.Where(p => p.Id == id)                                         .OrderBy(p => p.LastName)                                         .ToArray()                                         .Select(p => new { FullName = string.Format(“{0} {1}”, p.FirstName, p.LastName)}); }   That simply change will perform the select after the results have been retrieved from the data source.

How to change your default language in Visual Studio

Problem: I want to change my default languge in Visual Studio. Solution: Select Tools / Import and Export Settings... Select Reset all settings Click Next > I suggest backing up your current settings just in case you want them back. Select the default Language setup you want to use Click Finish To verify click File/New Project.  Your desired language is selected by default.