public void FileReaderIsCallledWhenCallingRead()
        {
            var handleStreams = A.Fake <IHandleStreams>();

            handleStreams.StreamReader = new StreamReader(new MemoryStream(Encoding.Default.GetBytes("hello")));
            var mode = CSVReaderWriter.Mode.Read;

            A.CallTo(() => _fileOpener.Open("someFile", mode)).Returns(handleStreams);
            _csvReaderWriter.Open("someFile", mode);
            string column1, column2;

            _csvReaderWriter.Read(out column1, out column2);
            A.CallTo(() => _fileReader.Read(out column1, out column2, handleStreams))
            .MustHaveHappened();
        }
Exemplo n.º 2
0
        List <Log> ILogToObject.LogToObj(IReadFile read, String url)
        {
            StreamReader reader     = new StreamReader(read.Read(url));
            List <Log>   listOfLogs = new List <Log>();
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                string[] lineOfLog     = line.Split('|');
                string[] methodAndPath = lineOfLog[3].Split(" ");

                string provider     = "\"MINHA CDN\"";
                string method       = methodAndPath[0].Replace("\"", "");
                int    statusCode   = Convert.ToInt32(lineOfLog[1]);
                string uri          = methodAndPath[1];
                int    timeTaken    = Convert.ToInt32(lineOfLog[0]);
                string cacheStatus  = lineOfLog[2];
                int    responseSize = Decimal.ToInt32(Convert.ToDecimal(lineOfLog[4].Replace(".", ",")));

                Log logExists = listOfLogs.Find(obj => obj.HttpMethod1 == method && obj.UriPath1 == uri);
                if (logExists != null)
                {
                    cacheStatus = "REFRESH_" + logExists.CacheStatus1;
                }
                Log log = new Log(provider, method, statusCode, uri, timeTaken, responseSize, cacheStatus);
                listOfLogs.Add(log);
            }
            reader.Close();
            return(listOfLogs);
        }
        /// <summary>
        /// Imports the data from the file.
        /// <exception cref="System.IO.InvalidDataException">Thrown when the amount of rowXcolumn is not 16X26.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when data is negative.</exception>
        /// <exception cref="System.FormatException">Thrown when data is null or, empty or, not int.</exception>
        /// <exception cref="System.OverflowException">Thrown when data is too large or, too small for an Int32.</exception>
        /// </summary>
        private void ImportData()
        {
            try
            {
                IsUnitsBoxEnabled    = false;
                IsCubicFeetSelected  = false;
                IsCubicMeterSelected = false;
                IsBarrelsSelected    = false;
                ResultText           = "";
                ImportedData         = new List <int>();

                m_TopHorizonList = m_ReadCSV.Read(ImportText);

                ImportedData = m_TopHorizonList;
                m_VolumeCalculationHelper.InitialCalculation(m_TopHorizonList);
                IsUnitsBoxEnabled   = true;
                IsCubicFeetSelected = true;
            }
            catch (InvalidDataException)
            {
                ShowErrorMessage("File does not contains the correct amount of data.");
            }
            catch (ArgumentOutOfRangeException)
            {
                ShowErrorMessage("File contains negative data.");
            }
            catch (FormatException)
            {
                ShowErrorMessage("File contains corrupt data.");
            }
            catch (OverflowException)
            {
                ShowErrorMessage("File contains too large or, too small data.");
            }
        }
 public bool Read(out string column1, out string column2)
 {
     if (_streamHandler?.StreamReader == null)
     {
         throw new Exception("Can not read the file, failed to acquire read mode");
     }
     return(_fileReader.Read(out column1, out column2, _streamHandler));
 }
Exemplo n.º 5
0
        IEnumerable <User> IFetchUsersData.Fetch()
        {
            string xmlFileContent = _fileReader.Read("Monfichier.xml");

            var xmlData = XDocument.Load(new StringReader(xmlFileContent));
            var users   = xmlData.Descendants("User")
                          .Select(d =>
            {
                var id        = (int)d.Element("Id");
                var fullName  = (string)d.Element("FullName");
                var firstName = fullName.Split(' ')[0];
                var lastName  = fullName.Split(' ')[1];
                return(new User(id, firstName, lastName));
            });

            return(users);
        }