public void ConversationIsFilteredByKeyword()
        {
            Conversation actualConversation   = new ConversationReader("chat.txt").Conversation;
            Conversation expectedConversation = new ConversationReader("ConversationPie.txt").Conversation;

            var filter = new IDFilter()
            {
                Word = "pie"
            };

            actualConversation = filter.Filter(actualConversation);

            Assert.That(actualConversation.ToString(), Is.EqualTo(expectedConversation.ToString()));;
        }
Пример #2
0
        public void ConversationShouldBeFilteredByID()
        {
            Conversation actualConversation   = new ConversationReader("chat.txt").Conversation;
            Conversation expectedConversation = new ConversationReader("ConversationBob.txt").Conversation;

            var filter = new IDFilter()
            {
                Word = "bob"
            };

            actualConversation = filter.Filter(actualConversation);

            Assert.That(actualConversation.ToString(), Is.EqualTo(expectedConversation.ToString()));
        }
Пример #3
0
        /// <summary>
        /// Exports the conversation at <paramref name="inputFilePath"/> as JSON to <paramref name="outputFilePath"/>.
        /// </summary>
        /// <param name="inputFilePath">
        /// The input file path.
        /// </param>
        /// <param name="outputFilePath">
        /// The output file path.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown when a path is invalid.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when something bad happens.
        /// </exception>
        public void ExportConversation(string inputFilePath, string outputFilePath, ConversationEditor editor, LogCreator logCreator)
        {
            var          conversationReader = new ConversationReader(inputFilePath);
            Conversation conversation       = conversationReader.ReadConversation();

            editor.EditConversation(conversation);

            var outputLog = logCreator.CreateLog(conversation);

            LogWriter logWriter = new LogWriter();

            logWriter.WriteToOutput(outputLog, outputFilePath);

            Console.WriteLine("Conversation exported from '{0}' to '{1}'", inputFilePath, outputFilePath);
        }
Пример #4
0
        /// <summary>
        /// Exports the conversation at <paramref name="inputFilePath"/> as JSON to <paramref name="outputFilePath"/>.
        /// </summary>
        /// <param name="inputFilePath">
        /// The input file path.
        /// </param>
        /// <param name="outputFilePath">
        /// The output file path.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown when a path is invalid.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when something bad happens.
        /// </exception>
        public void ExportConversation(string inputFilePath, string outputFilePath)
        {
            var conversationReader = new ConversationReader();
            var conversationWriter = new ConversationWriter();

            var conversation = conversationReader.ReadConversation(inputFilePath);

            foreach (var filter in _filters)
            {
                conversation = filter.Filter(conversation);
            }

            conversationWriter.WriteConversation(conversation, outputFilePath);

            Console.WriteLine("Conversation exported from '{0}' to '{1}'", inputFilePath, outputFilePath);
        }
        public void CombinedFiltersFilterChat()
        {
            // Define input and output file path

            var inputFilePath  = "chat.txt";
            var outputFilePath = "chat.json";

            // Create instances of conversation reader and writer

            var conversationReader = new ConversationReader();
            var conversationWriter = new ConversationWriter();

            // Read the inputFilePath

            var readConversation = conversationReader.ReadConversation(inputFilePath);

            // Create a list of filters

            var filters = new List <IFilter>();

            // Create all filters to test

            var usersToTest            = new string[] { "bob" };
            var keywordsToTest         = new string[] { "you" };
            var blacklistedWordsToTest = new string[] { "do" };

            // Populate the list of filters

            filters.Add(new UserFilter(usersToTest));
            filters.Add(new KeywordFilter(keywordsToTest));
            filters.Add(new Blacklist(blacklistedWordsToTest));
            filters.Add(new Report());

            // Create an instance of conversation exporter

            var conversationExporter = new ConversationExporter(filters);

            // Write the combined conversation to the output file path

            conversationWriter.WriteConversation(readConversation, outputFilePath);

            // Export the combined conversation to the output file path

            conversationExporter.ExportConversation(inputFilePath, outputFilePath);

            var serializedConversation = new StreamReader(new FileStream(outputFilePath, FileMode.Open)).ReadToEnd();

            var savedConversation = JsonConvert.DeserializeObject <Conversation>(serializedConversation);

            Assert.That(savedConversation.name, Is.EqualTo("My Conversation"));

            var combinedFilteredMessages = savedConversation.messages.ToList();
            var combinedfilteredActivity = savedConversation.activity.ToList();

            Assert.That(combinedFilteredMessages.Count == 1);
            Assert.That(combinedfilteredActivity.Count == 1);

            Assert.That(combinedFilteredMessages[0].timestamp, Is.EqualTo(DateTimeOffset.FromUnixTimeSeconds(1448470906)));
            Assert.That(combinedFilteredMessages[0].senderId, Is.EqualTo("bob"));
            Assert.That(combinedFilteredMessages[0].content, Is.EqualTo("I'm good thanks, *redacted* you like pie?"));

            Assert.That(combinedfilteredActivity[0].count == 1);
            Assert.That(combinedfilteredActivity[0].sender == "bob");
        }