public void HandleLinePath(string arr, int clientsQuant, int salesmanQuant, int idMostExpensive, string wrstSalesman)
        {
            SaleLot saleLot = new SaleLot("tst", "tst");

            foreach (var item in arr.Split('|'))
            {
                saleLot.HandleFileLine(item);
            }

            Assert.Equal(saleLot.Clients.Count, clientsQuant);
            Assert.Equal(saleLot.Salesmans.Count, salesmanQuant);
            Assert.Equal(saleLot.GetMostExpensiveSaleId(), idMostExpensive);
            Assert.Equal(saleLot.GetWhorstSalesman(), wrstSalesman);
        }
Beispiel #2
0
        private static void OnChanged(object source, FileSystemEventArgs file)
        {
            SaleLot saleLot = new SaleLot(file.Name, file.FullPath);

            const Int32 BufferSize = 128;

            using (var fileStream = new FileStream(saleLot.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    String line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        saleLot.HandleFileLine(line);
                    }
                    ;
                }
            }

            string path = string.Concat(HOMEPATH, @"\data\out\", file.Name);

            // Delete file if exists
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(path))
            {
                sw.WriteLine($"Quantidade de clientes no arquivo de entrada: {saleLot.Clients.Count} ");
                sw.WriteLine($"Quantidade de vendedores no arquivo de entrada: {saleLot.Salesmans.Count}");
                sw.WriteLine($"ID da venda mais cara: {saleLot.GetMostExpensiveSaleId()}");
                sw.WriteLine($"O pior vendedor: {saleLot.GetWhorstSalesman()} ");
                if (saleLot.Errors.Count > 0)
                {
                    sw.WriteLine($"\n Erros: \n {saleLot.GetErrors()}");
                }
            }
        }