Create a VHD and add it to the Boot menu using bcdedit command



Let’s list the steps

  1. Create a VHD from Disk Management
  2. Or create a VHD from Command line using diskpart command
  3. Attach the VHD if you already have an existing VHD using Disk Management
  4. Or attach VHD using Command line
  5. Copy a BCD entry and edit it according to the new value
  • Create a VHD from Disk Managment

We can create the VHD from the Disk Management from computer management, see the following link

http://www.sevenforums.com/tutorials/566-virtual-hard-disk-create-attach-vhd.html

  • Or create VHD from Command line using diskpart command
create vdisk file=”D:\pathToVhd.vhd” type=expandable maximum=maxsizeInMegabyte

For more information see the following link

Windows 7 – VHD Boot – Setup Guideline

  • Attach the VHD if you already have an existing VHD using Disk Management

You can see the first link

  • Or attach VHD using Command line
diskpart
select vdisk file=c:\windows7.vhd
attach vdisk
list volume
select volume <volume_number_of_attached_VHD>
assign letter=v
exit
  • Copy a BCD entry and edit it according to the new value
First we will see the existing entries by command bcdedit, this will list all existing entries, then we will select the entry for the same windows for example I will select the entry of windows 7 and copy it and then change it’s value to the new value, remember that we used the GUID to do this
bcdedit /copy {originalguid} /d "New Windows 7 Installation"
bcdedit /set {newguid} device vhd=[D:]\Image.vhd
bcdedit /set {newguid} osdevice vhd=[D:]\Image.vhd
bcdedit /set {newguid} detecthal on

Fore more information about bcedit command see the following link
http://www.sevenforums.com/tutorials/2676-bcdedit-how-use.html

http://technet.microsoft.com/en-us/library/dd799299(v=ws.10).aspx

I decide to create a category of links



I decide to create a category of links, I will post links that I like, or that have a good knowledge, etc. and I will put my comments, criticizing  or the situation information with it to be memorize and retrieval anytime latter and may help others

 

Copy comments from base in Resharper



I used to use a very slickly feature of Resharper which is copy comments from base (class or interface), anyone knows me will know that I am very strict to code guidance and rules using style copy and other code standard tools, we have very restricted rules about documentation, so this really helped me very well but….?!

 

The problem that the action context of this action sometimes didn’t appear, until this moment I didn’t know why? of course I Google everywhere but nothing helpful except that info that Resharper 6.0 doesn’t support the style cop plugin till now, which was very sad news for me anyway, here what I do to fix the problem, of course it fixed at the end but I didn’t know why??

 

  • I disable the Style copy for Resharper plugin
  • I remove the old comments
  • I remove the inheritance and bring it again

And now its working with style copy an without style cop, Just click on the method name and the context action will appear and include the copy comments from base

Copy comments from base without style cop plugin

Copy comments from base without style cop plugin

 

 

Copy comments from base with style cop plugin on

Copy comments from base with style cop plugin on

 

How to effectively debug Expression Tree?



First this is a very small tip and the reason for creating it because it took me time to reach where I can click the button to display the visualizer of the Expression tree?

  • First we have to be in the debug mode
  • Second open add-watch window for the expression

Add Watch

  • Third click on the a magnifying glass that appears, that’s it

Expression

  • Variable names are displayed with a “$” symbol at the beginning.
  • Assigned an automatically generated names for parameters, such as $var1 or $var2.
  • Assigned an automatically generated name for lambda expression, such as #Lambda1 or #Lambda2.

Good links for more more info

http://msdn.microsoft.com/en-us/library/ee725345.aspx

http://marlongrech.wordpress.com/2008/01/08/working-with-expression-trees-part-1/

Extension Methods for IEnumerable of T and Custom Collection



Custom Collection one of the best design pattern I have ever used. It encapsulates items or array of items inside a seperate class which will allow us to  full control these items, but for modern development, it’s rarely to see custom collection in any post or code snippet everywhere, when I deeply search why the community didn’t follow this pattern, I found the community not only follow this pattern, no it’s recommended to not doing it, Microsoft .NET Framework Design Guide

http://msdn.microsoft.com/en-us/library/ms229042.aspx

http://stackoverflow.com/questions/1544800/custom-collection-vs-generic-collection-for-public-methods

So what is the main reason for that?

The answer is Extension Method, Microsoft extend all the Old collection like (Any Array, List<T>, Queue<T>, Stack<T>, Dictionary<T,T> etc.) with all extension methods exist in the System.LINQ, so no need to create custom collection, we just need to use IEnumerable<T> or IList<T> and then extend them at any time in my project with new extension methods, but be careful this will not break the access of the members, in other words the extension method will not be able to access the private member like in the custom collection does, but in most cases this will be good enough

  • Extension Method for IEnumerable<T>

We can create extension methods that apply to an interface, which allow us to call this method for each class that implement this interface, for example

If we add extension method called CalculateSalary for IEnumerable<Employee> as the following:

public static decimal CalculateSalary(this IEnumerable<Employee> empList)
{
           decimal totalSalary = 0m;
           foreach (var employee in empList)
            {
              totalSalary += employee.Salary;
            }
           return totalSalary;
        }

So now I can create list of Employee and I will find the method exist in this list as the following:

static void Main(string[] args)
{
      IEnumerable<Employee> emplloyees = new List<Employee>
       {
          new Employee { Id = 1, Salary = 49m },
          new Employee { Id = 2, Salary = 33m },
          new Employee { Id = 4, Salary = 66m }
       };

      Console.WriteLine(emplloyees.CalculateSalary());

      Console.ReadLine();
}

Extension Method rules

  • It must be static and exist in any static class
  • It will extend the first parameter which is prefix with this
  • It will pass current instance of the extended class at the run time
  • If you extend an Interface that’s meaning you extend any class implement that interface

How to fix the path can’t be more than 260 character error in TFS



I read a good article on how to do that, I just document this information, thanks Tarun Arora for pointing to this post and thanks  scott.rudy

To fix the long path you can create a drive on your computer with the path that you want, for example if I have path like :

C:\Radwan\Wallpaper

I can create a file with the following code and save is as .reg and double click it, after reboot, we will find a drive V which point to the wallpaper folder
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"V:"="\\DosDevices\\C:\\Radwan\\Wallpaper"

How to isolate layers and other library using Moles in Unit Testing?



Moles is one of the Mocking framework for isolation dependencies and other layer’s classes, I used to work with Moq framework and it was very good, but with Mole you can do very good things I don’t know if we can make it with Moq?  like you can isolate your code from .NET Framework code for example how you will isolate DateTime.Now to return specific value that you want?  Remember that you don’t have access definition to the .NET Framework Classes, but with Moles you can do that.

I create a solution from multiple projects so we can investigate Moles, the solution structure as the following:

 

Projects

Project

You will add reference in the Test project to the DB project

Right click on the DB ref and choose Add Mole Assembly

Add Reference

Moles

Start using it as the following

DB Class

using Common;
namespace DB
{
public class DataBase:IDataBase
{
public bool Save(IEmployee e)
{
return true;
}
}
}

Employee Class

using System;
using Common;

namespace DB
{
public class Employee:IEmployee
{
public int Id { get; set; }

public string Name { get; set; }

public DateTime BirthDate { get; set; }
}
}

The Method under the Test

using System;
using Common;
using DB;

namespace TryMole
{
public class MyClas
{
public IDataBase DataBase { get; set; }

public void SaveEmployee(IEmployee e)
{
if (e == null)
throw new ArgumentNullException();
if (e.Id <= 0)
throw new ArgumentException();
if (e.Id > 5000)
throw new ArgumentException();
DataBase.Save(e);
}
}
}

Test Method

[TestMethod()]
public void SaveEmployeeTest()
{
MyClas target = new MyClas(); // TODO: Initialize to an appropriate value
var database = new SIDataBase();
database.SaveIEmployee = (IEmployee emp) => true;
target.DataBase = database;
IEmployee e = new Employee { Id = 5 };
target.SaveEmployee(e);
}

I included also a project that isolate .NET Framework DateTime to return 1/1/2000 Y2K Bug

To download the project and Y2K project click the following link

download

How to limit the Pex to not explorer every block in your application



MS Pex one of the greatest tool I found for automation of the generation of the unit testing, but when you Pex your application you don’t want Pex exploration to run for every method called for the desired method, so you can use some attributes to define this option

PexInstrumentAssemblyAttribute    Specifies to instrument an assembly

PexInstrumentTypeAttribute           Specifies to instrument a type

PexAssemblyUnderTestAttribute      Binds a test project to a project


[assembly:PexAssemblyUnderTest(&quot;MyAssembly&quot;)]

[assembly:PexInstrumentAssembly(&quot;Lib&quot;)]

[assembly:PexInstrumentType(typeof(MyClass))]

Very good hands on lab for ALM 2010 with VM



There is a very good hands on lab for ALM, it can be a starting point for anyone need to explorer TFS 2010, for the link click the following:

http://msdn.microsoft.com/en-us/vs2010trainingcourse_alm_unit

You can also download the Visual Studio 2010 RTM Virtual Machine with Sample Data and Hands-on-Labs from the following link:

Now Available: Visual Studio 2010 RTM Virtual Machine with Sample Data and Hands-on-Labs

enjoy