First Test Method

Remember, the fundamental concept is Red, Green, then Refactor. Another concept is AAA, stands for Arrange, Act, and Assert

First thing to do is create a TestMethod. The structure shown below.

[TestMethod]
public void Given1Return1()
{
    // Arrange
    FizzBuzzController controller = new FizzBuzzController();

    // Act
    ..
    ..

    // Assert
    Assert.AreEqual(expected, actual);
}

The idea is we throw "1" and the view will show "1". If we throw "3", it will show "1, 2, Fizz".

To get a result of view, we use ViewResult. Then, the result will be stored in ViewBag.

ViewResult result = controller.Index(1) as ViewResult;
string expected = "1";
string actual = result.ViewBag.Output;

results matching ""

    No results matching ""