Source

LawnSprinkler / Netuino.Sprinkler.Specs / Contract / JSONSteps.cs

Full commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using Netduino.Sprinkler.Contract;
using NUnit.Framework;

namespace Netuino.Sprinkler.Specs.Contract
{
	[Binding]
	public class JSONSteps
	{
		string _jsonMessage;
		DateTime _result;
		bool _parsedOk;

		[Given(@"I have a json message 8/10/2011 23:00:00")]
		public void GivenIHaveAJsonMessage8102011230000()
		{
			_jsonMessage = @"{""DateTime"":""08/10/2011 23:00:00""}";
		}
		[Given(@"I have a json message 8/10/2011 09:00:00")]
		public void GivenIHaveAJsonMessage8102011090000()
		{
			_jsonMessage = @"{""DateTime"":""8/10/2011 09:00:00""}";
		}
		[When(@"I parse the message")]
		public void WhenIParseTheMessage()
		{
			_parsedOk = JSON.TryParseDateTime(_jsonMessage, "DateTime", out _result);
		}
		[Then(@"the result should be a datetime 8/10/2011 23:00:00")]
		public void ThenTheResultShouldBeADatetime8102011230000()
		{
			Assert.AreEqual(true, _parsedOk, "The JSON Message could not be parsed");
			Assert.AreEqual(new DateTime(2011, 8, 10, 23, 0, 0), _result, "incorrect datetime");
		}

		[Then(@"the result should be a datetime 8/10/2011 9:00:00")]
		public void ThenTheResultShouldBeADatetime810201190000()
		{
			Assert.AreEqual(true, _parsedOk, "The JSON Message could not be parsed");
			Assert.AreEqual(new DateTime(2011, 8, 10, 9, 0, 0), _result, "incorrect datetime");
		}
	}
}