Esempio n. 1
0
        public object Process(string data)
        {
            ContainerResult <T> result = _container.Parse(data);

            if (!result.Success)
            {
                throw new InvalidRegexDataException($"Data '{data}' does not match regex for container type {nameof(T)}");
            }
            return(result.Value);
        }
Esempio n. 2
0
        public void RegexContainer_ParseAllArrayType_ValidContainersReturned()
        {
            string names = "John Doe, Jane Doe";
            RegexContainer <NamesTest>  container = new RegexContainer <NamesTest>();
            ContainerResult <NamesTest> result    = container.Parse(names);

            Assert.Multiple(() =>
            {
                Assert.That(result.Success, Is.True);
                Assert.That(result.Value.Names[0], Is.EqualTo("John Doe"));
                Assert.That(result.Value.Names[1], Is.EqualTo("Jane Doe"));
            });
        }
Esempio n. 3
0
        public void RegexContainer_ParseDefaultGrouping_ValidContainerReturned()
        {
            string points = "1 10 7";
            RegexContainer <DefaultGroupingTest>  container = new RegexContainer <DefaultGroupingTest>();
            ContainerResult <DefaultGroupingTest> result    = container.Parse(points);

            Assert.Multiple(() =>
            {
                Assert.That(result.Success, Is.True);
                Assert.That(result.Value.X, Is.EqualTo(1));
                Assert.That(result.Value.Y, Is.EqualTo(10));
                Assert.That(result.Value.Z, Is.EqualTo(7));
            });
        }
Esempio n. 4
0
        public void RegexContainer_Parse_ValidContainerReturned()
        {
            RegexContainer <UserInfo> container = new RegexContainer <UserInfo>();
            string text = "John Doe, 1500 St. Martin Blvd, Blah, XX 11111|23 X Pkwy, Test Blank, YY 44444\r\n";
            ContainerResult <UserInfo> result = container.Parse(text);

            Assert.Multiple(() =>
            {
                Assert.That(result.Success, Is.True);
                Assert.That(result.Value.FirstName, Is.EqualTo("John"));
                Assert.That(result.Value.LastName, Is.EqualTo("Doe"));
                Assert.That(result.Value.Addresses[0].City, Is.EqualTo("Blah"));
                Assert.That(result.Value.Addresses[0].State, Is.EqualTo("XX"));
                Assert.That(result.Value.Addresses[1].StreetAddress, Is.EqualTo("23 X Pkwy"));
                Assert.That(result.Value.Addresses[1].ZipCode, Is.EqualTo(44444));
            });
        }
Esempio n. 5
0
        public void RegexContainer_DataMismatchWithSubContainer_InvalidContainerReturned()
        {
            RegexContainer <DataMismatchSubcontainer> container = new RegexContainer <DataMismatchSubcontainer>();

            Assert.That(container.Parse("Fail").Success, Is.False);
        }