Exemple #1
0
        public void GenerateStatisticsTest(string text, int hiphensQty, int spacesQty, int wordsQty)
        {
            ITextProcessAppService textProcessAppService = new TextProcessAppService();

            TextStatisticsDto textStatisticsDto = textProcessAppService.GenerateStatistics(text);

            Assert.AreEqual(hiphensQty, textStatisticsDto.HiphensQuantity, "bad hiphens count");
            Assert.AreEqual(spacesQty, textStatisticsDto.SpacesQuantity, "bad spaces count");
            Assert.AreEqual(wordsQty, textStatisticsDto.WordsQuantity, "bad words count");
        }
Exemple #2
0
        public TextStatisticsDto MapToDto(TextStatistics dto)
        {
            var statisticsDto = new TextStatisticsDto();

            foreach (var stat in dto.Statistics)
            {
                var statisticDto = new StatisticDto()
                {
                    Count = stat.Value,
                    Type  = stat.Type.ToString()
                };

                statisticsDto.Statistics.Add(statisticDto);
            }

            return(statisticsDto);
        }
Exemple #3
0
        /// <summary>
        /// Processes de text and generates statistics
        /// </summary>
        /// <param name="text">Text to process</param>
        /// <returns>Statistic data<see cref="TextStatisticsDto"/></returns>
        public TextStatisticsDto GenerateStatistics(string text)
        {
            TextStatisticsDto textStatisticsDto = new TextStatisticsDto();

            if (_statisticRules.ContainsKey(nameof(HiphenStatisticRule)))
            {
                textStatisticsDto.HiphensQuantity = _statisticRules[nameof(HiphenStatisticRule)].Execute(text);
            }

            if (_statisticRules.ContainsKey(nameof(SpaceStatisticRule)))
            {
                textStatisticsDto.SpacesQuantity = _statisticRules[nameof(SpaceStatisticRule)].Execute(text);
            }

            if (_statisticRules.ContainsKey(nameof(WordStatisticRule)))
            {
                textStatisticsDto.WordsQuantity = _statisticRules[nameof(WordStatisticRule)].Execute(text);
            }

            return(textStatisticsDto);
        }
Exemple #4
0
        public IHttpActionResult PostGenerateStatistics(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(BadRequest());
            }

            TextStatisticsDto textStatisticsDto = null;

            //only place to catch and process excepcions
            try
            {
                textStatisticsDto = TextProcessAppService.GenerateStatistics(value);
            }
            catch (Exception e)
            {
                //TODO: generate log?
                return(InternalServerError(e));
            }

            return(Ok(textStatisticsDto));
        }