Skip to content

Instantly share code, notes, and snippets.

@mitchdenny
Created December 31, 2010 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchdenny/760641 to your computer and use it in GitHub Desktop.
Save mitchdenny/760641 to your computer and use it in GitHub Desktop.
This is a specification for a basic calculator with the implementation rounded out.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSTestContrib.Specifications;
namespace Calculator.Core.Specifications
{
[TestClass]
[SpecificationDescription("As a user I want to perform mathematical calculations so that my head doesn't hurt.")]
public class BasicCalculatorSpecification : Specification
{
public BasicCalculator Calculator { get; private set; }
[TestMethod]
[ScenarioDescription("Add two to a calculator with zero on the accumulator.")]
public void AddTwoToACalculatorWithZeroOnTheAccumulator()
{
Given("a calculator with zero on the accumulator", CalculatorWithZeroOnTheAccumulator)
.When("I add two to the accumulator", x => this.Calculator.Add(2))
.Then("the accumulator should show two", x => this.Calculator.Accumulator == 2);
}
private void CalculatorWithZeroOnTheAccumulator(SpecificationContext context)
{
Calculator = new BasicCalculator();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment