Creating the TFS Team Project

PDF for offline use

Let us know how you feel about this


0/250

A Team Project in TFS is the home for all project-related information, including the Team Foundation Version Control (TFVC) repository to which we'll add the TaskyPortable solution for continuous integration. These steps create a team project for TaskyPortable:

  1. In Visual Studio's Team Explorer pane, select the Home icon:

  2. Click Home to see the drop-down menu, then Projects and Teams > New Team Project…

  3. In the New Team Project dialog, enter Tasky for the team project name, enter a description if you like, and click Next.
  4. Accept the defaults on the next screen and click Finish button to create the Team Project. Note that if you want to use Git instead of TFVC for version control, you can click Next here instead to change that option.

Connecting the Xamarin Solution to the Team Project

With the team project in place, we can now add the TaskyPortable solution to it.

  1. In Visual Studio's Solution Explorer, right-click the TaskyPortable solution, then select Add Solution to Source Control…:

  2. In the Choose Source Control dialog that appears, select Team Foundation Version Control (or Git if you changed that option earlier), and press OK.

  3. In the Add Solution to Source Control dialog, select the Tasky team project and click OK:

  4. This will set up the solution for version control, but will not automatically check in files. Before doing that, however, we need to add two other DLLs in the TaskyPortable sample folder to the solution so they're included in version control and available to the TFS machine during builds.

    a. Right-click Solution TaskyPortable in Solution Explorer, select Add > Exiting Item..., navigate to Dependencies > Community.CshareSqlite, and double-click the Community.CsharpSqlite.WP7.dll file. This will add the file to the product in a folder called Solution Items.

    b. Repeat the step above but navigate into Dependencies > Microsoft.Phone.Controls.Toolkit and double-click Microsoft.Phone.Controls.Toolkit.dll.

  5. To now check everything into version control, right-click Solution TaskyPortable again and select Check In.

  6. This switches automatically to the Team Explorer pane. Enter Initial check-in for the comment and click Check In to complete the process:

With TaskyPortable in version control, we are ready to add unit testing and prepare the solution for CI.

Adding the NUnit Unit Testing Framework

One of the major benefits of using CI is automatic testing and validation of code whenever changes are checked in and committed to the team project. To see this in action, let's add some simple unit tests to TaskyPortable.

If you're only using Visual Studio and Android, then you can use Visual Studio's built-in MSTest framework. However, if you are targeting iOS or would like to open the solution in Xamarin Studio you need a framework like NUnit that can also run on the Mac OS X built host. The following steps install and configure NUnit for this purpose:

  1. In Visual Studio, select the Tools > Extensions and Updates… menu command.
  2. Expand Online > Visual Studio Gallery > Tools on the left side, select Testing, select NUnit Test Adapter, and click it's Download button, When complete, a green check should appear next to it, and you may be prompted to restart Visual Studio:

Adding Unit Tests

The following steps add a few unit tests to TaskyPortable:

  1. In Visual Studio, select the File > Add > New Project… command, navigate to Installed > Other Languages > Visual C#, then select the Class Library template. Give it the name of NUnitTests and click OK:

  2. In Solution Explorer, right click Class1.cs file in the NUnitTests project, select Rename, and call it CIBackendTests.cs.

  3. Right click References under the NUnitTests project and select Add Reference…. In the dialog that appears, expand Projects > Solution, select TaskyPortableLibrary and click OK:

  4. Right click the NUnitTests project again and select Manage NuGet Packages…. For Visual Studio 2013: in the dialog that appears, select Online, and then enter NUnitTestAdapter in the search box. For Visual Studio 2015: in the page that appears, make sure nuget.org is selected as the source, enter NUnitTestAdapter in the search box. In either, when the results are displayed, select NUnit TestAdapter including NUnit x.y.z Framework… or NUnitTestAdapter.WithFramework, click Install, and then click Close when the installation is complete:

  5. Before we can write our unit tests, we need something to test. In the TaskyPortableLibrary project in Solution Explorer, open Task.cs and make it look like the following to add an Importance property:

    using System;
    using Tasky.BL.Contracts;
    using SQLite;
    
    namespace Tasky.BL
    {
        /// <summary>
        /// Represents a Task.
        /// </summary>
        public class Task : IBusinessEntity
        {
            private int _importance = 0;
    
            public Task ()
            {
            }
    
            public Task(int Importance)
            {
                // Save default importance
                this._importance = Importance;
            }
    
            [PrimaryKey, AutoIncrement]
            public int ID { get; set; }
            public string Name { get; set; }
            public string Notes { get; set; }
            public bool Done { get; set; }
    
            public int Importance
            {
                get { return _importance; }
                set { _importance = value; }
            }
    
            public void SetImportance(int Importance)
            {
                this._importance = Importance;
            }
    
            public void IncrementImportance()
            {
                ++_importance;
            }
    
            public void DecrementImportance()
            {
                --_importance;
            }
        }
    }
  6. In the NUnitTests project, open CIBackendTest.cs and make it look like the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using NUnit.Framework;
    using Tasky.BL;
    
    namespace NUnitTests
    {
        [TestFixture]
        public class CIBackendTests
        {
            #region Private Variables
            private Tasky.BL.Task _task;
            #endregion
    
            #region Configuration
            [SetUp]
            public void InitBusinessLogic()
            {
                _task = new Tasky.BL.Task(100);
            }
            #endregion
    
            #region Unit Tests
            [Test]
            public void BusinessLogicDecrementation()
            {
                _task.DecrementImportance();
    
                // Assert
                Assert.AreEqual(99, _task.Importance);
            }
    
            [Test]
            public void BusinessLogicIncrementation()
            {
                _task.IncrementImportance();
                Assert.AreEqual(101, _task.Importance);
            }
    
            [Test]
            public void BusinessLogicInstantiation()
            {
    
                Assert.AreEqual(100, _task.Importance);
            }
            #endregion
    
        }
    }
  7. Now run the unit tests and make sure that everything is configured and working correctly by selecting the Test > Windows > Test Explorer menu command and click the Run All link at the top. This will build the solution, run the tests, and display the results:

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.