Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/541570890165944320
explained why this needs improving
Source Link
ThunderDev
  • 537
  • 1
  • 5
  • 12

What would you doI'm not too happy with this, and I'm doing 2 asserts which is bad practice.. Any ideas ?

What would you do ?

I'm not too happy with this, and I'm doing 2 asserts which is bad practice.. Any ideas ?

deleted 12 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Edit

So far, I have put the custom reason phrases in a constant

Edit

So far, I have put the custom reason phrases in a constant

So far, I have put the custom reason phrases in a constant

added code sample
Source Link
ThunderDev
  • 537
  • 1
  • 5
  • 12

Edit

So far, I have put the custom reason phrases in a constant

public sealed class AuthError
{
    public const string ApiKeyMissing = "ApiKey is required";
    ...
}

And my tests look like this

[TestMethod]
public void SecurityHandler_ApiKeyMissingFromHeader_ReturnsUnauthorizedHttpStatus()
{
    var handler = new SecurityHandler(new Mock<IClientRepository>().Object, new Mock<ISignatureCalculator>().Object);

    var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

    var client = new HttpClient(handler);
    var result = client.SendAsync(httpRequestMessage).Result;

    Assert.AreEqual(result.StatusCode, HttpStatusCode.Unauthorized);
    Assert.AreEqual(result.ReasonPhrase, SecurityHandler.AuthError.ApiKeyMissing);
}

What would you do ?

Edit

So far, I have put the custom reason phrases in a constant

public sealed class AuthError
{
    public const string ApiKeyMissing = "ApiKey is required";
    ...
}

And my tests look like this

[TestMethod]
public void SecurityHandler_ApiKeyMissingFromHeader_ReturnsUnauthorizedHttpStatus()
{
    var handler = new SecurityHandler(new Mock<IClientRepository>().Object, new Mock<ISignatureCalculator>().Object);

    var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

    var client = new HttpClient(handler);
    var result = client.SendAsync(httpRequestMessage).Result;

    Assert.AreEqual(result.StatusCode, HttpStatusCode.Unauthorized);
    Assert.AreEqual(result.ReasonPhrase, SecurityHandler.AuthError.ApiKeyMissing);
}

What would you do ?

edited tags; edited title; edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
Source Link
ThunderDev
  • 537
  • 1
  • 5
  • 12
Loading