Exemplo n.º 1
0
        public void TestThatNonExistentValuesAreNotFindable()
        {
            var argType = EnumArgumentType.Create(typeof(SampleEnum));

            argType.TryGetValue("foo", out IArgumentValue value).Should().BeFalse();
            value.Should().BeNull();
        }
Exemplo n.º 2
0
        public void TestThatFormatThrowsOnNull()
        {
            var argType = EnumArgumentType.Create(typeof(SampleEnum));

            argType.Invoking(t => t.Format(null))
            .Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        public void InvalidEnumArgumentTypeUsage()
        {
            var actions = new Action[]
            {
                () => EnumArgumentType.Create(typeof(object))
            };

            foreach (var action in actions)
            {
                action.ShouldThrow <ArgumentException>();
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
        public void ConflictingAttributesOnMembers()
        {
            Action typeFactory = () => EnumArgumentType.Create(typeof(ConflictingAttributes));

            typeFactory.Should().Throw <ArgumentOutOfRangeException>();
        }
Exemplo n.º 9
0
        public void EnumWithCaseInsensitivelyEqualMemberNames()
        {
            Action typeFactory = () => EnumArgumentType.Create(typeof(CaselessSameMemberNames));

            typeFactory.Should().Throw <ArgumentOutOfRangeException>();
        }
Exemplo n.º 10
0
        public void DisallowedEnumValue()
        {
            var type = EnumArgumentType.Create(typeof(SampleEnum));

            type.TryParse(ArgumentParseContext.Default, "Unusable", out object o).Should().BeFalse();
        }