public void Analyze_ForListOfLinesWithEmptyLines_ListOfWordsReturned()
        {
            String         someFilePath = "testPath";
            IList <String> lines        = new List <String>();

            lines.Add("The quick brown quick");
            lines.Add("                      ");
            lines.Add("over dog's quick brown dog's");
            var textReader = Substitute.For <ITextReader>();

            textReader.Read(null).ReturnsForAnyArgs(x => lines);
            var logger = Substitute.For <ILogger>();
            TextAnalyzerService stu = new TextAnalyzerService(textReader, logger);

            IList <Word> words = stu.Analyze(someFilePath);

            Assert.AreEqual(5, words.Count);
            Assert.AreEqual("The", words[0].Name);
            Assert.AreEqual(1, words[0].Counter);

            Assert.AreEqual("quick", words[1].Name);
            Assert.AreEqual(3, words[1].Counter);

            Assert.AreEqual("brown", words[2].Name);
            Assert.AreEqual(2, words[2].Counter);

            Assert.AreEqual("over", words[3].Name);
            Assert.AreEqual(1, words[3].Counter);

            Assert.AreEqual("dog's", words[4].Name);
            Assert.AreEqual(2, words[4].Counter);
        }
示例#2
0
        static void Main(string[] args)
        {
            initializeConfiguration();

            try
            {
                // prepare dependencies (TODO: can be done with a DI container)
                ILogger     logger     = new FileLogger(LogFilePath);
                ITextReader textReader = new FileTextReader();
                IWordSorter wordSorter = new LengthASCIIWordSorter();

                // to output the report to console
                // IReportWriter reportWriter = new ConsoleReportWriter();

                IReportWriter reportWriter = new FileReportWriter(ReportOutputFilePath);

                TextAnalyzerService textAnalyzer = new TextAnalyzerService(textReader, logger);
                IList <Word>        words        = textAnalyzer.Analyze(TextToAnalyzePath);

                TextReportService reportService = new TextReportService(wordSorter, reportWriter, logger);
                reportService.ProduceReport(words, reportConfig);

                Console.WriteLine("Finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }



            Console.WriteLine("Press any key to exit ...");
            Console.Read();
        }
 public void Constructor_WhenNullReaderOrLoggerInInput_ArgumentExceptionThrown()
 {
     try
     {
         TextAnalyzerService stu = new TextAnalyzerService(null, null);
     }
     catch (ArgumentNullException)
     {
         Assert.Pass();
     }
 }
        public void Analyze_WhenNullFilePathProvided_EmptyListOfWords()
        {
            var textReader = Substitute.For <ITextReader>();

            textReader.Read(null).ReturnsForAnyArgs(x => new List <String>());
            var logger = Substitute.For <ILogger>();
            TextAnalyzerService stu = new TextAnalyzerService(textReader, logger);

            IList <Word> words = stu.Analyze(null);

            Assert.AreEqual(0, words.Count);
            logger.Received(1).LogInfo(Arg.Any <String>());
        }
示例#5
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            string          chatResponse = null;
            ConnectorClient connector    = new ConnectorClient(new Uri(activity.ServiceUrl));

            try
            {
                if (activity.Type == ActivityTypes.Message)
                {
                    var chat           = CreateChatFromMessage(activity);
                    var analyzer       = new TextAnalyzerService();
                    var analysisResult = await analyzer.AnalyzeAsync(activity.Text);

                    chat.Sentiment  = analysisResult.Sentiment;
                    chat.KeyPhrases = analysisResult.KeyPhrases;

                    var selectedResponse = await _messageMatcherProcessor.ProcessAsync(activity.From.Name, analysisResult, activity.Text);

                    chat.Response          = selectedResponse.Message;
                    chat.ResponseTime      = DateTime.UtcNow;
                    chat.SentimentResponse = selectedResponse.Sentiment;
                    // calculate something for us to return
                    int length = (activity.Text ?? string.Empty).Length;

                    chatResponse = chat.Response;
                    await _chatRepository.QeueChatAsync(chat);
                }
            }
            catch (Exception ex)
            {
                chatResponse = ex.ToString();
            }

            // return our reply to the user
            Activity reply = activity.CreateReply(chatResponse);


            await connector.Conversations.ReplyToActivityAsync(reply);

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
示例#6
0
 public HomeController(JsonFileProductService jsonFileProductService, TextAnalyzerService textAnalyzerService) : base()
 {
     _TextAnalyzerService    = textAnalyzerService;
     _JsonFileProductService = jsonFileProductService;
 }