Exemplo n.º 1
0
        public void TryParseCollectionWithBadSyntax()
        {
            var listOfIntArgType = new CollectionOfTArgumentType(typeof(List <int>));

            listOfIntArgType.TryParse(ArgumentParseContext.Default, "1, z", out object value).Should().BeFalse();
            value.Should().BeNull();
        }
Exemplo n.º 2
0
        public void FormatCollection()
        {
            var listOfIntArgType = new CollectionOfTArgumentType(typeof(List <int>));

            var list = new[] { 0, 10, 3, -1 }.ToList();

            listOfIntArgType.Format(list).Should().Be("0, 10, 3, -1");
        }
        public void TestThatTokenWithSingleElementParses()
        {
            var type    = new CollectionOfTArgumentType(typeof(List <int>));
            var context = ArgumentParseContext.Default;

            type.TryParse(context, "15", out object value).Should().BeTrue();
            value.Should().BeOfType <List <int> >().Which.Should().BeEquivalentTo(new[] { 15 });
        }
        public void TestThatTokenWithMatchingSeparatorsParsesAsMultipleElements()
        {
            var type = new CollectionOfTArgumentType(typeof(List <string>));

            var context = ArgumentParseContext.Default;

            context.ElementSeparators = new[] { ":" };

            type.TryParse(context, "a:b", out object value).Should().BeTrue();
            value.Should().BeOfType <List <string> >().Which.Should().BeEquivalentTo(new[] { "a", "b" });
        }
Exemplo n.º 5
0
        public void TryParseCollection()
        {
            var listOfIntArgType = new CollectionOfTArgumentType(typeof(List <int>));

            listOfIntArgType.TryParse(ArgumentParseContext.Default, "1, 2", out object value).Should().BeTrue();
            value.Should().BeOfType <List <int> >();

            var list = (List <int>)value;

            list.Should().HaveCount(2);
            list.Should().ContainInOrder(1, 2);
        }
Exemplo n.º 6
0
        public void CollectionToCollection()
        {
            var listOfIntArgType = new CollectionOfTArgumentType(typeof(List <int>));

            Action invocation = () => listOfIntArgType.ToCollection(null);

            invocation.ShouldThrow <ArgumentNullException>();

            var outCollection = listOfIntArgType.ToCollection(new ArrayList(new[] { 10, -1 }));

            outCollection.Should().BeOfType <List <int> >();

            var outList = (List <int>)outCollection;

            outList.Should().HaveCount(2);
            outList.Should().ContainInOrder(10, -1);
        }
Exemplo n.º 7
0
        public void TryParseCollectionWithNonDefaultSeparators()
        {
            var argType = new CollectionOfTArgumentType(typeof(List <string>));

            var context = ArgumentParseContext.Default;

            context.AllowEmpty        = true;
            context.ElementSeparators = new[] { "|", "~" };

            argType.TryParse(context, "1,3|00~4~", out object value).Should().BeTrue();
            value.Should().BeOfType <List <string> >();

            var list = (List <string>)value;

            list.Should().HaveCount(4);
            list.Should().Equal("1,3", "00", "4", string.Empty);
        }