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"

Creates test cases from test methods using tcm.exe



Tcm.exe is an application that can be used to creates test cases from test methods, we can also run test cases with associated automation test  instead of using the user interface so it can be run with the nightly build batch

When you start the run from the command line, use tcm.exe. You must specify both the test settings that contain the set of roles that you require to run your tests, and an environment that contains this set of roles.

So

Tcm.exe is a command-line utility that lets you perform the following tasks:

MVC 3 Dependency injection with Unity 2.0 Video



I just create a video that explain the new feature of MVC3 IDependencyResolver which make the DI(Dependency Injection) easier with mvc .net, I used the Unity 2.0 DI framework to inject Service A and Service B, in this video I show how to work with Unity in design-time and run-time for different services

I will use Unity Microsoft, with net MVC, as we know Microsft Unity one of the appliction block for dependency injection .net

Thanks for Jan Jonas for his post.

For more information you can visit the following link on MSDN

You can download the project from here (Download)

How to control all the TFS services from one place



We can use the TFSServiceControl command to manage, stop or start all of the services and application pools Visual Studio Team Foundation Server uses. For example, we use this command when backing up or restoring databases, or when you are moving your deployment from one machine to another.

Don’t try to stop the job or any service directly, the command will be as the following:

TFSServiceControl [quiesce|unquiesce]

For more information see the MSDN link here

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

Generate unit tests and run them with CI (Continuous integration) using Pex and MS Team Build 2010



Continuous Integration + Microsoft Pex = Continuous Exploration

By exploring our code with Microsoft Pex in our continuous integration, we will leverage the full power of automated test generation.

  • First let’s deifne what is the Pex in nutshell ?

Pex is a white box testing framework that do the following:

  1. Generate parameterize unit test if it is not exist
  2. Run Pex Exploration on  parameterize unit test
  3. Generate unit tests with inputs depend on 2 things
    1. The code of the method under the test
    2. The precondition of the test data and parameters in the  parameterize unit test  (PexAssume)
  4. Identify if the generated unit tests will success or fail when they run?
So I can integrate the Pex in the CI (Continuous Integration) as the following
Preconditions:
The pex will be used for the Domain and the DAL layer, I will not use Pex in the Controller or the Presentation layer (MVC)
First scenario :
  1. The developer using Pex in his/her day to day development tasks since he/she is working on the Domain or the DAL layer
  2. The developer start create the parameterize unit test manual and put any precondition as needed (PexAssume, ExpectException, etc.. )
  3. The developer run Pex Exploration on his/her manual parameterize unit test and see if there is any method generated will fail so he/she start adjust the parameterize unit test by adding  PexAssume, ExpectException and so on until all generated test methods become green which indicate that they will pass if they run
  4. The developer check-in his code (code under test and the manual parameterize unit test) in the source control
  5. The build start and run Pex Explortion against the manual  parameterize unit test and generate the unite tests and see if they has any unit test that fail so the build will fail
pex.exe MyApplication.Tests.dll /nor /ftf
Second scenario :
  1. The developer didn’t use Pex at all, the developer may use Pex for personal check only before check-in his code, the parameterize unit test will not checked-in  in the source control
  2. The developer start develop on the application
  3. The developer check-in his code in the source control
  4. The build start and run Pex to generate  parameterize unit test
  5. The build run Pex Explortion against the generated parameterize unit test and generate the unite tests and see if they has any unit test that fail so the build will fail
pex.exe MyApplication.dll /nor /ftf /erm:wizard

All you need to do to integrate Pex with MS Team Build 2010 just invoke the process of the CMD and run Pex from Command line and give it the appropriated parameters


What is the parameterized unit tests?



Before answer this question we have to answer the question what is classic unit test?

  • Classic unit test

Classic or closed unit test is the normal unit test that doesn’t take parameter and depend on static data inside the method itself, using traditional unit tests that do not take inputs lead that you have to write many tests to cover all possible inputs

[TestMethod]
public void MyTestMethod()
{
int x = 5;
int y = 10;
}
  • Parameterized unit test

Parameterized unit tests are test methods with parameters. A straightforward extension is to allow parameters, which serve as the test input. The result is a parameterized unit test

[TestMethod]
public void MyTestMethod(int x, int y)
{

}

So classic unit tests are methods without parameters, parameterized unit tests are methods with parameters. So you can use it with Data driven test from DB or Excel sheet, or you can use it with many inputs as needed

You can partition parameterized unit tests into four parts:

  1.  Assume: Assume preconditions over the test inputs.
  2.  Arrange: Set up the unit under test—determine which parameters are used to shape legal test inputs.
  3. Act: Exercise the unit under test by adding a method sequence, which specifies a scenario, and capturing any resulting state.
    You use parameters for argument values when calling other methods in the Act stage.
  4. Assert: Verify the behavior by adding assertions that encode the rules of a unit test.
[PexMethod]
        public void ContainsNumbers(string number, Employee employee, [PexAssumeNotNull]string value)
        {
            PexAssume.IsTrue(Employee != null);
            PexAssert.TrueForAll(number, delegate(char c){ return char.IsDigit(c);});
        }