2022-01-10 16:58:16 +01:00
|
|
|
|
using AutoFixture.Xunit2;
|
|
|
|
|
using Bit.Core.Tokens;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Test.Tokens;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
public class TokenTests
|
|
|
|
|
{
|
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public void InitializeWithString_ReturnsString(string initString)
|
|
|
|
|
{
|
|
|
|
|
var token = new Token(initString);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
Assert.Equal(initString, token.ToString());
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public void AddsPrefix(Token token, string prefix)
|
|
|
|
|
{
|
|
|
|
|
Assert.Equal($"{prefix}{token.ToString()}", token.WithPrefix(prefix).ToString());
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public void RemovePrefix_WithPrefix_RemovesPrefix(string initString, string prefix)
|
|
|
|
|
{
|
|
|
|
|
var token = new Token(initString).WithPrefix(prefix);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
Assert.Equal(initString, token.RemovePrefix(prefix).ToString());
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
[Theory, AutoData]
|
|
|
|
|
public void RemovePrefix_WithoutPrefix_Throws(Token token, string prefix)
|
|
|
|
|
{
|
|
|
|
|
var exception = Assert.Throws<BadTokenException>(() => token.RemovePrefix(prefix));
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-01-10 16:58:16 +01:00
|
|
|
|
Assert.Equal($"Expected prefix, {prefix}, was not present.", exception.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|