Example #1
0
        private void OnCreated(object source, FileSystemEventArgs e)
        {
            LoggerService.WriteLog(string.Format("Novo arquivo encontrado. Arquivo: {0}", e.FullPath), LoggerService.LogType.info);
            FileImporterService fileReader = new FileImporterService(_fileImporterConfiguration);

            fileReader.ProcessFile(e.FullPath);
        }
Example #2
0
        public void ShouldImportAFileWith31Transactions()
        {
            var fileRecorderServiceMock = new Mock <IFileRecorderService>();
            var sut      = new FileImporterService(fileRecorderServiceMock.Object);
            var filePath = GetFilePath();

            fileRecorderServiceMock.Setup(x => x.Recorder(It.IsAny <IFormFile>())).Returns(filePath);

            var qteTransactionsInFile = 31;
            var result = sut.Import(It.IsAny <IFormFile>());

            Assert.True(result != null);
            Assert.True(result.Transactions.Count == qteTransactionsInFile);
        }
Example #3
0
        private void processAllPendingFiles()
        {
            try
            {
                LoggerService.WriteLog(string.Format("Iniciando leitura do diretório {0}", _fileImporterConfiguration.inputDir), LoggerService.LogType.info);
                string[] directoryFiles = Directory.GetFiles(_fileImporterConfiguration.inputDir);

                FileImporterService fileImporterService = new FileImporterService(_fileImporterConfiguration);
                foreach (string fullFileName in directoryFiles)
                {
                    fileImporterService.ProcessFile(fullFileName);
                }
            }
            catch (Exception ex)
            {
                LoggerService.WriteLog("Ocorreu um erro durante a leitura do dretório de entrada.", LoggerService.LogType.error, ex);
            }
        }
Example #4
0
        public void TestIfImportSale()
        {
            FileContent fileContent = new FileContent();
            string      line        = "003ç10ç[1-10-100,2-10-1.50,3-1-3.30]çPedro";

            LoggerService.disableLogger = true;

            FileImporterService fileImporterService = new FileImporterService(configureFileImporterParameters());
            PrivateObject       obj = new PrivateObject(fileImporterService);

            obj.Invoke("processSales", fileContent, line);

            Assert.IsTrue(
                fileContent.Sales.Count == 1 &&
                fileContent.Sales[0].SaleId == 10 &&
                fileContent.Sales[0].SalesmanName == "Pedro" &&
                fileContent.Sales[0].SalesTotalValue == 1018.3m
                );
        }
Example #5
0
        public void TestIfImportCustomer()
        {
            FileContent fileContent = new FileContent();
            string      line        = "002ç2345675434544345çJose da SilvaçRural";

            LoggerService.disableLogger = true;

            FileImporterService fileImporterService = new FileImporterService(configureFileImporterParameters());
            PrivateObject       obj = new PrivateObject(fileImporterService);

            obj.Invoke("processCustomer", fileContent, line);

            Assert.IsTrue(
                fileContent.Customers.Count == 1 &&
                fileContent.Customers[0].Name == "Jose da Silva" &&
                fileContent.Customers[0].CNPJ == "2345675434544345" &&
                fileContent.Customers[0].BusinessArea == "Rural"
                );
        }
Example #6
0
        public void TestIfImportSeller()
        {
            FileContent fileContent = new FileContent();
            string      line        = "001ç3245678865434çPauloç40000.99";

            LoggerService.disableLogger = true;

            FileImporterService fileImporterService = new FileImporterService(configureFileImporterParameters());
            PrivateObject       obj = new PrivateObject(fileImporterService);

            obj.Invoke("processSeller", fileContent, line);

            Assert.IsTrue(
                fileContent.Sellers.Count == 1 &&
                fileContent.Sellers[0].Name == "Paulo" &&
                fileContent.Sellers[0].CPF == "3245678865434" &&
                fileContent.Sellers[0].Salary == 40000.99m
                );
        }
Example #7
0
        public void TestSumarizeReport()
        {
            LoggerService.disableLogger = true;
            FileContent fileContent = new FileContent();

            fileContent.Sales.Add(new Sales {
                SaleId = 1, SalesmanName = "Pedro", SalesTotalValue = 100
            });
            fileContent.Sales.Add(new Sales {
                SaleId = 2, SalesmanName = "Carlos", SalesTotalValue = 200
            });
            fileContent.Sales.Add(new Sales {
                SaleId = 3, SalesmanName = "Pedro", SalesTotalValue = 200
            });
            fileContent.Sellers.Add(new Seller {
                CPF = "111111111", Name = "Pedro", Salary = 2500.55m
            });
            fileContent.Sellers.Add(new Seller {
                CPF = "222222222", Name = "Carlos", Salary = 2800.55m
            });
            fileContent.Customers.Add(new Customer {
                CNPJ = "99999999999999", BusinessArea = "TI", Name = "XXX LTDA"
            });
            fileContent.Customers.Add(new Customer {
                CNPJ = "88888888888888", BusinessArea = "Agro", Name = "YYY LTDA"
            });

            FileImporterService fileImporterService = new FileImporterService(configureFileImporterParameters());
            PrivateObject       obj = new PrivateObject(fileImporterService);

            OutputFileContent summarizeFile = (OutputFileContent)obj.Invoke("summarizeFile", fileContent);

            Assert.IsTrue(
                summarizeFile.CustomerCount == 2 &&
                summarizeFile.SellerCount == 2 &&
                Enumerable.SequenceEqual(summarizeFile.ExpensiveSaleId, new int[] { 2, 3 }) &&
                Enumerable.SequenceEqual(summarizeFile.WorstSaller, new string[] { "Carlos" })
                );
        }