public SimpleValue(object example, MatcherType match)
 {
     Example     = example;
     MatcherList = new MatcherList {
         Matchers = new List <Matcher> {
             new Matcher {
                 MatcherType = match
             }
         }
     };
 }
 public Array ContainingAtLeast(int numberOfElements)
 {
     if (numberOfElements > 0)
     {
         MatcherList = new MatcherList
         {
             Matchers = new List <Matcher>
             {
                 new Matcher {
                     MatcherType = MatcherType.type, Min = numberOfElements
                 }
             }
         };
     }
     return(this);
 }
        public String(string example, string regex)
        {
            if (!System.Text.RegularExpressions.Regex.IsMatch(example, regex))
            {
                throw new PactException($"The provided example {example} does not match the regular expression {regex}.");
            }

            Example     = example;
            MatcherList = new MatcherList {
                Matchers = new List <Matcher> {
                    new Matcher {
                        MatcherType = MatcherType.regex, Regex = regex
                    }
                }
            };
        }
        public void TestTooMany()
        {
            var list = new MatcherList(5)
            {
                new Matcher(null),
                new Matcher(null)
            };
            var iterator = list.GetEnumerator();

            iterator.MoveNext().Should().BeTrue();
            iterator.Current.Should().NotBeNull();
            iterator.MoveNext().Should().BeTrue();
            iterator.Current.Should().NotBeNull();
            iterator.MoveNext().Should().BeFalse();
            var a = new Action(() => { var c = iterator.Current; });

            a.Should().Throw <IndexOutOfRangeException>();
        }
        public void TestNormalUse()
        {
            var list = new MatcherList(1);

            list.Count.Should().Be(0);
            list.Any().Should().BeFalse();
            list.Add(new Matcher(null));
            list.Count.Should().Be(1);
            list.Any().Should().BeTrue();
            list.Add(new Matcher(null));
            list.Count.Should().Be(2);
            list.Any().Should().BeTrue();
            var iterator = list.GetEnumerator();

            iterator.MoveNext().Should().BeTrue();
            var match1 = iterator.Current;

            match1.Should().NotBeNull();
            iterator.MoveNext().Should().BeTrue();
            var match2 = iterator.Current;

            match2.Should().NotBeNull();
            iterator.MoveNext().Should().BeFalse();

            list.Clear();

            list.Count.Should().Be(0);
            list.Any().Should().BeFalse();
            list.Add(new Matcher(null));
            list.Count.Should().Be(1);
            list.Any().Should().BeTrue();
            list.Add(new Matcher(null));
            list.Count.Should().Be(2);
            list.Any().Should().BeTrue();
            iterator = list.GetEnumerator();
            iterator.MoveNext().Should().BeTrue();
            match1 = iterator.Current;
            match1.Should().NotBeNull();
            iterator.MoveNext().Should().BeTrue();
            match2 = iterator.Current;
            match2.Should().NotBeNull();
            iterator.MoveNext().Should().BeFalse();
        }