I am new on MVC3 and not familiar with the unit testing part. I have been trying to construct Datetime with exception handling from accepting 3 integer value but the it fails the unit testing. Im not sure i am doing it correctly or not.
This is the controller part:
public DateTime MakeDate(string dateString)
{
DateTime myDate;
if (DateTime.TryParseExact(dateString, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out myDate))
{
return myDate;
}
return new DateTime();
}
And this is the unit Testing:
[TestMethod]
public void MakeDateConstructsADateTimeFromYearMonthAndDay()
{
//Arrange
var controller = new DateController();
var expected = new DateTime(2014, 6, 30);
//Act
var result = controller.MakeDate(2014, 6, 30);
//Assert
Assert.AreEqual<DateTime>(expected, result);
}
[TestMethod]
public void MakeDateReturnsDefaultDateTimeIfInputDataInvalid()
{
var controller = new DateController();
var expected = new DateTime();
//Act
//June has only 30 days so this will cause an exception
var result = controller.MakeDate(2014, 6, 31);
//Assert
Assert.AreEqual<DateTime>(expected, result);
}
Thanks in advance