public void Success_ReadAndConvertFiles( string pCommandLine, TestConsole pConsoleCommandLine, InOutService pInOutService, [Frozen] IVendorService pVendorService) { // Setup data BaseResultModel <Vendor> fModel = new BaseResultModel <Vendor>(new Vendor(), null); // Setup services pVendorService .CreateOrUpdate(Arg.Any <Vendor>()) .Returns(fModel); var pCommand = new SyncVendorsCommand(pVendorService, pInOutService, null); // Test pCommand.Invoke(pCommandLine, pConsoleCommandLine); // Validate pConsoleCommandLine.Error.ToString().Should().BeNullOrEmpty(); pVendorService.Received().CreateOrUpdate(Arg.Is <Vendor>(x => x.Id.Equals(Ids[0]))); pVendorService.Received().CreateOrUpdate(Arg.Is <Vendor>(x => x.Id.Equals(Ids[1]))); pVendorService.Received().CreateOrUpdate(Arg.Is <Vendor>(x => x.Id.Equals(Ids[2]))); }
private async Task CreateVendorHandler( CreateVendorInput pComplexType) { var fCreateVendor = new Vendor { Name = pComplexType.Name ?? pComplexType.AdministrationCode, VatNumber = string.Empty, CountryCode = pComplexType.Country, Iban = pComplexType.Iban.ToList(), CurrencyCode = pComplexType.Currency, VendorCustomerCode = string.Empty, DefaultLedgerCode = pComplexType.Ledger, DefaultVatCode = pComplexType.Vat, DefaultVatScenarioCode = string.Empty, DefaultPaymentTermCode = pComplexType.Payment, Blocked = false, Id = Guid.Empty, AdministrationCode = pComplexType.AdministrationCode, IdCompany = pComplexType.CompanyId }; var fResult = await _vendorService.CreateOrUpdate(fCreateVendor); //var fResult = await _vendorService.CreateOrUpdate(fCreateVendor); if (fResult.Object is null) { _logger.LogWarning($"Creating vendor failed with following error(s): {fResult.ErrorMessage}"); return; } await _utilities.HandleOutput(pComplexType.Format, fResult.Object, pComplexType.Output); }
private async Task ImportVendorsHandler( FileInfo input, EFormatType inputformat, FileInfo?output, EFormatType outputformat) { var fSyncFilePath = input.FullName; var fVendorList = File.ReadAllText(fSyncFilePath); var fVendors = _utilities.ReadAs <Vendor>(inputformat, fVendorList); if (fVendors is null) { return; } var fSuccessList = new List <Vendor>(); var fFailedList = new List <Vendor>(); var fCount = 1; var fTotalVendors = fVendors.Count; foreach (var fVendor in fVendors) { var fResult = await _vendorService.CreateOrUpdate(fVendor); if (fResult.Object == null) { fFailedList.Add(fVendor); _logger.LogWarning($"{fCount}/{fTotalVendors}: Failed syncing vendor '{fVendor.Name}' - {fResult.ErrorMessage}"); } else { fSuccessList.Add(fResult.Object); Console.WriteLine($"{fCount}/{fTotalVendors} Successfully synced vendor '{fVendor.Name}'"); } fCount++; } Console.WriteLine($"{fSuccessList.Count}/{fTotalVendors} vendors have been successfully imported"); await _utilities.HandleOutput(outputformat, fSuccessList, output); if (output != null) { await _utilities.HandleOutputToFilePath(outputformat, fFailedList, $"{output?.Directory?.FullName}/failed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); await _utilities.HandleOutputToFilePath(outputformat, fSuccessList, $"{output?.Directory?.FullName}/succeed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); } }
public void Success_ConsolOutput( EFormatType pFormat, TestConsole pConsoleCommandLine, InOutService pInOutService, [Frozen] IVendorService pVendorService, [Frozen] Vendor pVendor) { // Setup data pVendorService .CreateOrUpdate(Arg.Any <Vendor>()) .Returns(new BaseResultModel <Vendor>(pVendor, null)); var fCommandLine = $"-c IdCompany -a AdministrationCode --country CountryCode --currency CurrencyCode --iban Iban -f {pFormat}"; // Setup services var pCommand = new CreateVendorCommand(pVendorService, pInOutService, null); // Test pCommand.Invoke(fCommandLine, pConsoleCommandLine); // Validate pConsoleCommandLine.Error.ToString().Should().BeNullOrEmpty(); pVendorService.Received(1); }