Exemple #1
0
        public void TestOutputFileDataWithUserFilter()
        {
            ConversationExporter exporter = new ConversationExporter(path + "chat.txt", path + "chat_test_2.json");
            ConversationFilters  filter   = new ConversationFilters("bob", "", new string[] { "" });
            bool test = exporter.ExportConversation(filter);

            var          serializedConversation = new StreamReader(new FileStream(path + "chat_test_2.json", FileMode.Open)).ReadToEnd();
            Conversation savedConversation      = JsonConvert.DeserializeObject <Conversation>(serializedConversation);

            Assert.IsTrue(test);

            Assert.AreEqual("My Conversation", savedConversation.name);

            var messages = savedConversation.messages.ToList();

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470901), messages[0].timestamp);
            Assert.AreEqual("bob", messages[0].sender.username);
            Assert.AreEqual("Hello there!", messages[0].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470906), messages[1].timestamp);
            Assert.AreEqual("bob", messages[1].sender.username);
            Assert.AreEqual("I'm good thanks, do you like pie?", messages[1].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470914), messages[2].timestamp);
            Assert.AreEqual("bob", messages[2].sender.username);
            Assert.AreEqual("No, just want to know if there's anybody else in the pie society...", messages[2].content);
        }
Exemple #2
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <param name="args">
        /// The command line arguments.
        /// </param>
        public static void Main(string[] args)
        {
            try
            {
                CommandLineArgumentParser parser = new CommandLineArgumentParser();

                ConversationExporter exporter = parser.ParseCommandLineFilePaths();

                ConversationFilters filters = parser.ParseCommandLineFilters();

                if (exporter.ExportConversation(filters))
                {
                    Console.WriteLine("Conversation exported successfully");
                }
            }
            catch (OutOfMemoryException e)
            {
                Console.WriteLine("The application ran out of memory. Please restart the appliction and try again.");
                Console.WriteLine(e.InnerException.Message);
            }
            catch (IOException e)
            {
                Console.WriteLine("Something went wrong in the IO while reading the input from the user. Please restart the appliction and try again.");
                Console.WriteLine(e.InnerException.Message);
            }
        }
        public void SetMessageHiddenWordsFilterFilterArgumentException()
        {
            ConversationFilters filter       = new ConversationFilters("", "", null);
            Conversation        conversation = new Conversation();

            conversation.name     = "Test";
            conversation.messages = new List <Message>();
            filter.ReplaceHiddenWords();
        }
        public void SetKeywordMessagesFilterFilterArgumentException()
        {
            ConversationFilters filter       = new ConversationFilters("", null, new string[] { "" });
            Conversation        conversation = new Conversation();

            conversation.name     = "Test";
            conversation.messages = new List <Message>();
            filter.ApplyKeywordMessageFilter();
        }
Exemple #5
0
        public void ReadConversationExceptionFileNotFound()
        {
            ConversationExporter exporter = new ConversationExporter(path + "chatVVV.txt", path + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.ReadConversation();

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #6
0
        public void WriteConversationExceptionFileNameEmpty()
        {
            ConversationExporter exporter = new ConversationExporter(path + "chat.txt", path + "");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.WriteConversation(new Conversation());

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #7
0
        public void WriteConversationExceptionDirectoryNotFound()
        {
            ConversationExporter exporter = new ConversationExporter(path + "chat.txt", path + "\\vvv\\" + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.WriteConversation(new Conversation());

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #8
0
        public void ReadConversationEmptyFile()
        {
            string       testConversation = "";
            StreamWriter writer           = new StreamWriter(new FileStream(path + "chat_test_8.txt", FileMode.Create, FileAccess.Write));

            writer.Write(testConversation);
            writer.Flush();
            writer.Close();

            ConversationExporter exporter = new ConversationExporter(path + "chat_test_8.txt", path + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #9
0
        public void ReadConversationExceptionMessageLessArguments()
        {
            string       testConversation = "My Test Conversation\n1448470901";
            StreamWriter writer           = new StreamWriter(new FileStream(path + "chat_test_7.txt", FileMode.Create, FileAccess.Write));

            writer.Write(testConversation);
            writer.Flush();
            writer.Close();

            ConversationExporter exporter = new ConversationExporter(path + "chat_test_7.txt", path + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.ReadConversation();

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #10
0
        public void ReadConversationExceptionTimestampFormat()
        {
            string       testConversation = "My Test Conversation\nVVV bob Hello there!";
            StreamWriter writer           = new StreamWriter(new FileStream(path + "chat_test_6.txt", FileMode.Create, FileAccess.Write));

            writer.Write(testConversation);
            writer.Flush();
            writer.Close();

            ConversationExporter exporter = new ConversationExporter(path + "chat_test_6.txt", path + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.ReadConversation();

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #11
0
        public void ReadConversationExceptionFilePermission()
        {
            StreamReader reader = new StreamReader(new FileStream(path + "chat.txt", FileMode.Open, FileAccess.Read), Encoding.ASCII);

            StreamWriter writer = new StreamWriter(new FileStream(path + "chat_test_5.txt", FileMode.Create, FileAccess.Write));

            writer.Write(reader.ReadToEnd());
            writer.Flush();
            writer.Close();

            ConversationExporter exporter = new ConversationExporter(path + "chat_text_5.txt", path + "chat_output.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "" });

            exporter.ReadConversation();

            bool test = exporter.ExportConversation(filter);

            Assert.IsFalse(test);
        }
Exemple #12
0
        public void TestOutputFileDataWithHiddenWordsFilter()
        {
            ConversationExporter exporter = new ConversationExporter(path + "chat.txt", path + "chat_test_4.json");
            ConversationFilters  filter   = new ConversationFilters("", "", new string[] { "NO", "ask" });
            bool test = exporter.ExportConversation(filter);

            var          serializedConversation = new StreamReader(new FileStream(path + "chat_test_4.json", FileMode.Open)).ReadToEnd();
            Conversation savedConversation      = JsonConvert.DeserializeObject <Conversation>(serializedConversation);

            Assert.IsTrue(test);

            Assert.AreEqual("My Conversation", savedConversation.name);

            var messages = savedConversation.messages.ToList();

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470901), messages[0].timestamp);
            Assert.AreEqual("bob", messages[0].sender.username);
            Assert.AreEqual("Hello there!", messages[0].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470905), messages[1].timestamp);
            Assert.AreEqual("mike", messages[1].sender.username);
            Assert.AreEqual("how are you?", messages[1].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470906), messages[2].timestamp);
            Assert.AreEqual("bob", messages[2].sender.username);
            Assert.AreEqual("I'm good thanks, do you like pie?", messages[2].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470910), messages[3].timestamp);
            Assert.AreEqual("mike", messages[3].sender.username);
            Assert.AreEqual("\\*redacted\\* let me \\*redacted\\* Angus...", messages[3].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470912), messages[4].timestamp);
            Assert.AreEqual("angus", messages[4].sender.username);
            Assert.AreEqual("Hell yes! Are we buying some pie?", messages[4].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470914), messages[5].timestamp);
            Assert.AreEqual("bob", messages[5].sender.username);
            Assert.AreEqual("\\*redacted\\* just want to know if there's anybody else in the pie society...", messages[5].content);

            Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1448470915), messages[6].timestamp);
            Assert.AreEqual("angus", messages[6].sender.username);
            Assert.AreEqual("YES! I'm the head pie eater there...", messages[6].content);
        }
Exemple #13
0
 /// <summary>
 /// Reads a <see cref="Conversation"/> from the input file path and exports it to as JSON file.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// Thrown when there is a problem with the any of the arguments.
 /// </exception>
 /// <exception cref="IOException">
 /// Thrown when something with the IO went wrong.
 /// </exception>
 public bool ExportConversation(ConversationFilters filters)
 {
     try
     {
         Conversation conversation = this.ReadConversation();
         if (conversation == null)
         {
             return(false);
         }
         Conversation filteredConversation = filters.ApplyFilters(conversation);
         return(this.WriteConversation(filteredConversation));
     }
     catch (ArgumentException e)
     {
         Console.WriteLine("Something went wrong while exporting the conversation. Please restart the appliction and try again.");
         Console.WriteLine(e.Message);
         return(false);
     }
     catch (OutOfMemoryException e)
     {
         Console.WriteLine("The application ran out of memory while exporting the conversation. Please restart the appliction and try again.");
         Console.WriteLine(e.Message);
         return(false);
     }
     catch (RegexMatchTimeoutException e)
     {
         Console.WriteLine("Appying the iflters is taking too long. Please restart the appliction and try again.");
         Console.WriteLine(e.Message);
         return(false);
     }
     catch (IOException e)
     {
         Console.WriteLine("Something went wrong in the IO while exporting the conversation. Please restart the appliction and try again.");
         Console.WriteLine(e.Message);
         return(false);
     }
 }