Click here to Skip to main content
15,896,111 members
Articles / All Topics

w00t: Building a New App from the Ground Up: First Specs and Getting Started

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
20 Oct 2009CPOL2 min read 8.4K   1  
Ok, this step took quite some time to figure out, but once you know how to do this, it is should be really simple...

This is one of the articles in our series; the parts are:

  1. Methodology, technology & tools used
  2. Setting up the environment
  3. First specs and getting started
  4. IOC, database and other stuff; a real framework

Happy reading !

Ok, this step took quite some time to figure out, but once you know how to do this, it should be really simple.

  1. Open the solution and go to the properties of the Specs project
  2. Go to the build events, and put the following text in the post-build event command line:
del "$(TargetDir)*.html"
"$(ProjectDir)..\..\tools\Machine.Specifications.ConsoleRunner.exe" 
			"$(TargetPath)" --html $(TargetDir) 
ren "$(TargetDir)$(TargetName)*.html" output.html
"$(TargetDir)output.html"
exit 0 

This will make sure that everytime you do a build, the old Mspec HTML file gets deleted, mspec is run, and the HTML is renamed to output.html and shown in your default browser.

Please do note that as long as you have the browser open, your build will not be considered finished, so you should close this window in order to continue developing.
Another possibility would be to build the HTML file somewhere in your project path, and add it to the project, so you can load it in your project each time, and get a message if it has changed.

  1. Add a reference to ..\lib\Machine.specifications.dll
  2. Remove the bogus class and start writing your specs

Regarding this part, there might be some discussions. I created a file called ProductSpecs.cs, which has the following content:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Machine.Specifications;
namespace Specs
{
    public class Product { };
    public interface IRepository<T>
    {
        IQueryable<T> Find {get;}
        bool Add(T instance);
        bool Delete(T instance);
        bool Update(T instance);
    }
    public interface IUnitOfWork : IDisposable 
    {
        void Commit();
    }
    public interface IProductRepository : IRepository<Product>
    {
         ICollection<Product> GetFromXml(string xml);
    };
    public abstract class with_empty_productlist
    {
        protected static IProductRepository productrepo;
        protected static ICollection<Product> products;
        Establish context = () => 
            {
                products = new List<Product>();
            };
    }
    public abstract class with_productlist : with_empty_productlist
    {
        Establish context = () =>
        {
            products = new List<Product>();
            products.Add(new Product());
            products.Add(new Product());
            products.Add(new Product());
        };
    }
    public class when_products_are_imported_from_external_xmlfile : with_productlist
    {
        Because of = () => products = 
		productrepo.GetFromXml(Properties.Resources.ExternalProductsXml);
        It should_contain_xx_products;
        It should_have_an_article_matching_xx;
    }
}

So as you might see, I added some of my code to be in order to be able to start writing some code in my specs; the next thing I am going to do is write code to match these simple specs, and move the respective app code in a proper project of its own.

Once this is finished, I am going to extend my specs to match a bigger part of the scope...

I'll keep you all posted !!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Virtual Sales Lab
Belgium Belgium

Comments and Discussions

 
-- There are no messages in this forum --