Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Sunday, February 26, 2017

Visual Studio 2017 live unit tests

I was experimenting today with VS 2017 live unit testing. I really like them a lot. I wish they were available in all editions of VS  2017 not just enterprise.

I started with a simple console app.  Which adds 2 numbers.


   public class Program
    {
        static void Main(string[] args)
        {
            Console.Write("1 + 1 = ");
            Console.WriteLine(Add2Numbers(1,1).ToString());
            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
        }
        public static int Add2Numbers(int x,int y)
        {
            return x * y;
        }
    }


Then I added a Unit Test project. I added a project reference to my ConsoleApp


Here is the tests I added.

Namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            int x = 1;
            int y = 1;
            int expected = 2;
            Assert.AreEqual(expected, ConsoleApp1.Program.Add2Numbers(x, y));
        }
    }
}


Then I build the project and ran the test.  As you can see the test failed. 

Lets turn on the Live Unit Tests in Visual Studio's Options.  There is a section for it.


Right click on the solution in the solution explorer and select Live Tests and select include.

Here is what you will see.


Now if we update the code. We  will see it goes to passing



        public static int Add2Numbers(int x,int y)
        {
            return x + y;
        }



Very useful feature.








Saturday, December 10, 2016

Fixing your Hyper-V emulators

If you are having problems getting your hyper-v emulators to run here are the steps I recommend to fix them

First and this usually fixes the issue.  Open the Hyper-V manager and delete all the virtual switches you will find them under the virtual switch manager



Try running the Hyper-V emulators again the switches will be recreated.  In the rare chance they still do not work go ahead and delete the virtual switches again. 



Now delete the virtual machines for the emulators.  Finally open the Device Manager and delete any hyper-v network adapters you might have




Rerun the emulators and they should work everything you deleted will be recreated.