Exemple #1
0
        public IActionResult Post(MatchEntity match)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var occurrences = match.FindOccurrences();

                var result = new MatchResult(match);
                result.Occurrences.AddRange(occurrences.Select(occurence => new MatchOccurrence()
                {
                    Index  = occurence.Index,
                    Length = occurence.Length,
                    Value  = occurence.Value
                }));

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public void GivenInput_WithNonExistingSubstring_ShouldExpectNoMatches(string str, string substr)
        {
            // Arrange
            var match = new MatchEntity
            {
                Text    = str,
                Subtext = substr
            };

            // Act
            var occurrences = match.FindOccurrences();

            // Assert
            Assert.That(occurrences.Count, Is.EqualTo(0));
        }
        public void GivenInput_WithExistingSubstring_ShouldExpectAtLeastOneMatch(string str, string substr, int expectedOccurrences)
        {
            // Arrange
            var match = new MatchEntity
            {
                Text    = str,
                Subtext = substr
            };

            // Act
            var occurrences = match.FindOccurrences();

            // Assert
            Assert.That(occurrences.Count, Is.EqualTo(expectedOccurrences));
        }