mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* Run `build -Target FormatCode` to fixup whitespace etc * Fix delete release asset integration test * Fix repository fork test * Fix pagination test for PR Review Request * First cut of release notes * update release notes * Update release notes * include links to contributors * Add breaking changes/advisories section * Tidy up formatting * Tidy up wording
163 lines
4.8 KiB
C#
163 lines
4.8 KiB
C#
using System;
|
|
using Xunit;
|
|
|
|
namespace Octokit.Tests.Models
|
|
{
|
|
public class StringEnumTests
|
|
{
|
|
public class TheCtor
|
|
{
|
|
[Fact]
|
|
public void ShouldSetValue()
|
|
{
|
|
var stringEnum = new StringEnum<AccountType>("user");
|
|
|
|
Assert.Equal("user", stringEnum.StringValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldSetValueAndParsedValue()
|
|
{
|
|
var stringEnum = new StringEnum<AccountType>(AccountType.Bot);
|
|
|
|
Assert.Equal("bot", stringEnum.StringValue);
|
|
Assert.Equal(AccountType.Bot, stringEnum.Value);
|
|
Assert.Equal("bot", stringEnum);
|
|
Assert.Equal(AccountType.Bot, stringEnum);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldRespectCustomPropertyAttributes()
|
|
{
|
|
StringEnum<ReactionType> stringEnum = ReactionType.Plus1;
|
|
|
|
Assert.Equal("+1", stringEnum.StringValue);
|
|
Assert.Equal(ReactionType.Plus1, stringEnum.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldThrowForInvalidEnumValue()
|
|
{
|
|
Assert.Throws<ArgumentException>(() => new StringEnum<AccountType>((AccountType)1337));
|
|
}
|
|
}
|
|
|
|
public class TheParsedValueProperty
|
|
{
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(null)]
|
|
[InlineData("Cow")]
|
|
public void ShouldThrowForInvalidValue(string value)
|
|
{
|
|
var stringEnum = new StringEnum<AccountType>(value);
|
|
|
|
Assert.Throws<ArgumentException>(() => stringEnum.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldHandleUnderscores()
|
|
{
|
|
var stringEnum = new StringEnum<EventInfoState>("review_dismissed");
|
|
|
|
Assert.Equal("review_dismissed", stringEnum.StringValue);
|
|
Assert.Equal(EventInfoState.ReviewDismissed, stringEnum.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldHandleHyphens()
|
|
{
|
|
var stringEnum = new StringEnum<EncodingType>("utf-8");
|
|
|
|
Assert.Equal("utf-8", stringEnum.StringValue);
|
|
Assert.Equal(EncodingType.Utf8, stringEnum.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldHandleCustomPropertyAttribute()
|
|
{
|
|
var stringEnum = new StringEnum<ReactionType>("+1");
|
|
|
|
Assert.Equal("+1", stringEnum.StringValue);
|
|
Assert.Equal(ReactionType.Plus1, stringEnum.Value);
|
|
}
|
|
}
|
|
|
|
public class TheTryParseMethod
|
|
{
|
|
[Fact]
|
|
public void ShouldReturnTrueForValidValue()
|
|
{
|
|
var stringEnum = new StringEnum<AccountType>("Bot");
|
|
|
|
AccountType type;
|
|
var result = stringEnum.TryParse(out type);
|
|
|
|
Assert.True(result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(null)]
|
|
[InlineData("Cow")]
|
|
public void ShouldReturnFalseForInvalidValue(string value)
|
|
{
|
|
var stringEnum = new StringEnum<AccountType>(value);
|
|
|
|
AccountType type;
|
|
var result = stringEnum.TryParse(out type);
|
|
|
|
Assert.False(result);
|
|
}
|
|
}
|
|
|
|
public class TheImplicitConversionOperator
|
|
{
|
|
[Fact]
|
|
public void ShouldSetValue()
|
|
{
|
|
StringEnum<AccountType> stringEnum = "user";
|
|
|
|
Assert.Equal("user", stringEnum.StringValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldSetValueAndParsedValue()
|
|
{
|
|
StringEnum<AccountType> stringEnum = AccountType.Bot;
|
|
|
|
Assert.Equal("bot", stringEnum.StringValue);
|
|
Assert.Equal(AccountType.Bot, stringEnum.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldThrowForInvalidEnumValue()
|
|
{
|
|
StringEnum<AccountType> stringEnum;
|
|
Assert.Throws<ArgumentException>(() => stringEnum = (AccountType)1337);
|
|
}
|
|
}
|
|
|
|
public class TheEqualityOperator
|
|
{
|
|
[Fact]
|
|
public void IsCaseInsensitive()
|
|
{
|
|
var first = new StringEnum<AccountType>("bot");
|
|
var second = new StringEnum<AccountType>("BoT");
|
|
|
|
Assert.True(first == second);
|
|
}
|
|
|
|
[Fact]
|
|
public void FallsBackToStringComparison()
|
|
{
|
|
var first = new StringEnum<AccountType>("god");
|
|
var second = new StringEnum<AccountType>("GoD");
|
|
|
|
Assert.True(first == second);
|
|
}
|
|
}
|
|
}
|
|
}
|