Unit test the ICommand Property of ViewModel – MVVM Pattern

Good to have new Patterns to design your applications. MVVM is such one pattern.

I assume the reader of this post has basic understanding of what MVVM stands for.

MVVM gives the flexibility to handle the User action in ViewModel using ICommand property. However this brings another challenge for developer of unit test this.

Consider a sample ICommand:

public ICommand ClearCommand
{
            get
            {
                if (this.infClearCommand == null)
                {
                    this.infClearCommand = new RelayCommand(
                        param =>
                        {
                            this.SelectedFileName = string.Empty;
                            this.infFileReader = null;
                            this.NotifyPropertyChanged("SelectedFileName");
                        },
                        param =>
                        {
                             return true;
                         });
                 }
                 return this.infClearCommand;             
        }         
}

Now to unit test this piece of code:

[TestMethod]
public void Test()
{
    ABCViewModel target = new ABCViewModel(); 
    target.SelectedFileName = "XYZ";
    target.ClearCommand.Execute(null);
    Assert.AreEqual(target.SelectedFileName, string.Empty);
}

ICommand.Execute will take care of the Unit Test for you.

Team Foundation Server 2013 Customization

Team Foundation Server 2013 Customization

New book on TFS 2013, cutomization written by Gordon Beeming, talks about all the possible customization of TFS, at one place, which is good. This book is kind of quicker reckoner for any particular. However if you are looking for details and limitations/ drawbacks/ benefits of each customization in detail, this book misses that information.