Skip to content

Instantly share code, notes, and snippets.

@mausworks
Last active July 3, 2017 15:24
Show Gist options
  • Save mausworks/37ba3aa9d3aeb3625b2eda196a0f1796 to your computer and use it in GitHub Desktop.
Save mausworks/37ba3aa9d3aeb3625b2eda196a0f1796 to your computer and use it in GitHub Desktop.
Tests for BasicAuthentication
public class BasicAuthenticationTests
{
public const string Username = "test-123";
public const string Password = "test-321";
/// <summary>
/// A base64 encoded representation of "test-123:test-321"
/// </summary>
public const string Base64 = "dGVzdC0xMjM6dGVzdC0zMjE=";
[Fact]
public void Initialization_SetsUsernameAndPassword()
{
// Act
var auth = new BasicAuthentication(Username, Password);
// Assert
Assert.Equal(Username, auth.Username);
Assert.Equal(Password, auth.Password);
}
[Fact]
public void Initialization_ThrowsForAnyNullValues()
{
// Act / Assert
Assert.Throws<ArgumentNullException>(() => new BasicAuthentication(Username, null));
Assert.Throws<ArgumentNullException>(() => new BasicAuthentication(null, Password));
}
[Fact]
public void GetBase64()
{
// Act
var auth = new BasicAuthentication(Username, Password);
var base64 = auth.GetBase64(Encoding.UTF8);
// Assert
Assert.Equal(Base64, base64);
}
[Fact]
public void CreateFromBase64()
{
// Act
var auth = BasicAuthentication.FromBase64(Base64, Encoding.UTF8);
// Assert
Assert.Equal(Username, auth.Username);
Assert.Equal(Password, auth.Password);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment