0

What is the pendant of the NUnit TestCaseAttribute for MS Test?

see this sample:

[TestCase("Authorization", "Basic", "test@gmail.com:Mypassword", HttpStatusCode.OK)]
[TestCase("Authorization", "bASic", "test@gmail.com:Mypassword", HttpStatusCode.OK)]
[TestCase("WrongAuthorization", "Basic", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "WrongBasic", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "Basic", "test@gmail.com:Mypassword:anotherpassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "Basic", "", HttpStatusCode.Unauthorized)]
[TestCase("test", "", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
public void Authenticate_User(string headerName, string headerValue, string credentials, HttpStatusCode expectedStatusCode)
{
    // Arrange
    var encodedEmailPassword = Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
    _client.DefaultRequestHeaders.Add(headerName, headerValue + " " + encodedEmailPassword);

    // Act
    var response = _client.SendAsync(new HttpRequestMessage(HttpMethod.Post, _server.BaseAddress + "api/authentication")).Result;

    // Assert
    Assert.That(response.StatusCode == expectedStatusCode);
}
Pascal
  • 12,265
  • 25
  • 103
  • 195

1 Answers1

0

The TestCase attribute runs the method with the supplied arguments. Authenticate_User will be run 7 times with the different arguments.

More info on NUnit TestCase at http://www.nunit.org/index.php?p=testCase&r=2.5

See also Does MSTest have an equivalent to NUnit's TestCase?

Community
  • 1
  • 1
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73