Unit testing a controller in ASP.NET MVC 3

Posted by Abdullah Al- Mansur on Stack Overflow See other posts from Stack Overflow or by Abdullah Al- Mansur
Published on 2012-11-03T21:08:38Z Indexed on 2012/11/03 23:01 UTC
Read the original article Hit count: 198

public Double Invert(Double? id)
{
    return (Double)(id / id);
}

I have done this for this test but fails please can anyone help with this cos just started with unit testing

/* HINT:  Remember that you are passing Invert an *integer* so
 * the value of 1 / input is calculated using integer arithmetic. 
 * */
//Arrange
var controller = new UrlParameterController();
int input = 7;
Double expected = 0.143d;
Double marginOfError = 0.001d;

//Act
var result = controller.Invert(input);

//Assert
Assert.AreEqual(expected, result, marginOfError);

/* NOTE  This time we use a different Assert.AreEqual() method, which
 * checks whether or not two Double values are within a specified
 * distance of one another.  This is a good way to deal with rounding
 * errors from floating point arithmetic.  Without the marginOfError 
 * parameter the assertion fails.
 * */  

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET