public void File_does_not_exists()
        {
            string fileToParse = _folder + "InexistentFile.tsv";

            Assert.Throws <IOException>(
                delegate { _result = _parser.ParseTsvFile(fileToParse); });
        }
        public void File_without_label_to_keep()
        {
            string fileToParse = _folder + "WrongLabel.tsv";

            _result = _parser.ParseTsvFile(fileToParse);

            Assert.That(_result.ContainsKey("latency_ms"), Is.False);
            Assert.That(_result.ContainsKey("bandwidth"), Is.False);
        }
        public void File_exists_without_values_to_keep()
        {
            _parser.ValuesToKeep = new List <string> {
                "latency_ms", "bandwidth"
            };
            string fileToParse = _folder + "EmptyValue.tsv";

            Assert.Throws <FormatException>(
                delegate { _result = _parser.ParseTsvFile(fileToParse); });
        }
        public void Take_values_without_values_to_keep()
        {
            _parser.ValuesToKeep = null;
            string fileToParse = _folder + "CorrectFile.tsv";

            _result = _parser.ParseTsvFile(fileToParse);

            Assert.That(_result["latency_ms"], Is.Not.Null);
            Assert.That(_result["latency_ms"], Is.EqualTo("70"));

            Assert.That(_result["bandwidth"], Is.Not.Null);
            Assert.That(_result["bandwidth"], Is.EqualTo("20"));
        }
        public void File_exists_with_values_to_keep()
        {
            _parser.ValuesToKeep = new List <string> {
                "latency_ms", "bandwidth"
            };
            string fileToParse = _folder + "CorrectFile.tsv";

            _result = _parser.ParseTsvFile(fileToParse);

            Assert.That(_result["latency_ms"], Is.Not.Null);
            Assert.That(_result["latency_ms"], Is.EqualTo("70"));

            Assert.That(_result["bandwidth"], Is.Not.Null);
            Assert.That(_result["bandwidth"], Is.EqualTo("20"));
        }
        public FileTsv ParseTsvFile(string filePath)
        {
            var file = new FileTsv();

            try
            {
                var reader = new StreamReader(filePath);

                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    string[] values = line.Split(Separator);

                    if (values.Length < 2)
                    {
                        throw new FormatException(String.Format("The key '{0}' has no value.", values[0]));
                    }

                    if (ValuesToKeep == null)
                    {
                        file.Add(values[0], values[1]);
                    }
                    else if (ValuesToKeep.Contains(values[0]))
                    {
                        file.Add(values[0], values[1]);
                    }
                }
            }
            catch (IOException e)
            {
                throw new IOException(e.Message);
            }

            return(file);
        }