public void TestThatNonExistentValuesAreNotFindable() { var argType = EnumArgumentType.Create(typeof(SampleEnum)); argType.TryGetValue("foo", out IArgumentValue value).Should().BeFalse(); value.Should().BeNull(); }
public void TestThatFormatThrowsOnNull() { var argType = EnumArgumentType.Create(typeof(SampleEnum)); argType.Invoking(t => t.Format(null)) .Should().Throw <ArgumentNullException>(); }
public void TestThatValuesAreRetrievable() { var argType = EnumArgumentType.Create(typeof(SampleEnum)); argType.TryGetValue(SampleEnum.Other, out IArgumentValue value).Should().BeTrue(); value.Should().NotBeNull(); value.ShortName.Should().Be("o"); }
public void InvalidEnumArgumentTypeUsage() { var actions = new Action[] { () => EnumArgumentType.Create(typeof(object)) }; foreach (var action in actions) { action.ShouldThrow <ArgumentException>(); } }
public void EnumWithCustomLongAndShortNames() { var type = EnumArgumentType.Create(typeof(SampleEnum)); type.TryParse(ArgumentParseContext.Default, "Fo", out object o).Should().BeTrue(); o.Should().Be(SampleEnum.Foo); type.TryParse(ArgumentParseContext.Default, "f", out o).Should().BeTrue(); o.Should().Be(SampleEnum.Foo); type.TryParse(ArgumentParseContext.Default, "o", out o).Should().BeTrue(); o.Should().Be(SampleEnum.Other); type.TryParse(ArgumentParseContext.Default, "Foo", out o).Should().BeFalse(); }
public void EnumWithAliasesIsOkay() { var argType = EnumArgumentType.Create(typeof(EnumWithAliases)); var values = argType.GetValues().ToList(); values.Should().HaveCount(4); values.Select(v => v.LongName) .OrderBy(name => name) .Should().Equal("None", "Nothing", "Some", "Something"); argType.TryParse(ArgumentParseContext.Default, "None", out object value1) .Should().BeTrue(); argType.TryParse(ArgumentParseContext.Default, "Nothing", out object value2) .Should().BeTrue(); value1.Should().Be(value2); }
public void CompletingEnums() { var type = EnumArgumentType.Create(typeof(TestEnum)); var c = CreateContext(); type.GetCompletions(c, string.Empty).ToArray() .Should().ContainInOrder("Default", "SomeOtherValue", "SomeValue"); type.GetCompletions(c, "a").ToArray().Should().BeEmpty(); type.GetCompletions(c, "s").ToArray() .Should().ContainInOrder("SomeOtherValue", "SomeValue"); type.GetCompletions(c, "S").ToArray() .Should().ContainInOrder("SomeOtherValue", "SomeValue"); type.GetCompletions(c, "Defaulte").ToArray().Should().BeEmpty(); type.GetCompletions(c, "Default").ToArray() .Should().ContainInOrder("Default"); }
public void ConflictingAttributesOnMembers() { Action typeFactory = () => EnumArgumentType.Create(typeof(ConflictingAttributes)); typeFactory.Should().Throw <ArgumentOutOfRangeException>(); }
public void EnumWithCaseInsensitivelyEqualMemberNames() { Action typeFactory = () => EnumArgumentType.Create(typeof(CaselessSameMemberNames)); typeFactory.Should().Throw <ArgumentOutOfRangeException>(); }
public void DisallowedEnumValue() { var type = EnumArgumentType.Create(typeof(SampleEnum)); type.TryParse(ArgumentParseContext.Default, "Unusable", out object o).Should().BeFalse(); }