578 lines
26 KiB
C#
578 lines
26 KiB
C#
using System;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using DataAccessLayer;
|
|
using System.Data;
|
|
using System.Threading;
|
|
using System.IO;
|
|
using ICSharpCode.SharpZipLib;
|
|
using System.Collections.Generic;
|
|
using ICSharpCode.SharpZipLib.Zip;
|
|
using GestoreTrimestrale.Logic;
|
|
using SmartFTP.Logic;
|
|
using AppConfigParser;
|
|
using System.Configuration;
|
|
|
|
namespace GestoreTrimestrale.Test
|
|
{
|
|
|
|
[TestClass]
|
|
public class UnitTest1
|
|
{
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
public UnitTest1()
|
|
{
|
|
|
|
}
|
|
|
|
//TEST CONFIGURATION
|
|
private string PDFProcessFolder { get { return @"C:\ReportisticaTrimestrale\PDF"; } }
|
|
private string PDFOutputFolder { get { return @"C:\ReportisticaTrimestrale\PDFtoDB"; } }
|
|
private string ZipFolder { get { return @"C:\ReportisticaTrimestrale\SELECTA\"; } }
|
|
private string ZipBackupFolder { get { return @"C:\ReportisticaTrimestrale\SEND\"; } }
|
|
private string WorkFolder { get { return ZipFolder + @"temp\"; } }
|
|
private string GestorePDFLocation { get { return @"C:\Projekty\Fideuram\ContrattoSEI\GestorePDF_NuoviSviluppi\bin\Debug\GestorePDF.exe"; } }
|
|
|
|
string FtpServer = @"10.0.8.22"; //your ftp server
|
|
string FtpUser = "pkowalski@hpe.com";
|
|
string FtpPassword = "password";
|
|
string FtpPath = @"/ddd/aaaa/";
|
|
|
|
private int NumberOfConcurrentGestorePDFProcesses { get { return 1; } }
|
|
private int NumberOfFiscalCodesPerFile { get { return 3; } }
|
|
|
|
private int ProduceHugeSetTestSample()
|
|
{
|
|
int i;
|
|
using (DataAccessDE d = new DataAccessDE(DBProvider.SqlServerStampeC6))
|
|
{
|
|
i = Int32.Parse(d.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "test.GESTIONE_PDF_PREPARE_TEST_SAMPLE3", null).ToString());
|
|
}
|
|
return i;
|
|
}
|
|
|
|
|
|
private string[,] OneTestSample
|
|
{
|
|
get
|
|
{
|
|
string[,] testSamples = new string[1, 2];
|
|
//testSamples[0, 0] = "DRSGRG58P10F241S"; testSamples[0, 1] = "F";
|
|
//testSamples[0, 0] = "CRGLRT47D28D332H"; testSamples[0, 1] = "F";
|
|
//testSamples[0, 0] = "CHRGLN62T17H501I"; testSamples[0, 1] = "F";
|
|
testSamples[0, 0] = "DRSGRG58P10F241S"; testSamples[0, 1] = "F";
|
|
return testSamples;
|
|
|
|
//F CRGLRT47D28D332H
|
|
}
|
|
|
|
}
|
|
|
|
private string[,] QuickTestSamples
|
|
{
|
|
get
|
|
{
|
|
string[,] testSamples = new string[6, 2];
|
|
testSamples[0, 0] = "BBNGCR56R59F817O"; testSamples[0, 1] = "S";
|
|
testSamples[1, 0] = "GGLMCN62M44F112K"; testSamples[1, 1] = "S";
|
|
testSamples[2, 0] = "GZZMLV44P59B328P"; testSamples[2, 1] = "S";
|
|
testSamples[3, 0] = "NSTGNN50L27F205U"; testSamples[3, 1] = "F";
|
|
testSamples[4, 0] = "ZCCLNR58P49H501R"; testSamples[4, 1] = "F";
|
|
testSamples[5, 0] = "BCCFST33L11F453G"; testSamples[5, 1] = "F";
|
|
//testSamples[1, 0] = "BRTMRC46R04D749A"; testSamples[1, 1] = "F";
|
|
//testSamples[2, 0] = "MLPMRA28M55C406X"; testSamples[2, 1] = "F";
|
|
//testSamples[3, 0] = "NGRNGL63E25E648B"; testSamples[3, 1] = "F";
|
|
|
|
//testSamples[4, 0] = "DRSGRG58P10F241S"; testSamples[4, 1] = "F";
|
|
//testSamples[5, 0] = "FNCNRM57H15F205I"; testSamples[5, 1] = "F";
|
|
return testSamples;
|
|
}
|
|
|
|
}
|
|
|
|
private string[,] TestSamples
|
|
{
|
|
get
|
|
{
|
|
string[,] test_samples = new string[40, 2]; //codice,rete
|
|
//string[,] test_samples = new string[3, 2]; //codice,rete
|
|
test_samples[0, 0] = "DRSGRG58P10F241S"; test_samples[0, 1] = "F";
|
|
test_samples[1, 0] = "FNCNRM57H15F205I"; test_samples[1, 1] = "F";
|
|
test_samples[2, 0] = "FRRLRD50D16D150B"; test_samples[2, 1] = "F";
|
|
test_samples[3, 0] = "DLLLCU68C22L682C"; test_samples[3, 1] = "F";
|
|
test_samples[4, 0] = "GLLPRN37C13H473T"; test_samples[4, 1] = "F";
|
|
test_samples[5, 0] = "GDURRT61P13F205Y"; test_samples[5, 1] = "F";
|
|
test_samples[6, 0] = "FRRRST43T21L048T"; test_samples[6, 1] = "F";
|
|
test_samples[7, 0] = "GFNNCL71A31E625V"; test_samples[7, 1] = "F";
|
|
|
|
test_samples[8, 0] = "BCCFBA48L19E463D"; test_samples[8, 1] = "F";
|
|
test_samples[9, 0] = "BCCFMN35C62B519D"; test_samples[9, 1] = "F";
|
|
test_samples[10, 0] = "BCCFNC30H12L219Y"; test_samples[10, 1] = "F";
|
|
test_samples[11, 0] = "BCCFNC44C29C814C"; test_samples[11, 1] = "F";
|
|
test_samples[12, 0] = "BCCFNC67D28G568Y"; test_samples[12, 1] = "F";
|
|
test_samples[13, 0] = "BCCFNN35L08H501W"; test_samples[13, 1] = "F";
|
|
test_samples[14, 0] = "BCCFNN70H50L219T"; test_samples[14, 1] = "F";
|
|
test_samples[15, 0] = "BCCFPP78H19G999V"; test_samples[15, 1] = "F";
|
|
test_samples[16, 0] = "BCCFST33L11F453G"; test_samples[16, 1] = "F";
|
|
test_samples[17, 0] = "BCCFST51L26H225B"; test_samples[17, 1] = "F";
|
|
test_samples[18, 0] = "BCCGCR34S26H710X"; test_samples[18, 1] = "F";
|
|
test_samples[19, 0] = "BCCGCR40L30H501U"; test_samples[19, 1] = "F";
|
|
test_samples[20, 0] = "BCCGCR52M16D612E"; test_samples[20, 1] = "F";
|
|
test_samples[21, 0] = "BCCGCR58C10H683W"; test_samples[21, 1] = "F";
|
|
test_samples[22, 0] = "BCCGCR62E31L117P"; test_samples[22, 1] = "F";
|
|
test_samples[23, 0] = "BCCGDU65E08G674V"; test_samples[23, 1] = "F";
|
|
test_samples[24, 0] = "BCCGGG53D13L219Z"; test_samples[24, 1] = "F";
|
|
test_samples[25, 0] = "BCCGLC63C24L219N"; test_samples[25, 1] = "F";
|
|
test_samples[26, 0] = "BCCGLD34D13A182H"; test_samples[26, 1] = "F";
|
|
test_samples[27, 0] = "BCCGLG55E28A182G"; test_samples[27, 1] = "F";
|
|
test_samples[28, 0] = "BCCGLN47P21I187G"; test_samples[28, 1] = "F";
|
|
test_samples[29, 0] = "BCCGLN49L62C750K"; test_samples[29, 1] = "F";
|
|
test_samples[30, 0] = "BCCGMR41P70A163E"; test_samples[30, 1] = "F";
|
|
test_samples[31, 0] = "BCCGNN27L23G337A"; test_samples[31, 1] = "F";
|
|
test_samples[32, 0] = "BCCGNN34E09I512K"; test_samples[32, 1] = "F";
|
|
test_samples[33, 0] = "BCCGNN35T57G713V"; test_samples[33, 1] = "F";
|
|
test_samples[34, 0] = "BCCGNN42R11F205L"; test_samples[34, 1] = "F";
|
|
test_samples[35, 0] = "BCCGPL48A12E730Y"; test_samples[35, 1] = "F";
|
|
test_samples[36, 0] = "BCCGNN44C11A291B"; test_samples[36, 1] = "F";
|
|
test_samples[37, 0] = "BCCGNN45A57F033V"; test_samples[37, 1] = "F";
|
|
test_samples[38, 0] = "BCCGNN56M14C265P"; test_samples[38, 1] = "F";
|
|
test_samples[39, 0] = "BCCGNR49A21L628O"; test_samples[39, 1] = "F";
|
|
//test_samples[40, 0] = "BCCGNN43B12I002A"; test_samples[40, 1] = "F";
|
|
|
|
/*
|
|
test_samples[40, 0] = "PSTBRN29M70G528H"; test_samples[40, 1] = "S";
|
|
test_samples[41, 0] = "PLNLSN38P28G401U"; test_samples[41, 1] = "S";
|
|
test_samples[42, 0] = "TLICCT55D19C351B"; test_samples[42, 1] = "S";
|
|
test_samples[43, 0] = "ZMBDNL49E45H501D"; test_samples[43, 1] = "S";
|
|
test_samples[44, 0] = "PGLVCN44C50F817O"; test_samples[44, 1] = "S";
|
|
test_samples[45, 0] = "NGRCLD62A47Z404V"; test_samples[45, 1] = "S";
|
|
test_samples[46, 0] = "PRTRST58T53L219L"; test_samples[46, 1] = "S";
|
|
test_samples[47, 0] = "MRTFRL70D17Z114U"; test_samples[47, 1] = "S";
|
|
test_samples[48, 0] = "SVNSVN61R15L295O"; test_samples[48, 1] = "S";
|
|
test_samples[49, 0] = "ZPPDRD57E15G493Z"; test_samples[49, 1] = "S";
|
|
test_samples[50, 0] = "LZTPCR47S29A017U"; test_samples[50, 1] = "S";
|
|
test_samples[51, 0] = "MCCVTR41E09F736B"; test_samples[51, 1] = "S";
|
|
test_samples[52, 0] = "MSTDRN62S06H501I"; test_samples[52, 1] = "S";
|
|
test_samples[53, 0] = "MRZCLL53B45A794N"; test_samples[53, 1] = "S";
|
|
test_samples[54, 0] = "CRRDMN62T04B300J"; test_samples[54, 1] = "S";
|
|
test_samples[55, 0] = "MSTMRS55S65A783N"; test_samples[55, 1] = "S";
|
|
test_samples[56, 0] = "MRZMNC59P68A794V"; test_samples[56, 1] = "S";
|
|
test_samples[57, 0] = "LTTPQL56A05I129D"; test_samples[57, 1] = "S";
|
|
test_samples[58, 0] = "CRRCLD58D09L840T"; test_samples[58, 1] = "S";
|
|
test_samples[59, 0] = "KPJVDM70H06Z100X"; test_samples[59, 1] = "S";
|
|
test_samples[60, 0] = "JCCGRG38T27A326Q"; test_samples[60, 1] = "S";
|
|
test_samples[61, 0] = "DBNFNC38L24D969G"; test_samples[61, 1] = "S";
|
|
test_samples[62, 0] = "ZPPNGL23M70L633U"; test_samples[62, 1] = "S";
|
|
test_samples[63, 0] = "GSPMGR31T69G482B"; test_samples[63, 1] = "S";
|
|
test_samples[64, 0] = "LVRDLA25S47B157C"; test_samples[64, 1] = "S";
|
|
test_samples[65, 0] = "NCLFNC61R29G482Y"; test_samples[65, 1] = "S";
|
|
test_samples[66, 0] = "DBRRFL58B08G902Z"; test_samples[66, 1] = "S";
|
|
test_samples[67, 0] = "CRSLRN54D28C847X"; test_samples[67, 1] = "S";
|
|
test_samples[68, 0] = "GAIRCE76T49A182F"; test_samples[68, 1] = "S";
|
|
test_samples[69, 0] = "CRVDNC70R18H324X"; test_samples[69, 1] = "S";
|
|
test_samples[70, 0] = "GMBGLC61C13H223L"; test_samples[70, 1] = "S";*/
|
|
return test_samples;
|
|
}
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public void SetUpTestSamples()
|
|
{
|
|
if (!Utils.ProduceTestSamples(QuickTestSamples))
|
|
Assert.Fail("can't produce test samples");
|
|
Assert.AreEqual(1, 1);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SetUpZipCases_DoNotUse() //to clean up the mess with statuses
|
|
{
|
|
string sql = "Update C6MartPeriodico.controllo_trimestrale Set Stato_Report = 6 WHERE Stato_Report = 4 ";
|
|
DataAccess.ExecuteNonQuery(DBProvider.SqlServerStampeC6, CommandType.Text, sql);
|
|
sql = "Update C6MartPeriodico.controllo_trimestrale Set Stato_Report = 4 WHERE ";
|
|
for (int i = 0; i < QuickTestSamples.GetLength(0); i++)
|
|
{
|
|
sql += " (cod_fiscale = '" + QuickTestSamples[i, 0] + "' and rete = '" + QuickTestSamples[i, 1] + "')";
|
|
sql += " or";
|
|
}
|
|
sql = sql.Substring(0, sql.Length - 3);
|
|
DataAccess.ExecuteNonQuery(DBProvider.SqlServerStampeC6, CommandType.Text, sql);
|
|
Assert.AreEqual(1,1);
|
|
}
|
|
|
|
|
|
//test if process can complete - produce pdf and pack them
|
|
[TestMethod]
|
|
public void ProcessCanComplete_PDFOnly()
|
|
{
|
|
string tempFolder = PDFProcessFolder;
|
|
string zipFolder = ZipFolder;
|
|
string pdfOutputFolder = PDFOutputFolder;
|
|
|
|
int maxProcessiGestorePDF = NumberOfConcurrentGestorePDFProcesses;
|
|
string pathProcesso = GestorePDFLocation;
|
|
|
|
Utils.DeleteFiles(zipFolder);
|
|
Utils.DeleteFiles(pdfOutputFolder);
|
|
Utils.DeleteFiles(tempFolder);
|
|
|
|
if (!Utils.ProduceTestSamples(QuickTestSamples))
|
|
Assert.Fail("can't produce test samples");
|
|
|
|
int maxGestoreThreads = int.Parse(ConfigurationManager.AppSettings["maxGestoreThreads"]);
|
|
int limit = int.Parse(ConfigurationManager.AppSettings["gestoreThreadsLimit"]);
|
|
if (limit < maxGestoreThreads) maxGestoreThreads = limit;
|
|
|
|
GestorePDF.Logic.ThreadManager m = new GestorePDF.Logic.ThreadManager();
|
|
m.Main(maxGestoreThreads);
|
|
int files_ctr = Utils.CountFiles(PDFProcessFolder, "pdf");
|
|
if (files_ctr < OneTestSample.GetLength(0))
|
|
Assert.Fail("Number of records in Output Folder should be greater or equal the number of samples");
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void FlushFilesWaitingForZIP()
|
|
{
|
|
|
|
string q1 = "update C6MartPeriodico.controllo_trimestrale set stato_report = 10 where stato_report in (4)";
|
|
//string q4 = "update C6MartPeriodico.controllo_trimestrale set stato_report = 10 where stato_report in (2)";
|
|
// string q5 = "update C6MartPeriodico.controllo_trimestrale set stato_report = 10 where stato_report in (3)";
|
|
string q2 = "update C6MartPeriodico.controllo_trimestrale set stato_report = 10 where stato_report in (1)";
|
|
string q3 = "update C6MartPeriodico.CRUSCOTTO_CONTRATTISEI set elab = 10 where elab in(1,2)";
|
|
|
|
using(DataAccessDE de = new DataAccessDE(DBProvider.SqlServerStampeC6))
|
|
{
|
|
de.ExecuteNonQuery(CommandType.Text, q1);
|
|
de.ExecuteNonQuery(CommandType.Text, q2);
|
|
de.ExecuteNonQuery(CommandType.Text, q3);
|
|
//de.ExecuteNonQuery(CommandType.Text, q4);
|
|
// de.ExecuteNonQuery(CommandType.Text, q5);
|
|
}
|
|
|
|
Assert.AreNotEqual(1, 2);
|
|
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ProcessCanComplete_PDFOnly_HugeSet()
|
|
{
|
|
string tempFolder = PDFProcessFolder;
|
|
string zipFolder = ZipFolder;
|
|
string pdfOutputFolder = PDFOutputFolder;
|
|
|
|
int maxProcessiGestorePDF = NumberOfConcurrentGestorePDFProcesses;
|
|
string pathProcesso = GestorePDFLocation;
|
|
|
|
Utils.DeleteFiles(zipFolder);
|
|
Utils.DeleteFiles(pdfOutputFolder);
|
|
Utils.DeleteFiles(tempFolder);
|
|
|
|
int i = ProduceHugeSetTestSample();
|
|
GestorePDF.Logic.ThreadManager m = new GestorePDF.Logic.ThreadManager();
|
|
m.Main();
|
|
int files_ctr = Utils.CountFiles(PDFProcessFolder, "pdf");
|
|
if (files_ctr < i)
|
|
Assert.Fail("Number of records in Output Folder should be greater or equal the number of samples");
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public void ProcessCanComplete_ProduceHugeSet()
|
|
{
|
|
string tempFolder = PDFProcessFolder;
|
|
string zipFolder = ZipFolder;
|
|
string pdfOutputFolder = PDFOutputFolder;
|
|
|
|
int maxProcessiGestorePDF = NumberOfConcurrentGestorePDFProcesses;
|
|
string pathProcesso = GestorePDFLocation;
|
|
|
|
Utils.DeleteFiles(zipFolder);
|
|
Utils.DeleteFiles(pdfOutputFolder);
|
|
Utils.DeleteFiles(tempFolder);
|
|
|
|
int i = ProduceHugeSetTestSample();
|
|
|
|
Assert.IsTrue(i>0);
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public void ProcessCanComplete_ZIPOnly()
|
|
{
|
|
string tempFolder = PDFProcessFolder;
|
|
string zipFolder = ZipFolder;
|
|
string pdfOutputFolder = PDFOutputFolder;
|
|
|
|
int maxProcessiGestorePDF = NumberOfConcurrentGestorePDFProcesses;
|
|
string pathProcesso = GestorePDFLocation;
|
|
|
|
Utils.DeleteFiles(zipFolder);
|
|
Utils.DeleteFiles(pdfOutputFolder);
|
|
|
|
using (ZipManagerProcess myZipManager = new ZipManagerProcess(1, @"c:\temp\o.txt",false, null, "APPROVAL", "APP", "NOAPP", true,1))
|
|
{
|
|
//myZipManager.Start(null);
|
|
while (myZipManager.Status != ManagerProcessStatusEnum.Completed)
|
|
{
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
int files_ctr = Utils.CountFiles(pdfOutputFolder, "pdf");
|
|
if (files_ctr < QuickTestSamples.GetLength(0))
|
|
Assert.Fail("Number of records in Output Folder should be greater of equal the number of samples");
|
|
Assert.AreEqual(Utils.CountFiles(tempFolder, "*"), 0); //no files remain in temp folder
|
|
Assert.AreEqual(Utils.CountSubFolders(tempFolder), 0); //no subfolders remain in temp folder
|
|
}
|
|
|
|
|
|
//test if process can complete - produce pdf and pack them
|
|
[TestMethod]
|
|
public void ProcessCanComplete()
|
|
{
|
|
string tempFolder = PDFProcessFolder;
|
|
string zipFolder = ZipFolder;
|
|
string pdfOutputFolder = PDFOutputFolder;
|
|
|
|
int maxProcessiGestorePDF = NumberOfConcurrentGestorePDFProcesses;
|
|
string pathProcesso = GestorePDFLocation;
|
|
|
|
Utils.DeleteFiles(zipFolder);
|
|
Utils.DeleteFiles(pdfOutputFolder);
|
|
Utils.DeleteFiles(tempFolder);
|
|
|
|
//if (!Utils.ProduceTestSamples(TestSamples))
|
|
// Assert.Fail("can't produce test samples");
|
|
|
|
Thread t = new Thread(() => {
|
|
GestorePDF.Logic.ThreadManager m = new GestorePDF.Logic.ThreadManager();
|
|
m.Main();
|
|
});
|
|
|
|
t.Start();
|
|
|
|
using (ZipManagerProcess myZipManager = new ZipManagerProcess(1, @"c:\temp\o.txt"))
|
|
{
|
|
//myZipManager.Start(null);
|
|
while (myZipManager.Status != ManagerProcessStatusEnum.Completed)
|
|
{
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
int files_ctr = Utils.CountFiles(pdfOutputFolder, "pdf");
|
|
if (files_ctr < TestSamples.GetLength(0))
|
|
Assert.Fail("Number of records in Output Folder should be greater of equal the number of samples");
|
|
Assert.AreEqual(Utils.CountFiles(tempFolder, "*"), 0); //no files remain in temp folder
|
|
Assert.AreEqual(Utils.CountSubFolders(tempFolder), 0); //no subfolders remain in temp folder
|
|
}
|
|
|
|
//check if number of pdf files in zip is the same as in the index file
|
|
[TestMethod]
|
|
public void ZipIntegrity()
|
|
{
|
|
string fileName;
|
|
string zipFolder = ZipFolder;
|
|
string workFolder = WorkFolder;
|
|
if (!Directory.Exists(workFolder))
|
|
Directory.CreateDirectory(workFolder);
|
|
|
|
foreach (FileInfo f in new DirectoryInfo(zipFolder).GetFiles())
|
|
{
|
|
fileName = f.Name;
|
|
Utils.DeleteFiles(workFolder);
|
|
Utils.Decompress(f, workFolder);
|
|
int numberOfPdfFiles = 0; //number of pdf files
|
|
int numberOfRecordsInIndex = 0; // numble of lines in index file
|
|
foreach (FileInfo a in new DirectoryInfo(workFolder).GetFiles())
|
|
{
|
|
if (a.Extension != ".pdf")
|
|
{
|
|
using (TextReader r = a.OpenText())
|
|
{
|
|
while (r.ReadLine() != null)
|
|
{
|
|
numberOfRecordsInIndex++;
|
|
}
|
|
}
|
|
}
|
|
else if (a.Name.Substring(a.Name.Length-7, 7) != "_DP.pdf")
|
|
{
|
|
string z = a.Name.Substring(a.Name.Length - 7, 7);
|
|
numberOfPdfFiles++;
|
|
}
|
|
}
|
|
Assert.AreEqual(numberOfPdfFiles, numberOfRecordsInIndex, "File Integrity check failed for " + fileName);
|
|
}
|
|
|
|
if (Directory.Exists(workFolder))
|
|
{
|
|
foreach (string s in Directory.GetFiles(workFolder))
|
|
{
|
|
FileInfo fi = new FileInfo(s);
|
|
fi.Delete();
|
|
}
|
|
Directory.Delete(workFolder);
|
|
}
|
|
}
|
|
|
|
//check if zip files contain correct pdf documents
|
|
[TestMethod]
|
|
public void NumberOfPackedPDFIsOK()
|
|
{
|
|
string zipFolder = ZipFolder;
|
|
string workFolder = WorkFolder;
|
|
if (!Directory.Exists(workFolder))
|
|
Directory.CreateDirectory(workFolder);
|
|
|
|
foreach (FileInfo f in new DirectoryInfo(zipFolder).GetFiles())
|
|
{
|
|
string name = f.Name.Substring(32, 4);
|
|
string selectPDF = "SELECT nomeFile FROM [C6MartPeriodico].[GESTIONE_PDF_FTP] " +
|
|
"WHERE id_fk_zip = " + name;
|
|
DataTable rows = DataAccess.ExecuteDataTable(DBProvider.SqlServerStampeC6, CommandType.Text, selectPDF);
|
|
Utils.DeleteFiles(workFolder);
|
|
Utils.Decompress(f, workFolder);
|
|
bool fileExists = false;
|
|
int ctr = 0;
|
|
foreach (DataRow i in rows.Rows)
|
|
{
|
|
foreach (var j in new DirectoryInfo(workFolder).GetFiles())
|
|
{
|
|
string ffile = j.Name.Substring(0, j.Name.IndexOf("."));
|
|
if (i["nomeFile"].ToString()+"_MP" == j.Name.Substring(0,j.Name.IndexOf(".")))
|
|
{
|
|
fileExists = true;
|
|
break;
|
|
}
|
|
}
|
|
if (fileExists) ctr++;
|
|
}
|
|
Assert.AreEqual(ctr, Directory.GetFiles(workFolder).Length - 1);
|
|
}
|
|
if (Directory.Exists(workFolder)){
|
|
foreach (string s in Directory.GetFiles(workFolder))
|
|
{
|
|
FileInfo fi = new FileInfo(s);
|
|
fi.Delete();
|
|
}
|
|
Directory.Delete(workFolder);
|
|
}
|
|
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestFTPSendingProcess()
|
|
{
|
|
string zipFolder = ZipFolder;
|
|
string backupFolder = ZipBackupFolder;
|
|
string ftpServer = FtpServer; //your ftp server
|
|
string ftpUser = FtpUser;
|
|
string ftpPassword = FtpPassword;
|
|
string ftpPath = FtpPath;
|
|
int res = FTPProcessSeparated.UploadTrimestraleFiles(zipFolder, ftpServer, ftpPath, ftpUser, ftpPassword, backupFolder);
|
|
Assert.AreEqual(1, res);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestVerifier()
|
|
{
|
|
PDFGenerator.Verifier.Verifier v = new PDFGenerator.Verifier.Verifier();
|
|
var x = v.GetInvalidFiles(@"C:\ReportisticaTrimestrale\PDF_LINE", 30);
|
|
Assert.AreEqual(0, x.Count);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestAppConfigSaveLoad()
|
|
{
|
|
string directory = Directory.GetCurrentDirectory();
|
|
string defaultAppConfig = String.Concat(directory, @"\", "AppConfig.xml");
|
|
string testAppConfig = String.Concat(directory, @"\", "AppConfig2.xml");
|
|
|
|
//values in current config
|
|
string expectedConnString = "Data Source=10.14.152.19; Database=C6StampeCentralizzate_31032016;User Id=F701264; Password=contrsei; Max Pool Size=1000;Pooling=yes;Load Balance Timeout=1000; Connection Timeout=200";
|
|
string expectedEstensioneFile = "IDX";
|
|
string expectedNumeroCfPerZip = "960";
|
|
|
|
//values we want to have
|
|
string desiredConnString = "Data Source=10.14.152.191; Database=C6StampeCentralizzate_31032016;User Id=F701264; Password=contrsei; Max Pool Size=1000;Pooling=yes;Load Balance Timeout=1000; Connection Timeout=200";
|
|
string desiredEstensioneFile = "IDXX";
|
|
string desiredNumeroCfPerZip = "9600";
|
|
|
|
//values after save and load
|
|
string realConnString;
|
|
string realEstensioneFile;
|
|
string realNumeroCfPerZip;
|
|
|
|
//making sure AppConfig2.xml does not exists
|
|
if (File.Exists(testAppConfig))
|
|
File.Delete(testAppConfig);
|
|
|
|
//loading default config
|
|
using (IAppConfigurationParser parser = new XmlConfigurationParser())
|
|
{
|
|
parser.LoadFrom(defaultAppConfig);
|
|
}
|
|
|
|
realConnString = ConfigurationManager.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString;
|
|
realEstensioneFile = ConfigurationManager.AppSettings["EstensioneFile"].ToString();
|
|
realNumeroCfPerZip = ConfigurationManager.AppSettings["numeroCfPerZip"].ToString();
|
|
|
|
//checking if values are correct
|
|
Assert.AreEqual(expectedConnString, realConnString);
|
|
Assert.AreEqual(expectedEstensioneFile, realEstensioneFile);
|
|
Assert.AreEqual(expectedNumeroCfPerZip, realNumeroCfPerZip);
|
|
|
|
//saving modified config
|
|
Configuration config =
|
|
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
config.ConnectionStrings.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString =
|
|
desiredConnString;
|
|
|
|
config.AppSettings.Settings["EstensioneFile"].Value = desiredEstensioneFile;
|
|
config.AppSettings.Settings["numeroCfPerZip"].Value = desiredNumeroCfPerZip;
|
|
|
|
config.Save(ConfigurationSaveMode.Minimal, true);
|
|
|
|
//refreshing config to save to file
|
|
ConfigurationManager.RefreshSection("connectionStrings");
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
|
|
using (IAppConfigurationParser parser = new XmlConfigurationParser())
|
|
{
|
|
//saving to file
|
|
parser.SaveTo(testAppConfig);
|
|
}
|
|
|
|
using (IAppConfigurationParser parser = new XmlConfigurationParser())
|
|
{
|
|
//loading modified config
|
|
parser.LoadFrom(testAppConfig);
|
|
}
|
|
|
|
realConnString = ConfigurationManager.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString;
|
|
realEstensioneFile = ConfigurationManager.AppSettings["EstensioneFile"].ToString();
|
|
realNumeroCfPerZip = ConfigurationManager.AppSettings["numeroCfPerZip"].ToString();
|
|
|
|
|
|
//checking if values were saved as expected
|
|
Assert.AreEqual(desiredConnString, realConnString);
|
|
Assert.AreEqual(desiredEstensioneFile, realEstensioneFile);
|
|
Assert.AreEqual(desiredNumeroCfPerZip, realNumeroCfPerZip);
|
|
|
|
}
|
|
|
|
//TODO
|
|
//[TestMethod]
|
|
public void TestFTPSendingProcess_old()
|
|
{
|
|
string ambiente = "SVILUPPO";
|
|
string tngServer = "";
|
|
string tngJobset = "";
|
|
string tngJob = "";
|
|
SmartFTPThread.Logic.FtpProcessSeparated.StartProcessing(ambiente, tngServer, tngJobset, tngJob);
|
|
}
|
|
}
|
|
}
|