dotnet thoughts 

a dotnet developer's technical blog

Cloak option missing from source control explorer context menu

Ever noticed some time cloak menu item missing from source control explorer context menu?

Cloak option is missing from source control explorer context menu
Cloak option is missing from source control explorer context menu

Cloaking used to prevent users from viewing specified workspace folders or for folders you do not currently need. Cloaking is useful when you are working with files from two or more branches under a common parent to prevent you from copying files unnecessarily. Finally, cloaking increases performance bandwidth and conserves local disk space by preventing folders and files not used currently from being copied to the local working folder. Today I noticed that I am missing the cloak option for a specific folder. I couldn’t find the reason, because it available for another Folder in same workspace. Later I found that it was because of the mapping of local and source folder are different. Like my TFS path was $Projects/System/Data/Binaries, it should be mapped to C:\Projects\System\Data\Binaries, but I was mapped to some other folder like C:\Projects\System\Data\DataBinaries. And then I changed it via File > Source Control > Workspaces option. After this I got the cloak option. :)

Cloak option of Source control explorer conext menu

Cloak option of Source control explorer conext menu

How to debug Windows Live Writer plugins

This is final post related to live writer plugins and its about debugging the Live writer plugins. While developing I don’t think there is a way we can debug the plugin code. This is after deployment. Initially I faced one issue with options dialog, it was related to object reference issue, I got a message like this.

Plug-in Error occured - Messagebox from Windows Live Writer

Plug-in Error occured - Messagebox from Windows Live Writer

It only shows the exception message, not the stack trace or any other information which helps to find the exception. For debugging, you need to attach the Windows Live writer to Visual Studio(we may need to run visual studio as Administrator) using Attach Process feature of Visual Studio from Debug menu.

Attach Windows Live Writer to Visual Studio

Attach Windows Live Writer to Visual Studio

Happy Programming.

Debugging NUnit Tests in Visual Studio 2010

If you are using NUnit with .Net 4.0 assemblies in Visual Studio 2010, while debugging, you will get this warning from breakpoints locations, “The breakpoint will not currently be hit. No symbols have been loaded for this document”

The breakpoint will not currently be hit. No symbols have been loaded for this document

The breakpoint will not currently be hit. No symbols have been loaded for this document

This issues is because of NUnit loads up in .Net 2.0 and then has to load up the modules in 4.0, so does so under the agent process. The solutionis to force NUnit to run under .Net 4.0. This will can done by modifing the NUnit.exe.config file.

<startup>
	<requiredRuntime version="v4.0.30319" />
</startup>

This will fix the issue, also you are able to debug with breakpoints. If you are running Windows 7, make sure you are opening the NUnit.exe.config file as Administrator. And if your OS is 64 bit, you should modify nunit-x86.exe.config file.

Happy Unit testing :)

Test impact analysis in Visual Studio 2010

Test impact analysis helps developers to identify which all tests should run after code changes. This feature only available in Ultimate and Premium editions and only works with Managed code.

  1. Create a class library project, it is our production code, this library allows numbers to Add and Subtract numbers. And here is the implementation.
    namespace DemoLib
    {
        public class Math
        {
            public int Add(int number1, int number2)
            {
                return number1 + number2;
            }
    
            public int Subtract(int number1, int number2)
            {
                return number1 - number2;
            }
        }
    }
    
  2. And here is the Unit Tests for both add and subtract methods.
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace DemoLib.Test
    {
        [TestClass]
        public class MathTests
        {
            [TestMethod]
            public void TestAdd()
            {
                int first = 10;
                int second = 20;
                int expected = first + second;
                Math math = new Math();
    
                var actual = math.Add(10, 20);
    
                Assert.AreEqual(expected, actual);
            }
    
            [TestMethod]
            public void TestSubtract()
            {
                int first = 10;
                int second = 20;
                int expected = first - second;
                Math math = new Math();
    
                var actual = math.Subtract(10, 20);
    
                Assert.AreEqual(expected, actual);
            }
        }
    }
    

    And here is TestList View

    TestList view

    TestList view

  3. We can get the Test Impact view from Test menu, Windows and Select Test Impact View.
    Test Impact View

    Test Impact View

    As it mentioned in the Test Impact View window, we need to enable the Test Impact.

  4. To enable Test Impact, edit the Test settings, from Test menu, which will open the Test Settings dialog. Select the Data and Diagnostics option from the left side. And check the Test Impact checkbox from the Grid.

    Test settings dialog

    Test settings dialog

  5. After enabling Test Impact, using the Test Setting window, select the Test Impact window, now we are ready to track the test impact for that we need to run the unit tests cases.

    Test Impact view after enabling Test Impact

    Test Impact view after enabling Test Impact

  6. Now run the unit test cases to enable tracking.
  7. Now I am modifying the source code, like the following.
    public int Add(int number1, int number2)
    {
        return System.Math.Abs(number1) + System.Math.Abs(number2);
    }
    

    Instead of adding the numbers directly, now I am adding the positive numbers, by taking absolute values. After changing the code, build the project, , Visual Studio automatically detect all the affected unit test cases and displays it in the Test Impact view. In our case, the TestAdd method.

    Test Impact view - Displaying affected unit tests

    Test Impact view - Displaying affected unit tests

    It also displays the changed methods. Instead of using the automated way, above mentioned, you can do this manually also. If you are making any code change, right click on the method and you can choose either Show calling Tests or Run calling tests, which will display or run the unit test cases.

    Right click on the code, for Show Calling tests or run calling tests

    Right click on the code, for Show Calling tests or run calling tests

Happy coding :)

Open Visual Studio Files As Administrator

Debugging WCF service requires to run the visual studio as Administrator, you can do it by right clicking the Visual Studio shortcut, Select Properties, and in Shortcut tab, click on Advanced button, it will display Advanced Properties, check the Run as administrator option.

Advanced Properties

Advanced Properties

But this option will not work, when you are opening a project or solution by double clicking on the solution file. Here is the tip which will help you to open Visual Studio files with Administrator option. All the solution files are opening using a small utility called VSLauncher.exe, which can be found in C:\Program Files (x86)\Common Files\microsoft shared\MSEnv folder. Right click on the executable, select Properties and select the Compatibility tab, Check the Run this program as an Administrator, under Privilege level. Apply the settings and click OK. Now open any solution, Windows will show the UAC dialog.

VSLauncher.exe Properties

VSLauncher.exe Properties

« Newer PostsOlder Posts »