public void DbfLibTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; var file = new FlatDatabase.DBase.File(); var output = new FlatDatabase.DBase.File(); if (file.Open(path + "File506Upload17.dbf", System.IO.FileMode.Open)) { var out_columns = new List <FlatDatabase.ColumnInfo>(file.Columns); out_columns.Add(new FlatDatabase.ColumnInfo() { Name = "caseid", DataType = typeof(string), Length = 20 }); out_columns.Add(new FlatDatabase.ColumnInfo() { Name = "status", DataType = typeof(string), Length = 20 }); output.Create(path + "File506Upload17_out.dbf", out_columns); string str = string.Empty; int i = 0; foreach (FlatDatabase.ColumnInfo col in file.Columns) { if (0 != i++) { str += "\t"; } str += col.Name; } Console.WriteLine(str); for (file.Position = 0; file.Position < file.RecordCount; file.Position++) { str = string.Empty; i = 0; output.AppendRecord(); for (i = 0; i < file.Columns.Count; i++) { var col = file.Columns[i]; if (0 != i) { str += "\t"; } var value = file.GetData(col); output.WriteField(output.Columns[i], file.GetString(col)); str += file.GetString(col); //break; } output.WriteField(output.Columns[i++], "Case"); output.WriteField(output.Columns[i], "status"); output.SaveRecord(); Console.WriteLine("{0,5} {1}", file.Position, str); //break; } file.Close(); output.Close(); } }
public void AvrSearchObjectCheckTest() { using (DbManagerProxy manager = DbManagerFactory.Factory.Create()) { try { manager.BeginTransaction(); manager.CommandTimeout = 120; string scriptPath = PathToTestFolder.Get(TestFolders.Db) + @"..\..\Sources\EIDSS\eidss.db\Scripts\AVR Check script\Search objects check script.sql"; if (!File.Exists(scriptPath)) { scriptPath = PathToTestFolder.Get(TestFolders.Db) + @"..\..\eidss.db\Scripts\AVR Check script\Search objects check script.sql"; } IEnumerable <string> scripts = ScriptLoader.LoadScript(scriptPath); foreach (string script in scripts) { if (String.IsNullOrWhiteSpace(script)) { continue; } manager.SetCommand(script.Trim()).ExecuteNonQuery(); } } finally { manager.RollbackTransaction(); } } }
public void VisualizeIndexedColors() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; var excelFileWrapper = new ExcelFileWrapper(new HSSFWorkbook()); var sheet = excelFileWrapper.Workbook.CreateSheet(); for (short i = 0; i < 64; i++) { var row = sheet.CreateRow(i); var cell = row.CreateCell(0); var style = excelFileWrapper.Workbook.CreateCellStyle(); style.FillPattern = FillPattern.SolidForeground; style.FillForegroundColor = i; cell.CellStyle = style; cell.SetCellValue(i); } excelFileWrapper.Save(path + "IndexedColors.xls"); }
public void DuplicateValidationTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; Assert.AreEqual(Upload506MasterState.ReadyForUpload, master.GetState()); var result = master.GetItems(path + "506FileUploadDuplicate2.xlsx"); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(5, master.Items.Count); var validated = master.ValidateItems(); Assert.IsFalse(validated); Assert.AreEqual(Upload506MasterState.HasErrors, master.GetState()); WriteErrorsToFile(path + "506FileUploadDuplicate2Errors.xlsx"); result = master.GetItems(path + "506FileUploadDuplicate4.xlsx"); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(7, master.Items.Count); validated = master.ValidateItems(); Assert.IsFalse(validated); Assert.AreEqual(Upload506MasterState.HasErrors, master.GetState()); WriteErrorsToFile(path + "506FileUploadDuplicate4Errors.xlsx"); }
public void ImportFromMdbFileTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; long start = 1009508; long chunkSize = 10000; EidssUserContext.Init(); DbManagerFactory.SetSqlFactory(bv.common.Configuration.Config.GetSetting("EidssConnectionString")); for (long i = start; i < 1009509; i += chunkSize) { var timer = new PerformanceTimer("mdb records loading", 0); using (var _manager = DbManagerFactory.Factory.Create(EidssUserContext.Instance)) { var _accessor = Upload506Master.Accessor.Instance(null); var _master = _accessor.CreateNewT(_manager, null); var result = _master.GetItems(path + "Cddata.mdb", i, chunkSize); timer.Stop(); Debug.WriteLine("records from {0} to {1} loading time:{2}", i, i + chunkSize, timer.Time()); timer = new PerformanceTimer("set item resolution", 0); foreach (var item in _master.Items) { item.Resolution = (int)Upload506Resolution.Created; } timer.Stop(); Debug.WriteLine("set item resolution time:{0}", timer.Time()); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(chunkSize, _master.Items.Count); Assert.AreEqual(Upload506MasterState.ReadyForValidation, _master.GetState()); timer = new PerformanceTimer("post", 0); Assert.IsTrue(_accessor.Post(_manager, _master)); timer.Stop(); Debug.WriteLine("records from {0} to {1} posting time:{2}", i, i + chunkSize, timer.Time()); } } EidssUserContext.Clear(); }
public void LoadDbfFileTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; Assert.AreEqual(Upload506MasterState.ReadyForUpload, master.GetState()); var result = master.GetItems(path + "File506Upload17.dbf"); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(17, master.Items.Count); Assert.AreEqual(Upload506MasterState.ReadyForValidation, master.GetState()); bool validationResult = master.ValidateItems(); Assert.AreEqual(true, validationResult); int i = 1; var rand = new Random(); foreach (var item in master.Items) { item.strCaseID = string.Format("00000{0}", i++); item.Resolution = rand.Next(3); } //master.WriteResultToFile(path + "File506Upload17Result.xls"); if (BaseSettings.Uploading506ResultToExcel) { master.WriteResultToFile(path + "File506Upload17Result.xls"); } else { master.WriteResultToFile(path + "File506Upload17Result.dbf"); } result = master.GetItems(path + "File506UploadError17.dbf"); Assert.AreEqual(Upload506FileError.Success, result); validationResult = master.ValidateItems(); Assert.AreEqual(false, validationResult); master.WriteErrorsToFile(path + "File506UploadError17Errors.xls"); }
public void ExcelReaderTest() { var excelFileWrapper = new ExcelFileWrapper(); string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; excelFileWrapper.Read(path + "506FileUploadGood.xlsx"); var sheet = excelFileWrapper.Workbook.GetSheetAt(0); for (int rowNum = sheet.FirstRowNum; rowNum <= sheet.LastRowNum; rowNum++) { var row = sheet.GetRow(rowNum); excelFileWrapper.SetupErrorCell(row.Cells[rowNum], "Comment " + rowNum + "\r\nComment 2\r\nComment 3 line long long long long long long long long"); foreach (var cell in row.Cells) { var value = excelFileWrapper.GetCellValue(cell); var str = excelFileWrapper.GetCellText(cell); } if (rowNum % 2 != 0) { excelFileWrapper.SetupErrorRow(row, "Test comment"); } } excelFileWrapper.Save(path + "test.xlsx"); }
public static void Init(TestContext testContext) { string scriptPath = PathToTestFolder.Get(TestFolders.Db) + "Data\\CreateTestTables.sql"; ScriptLoader.RunScript(scriptPath); }
public void StatisticImportTest() { DbManagerFactory.SetSqlFactory(Config.GetSetting("EidssConnectionString", "")); EidssUserContext.Init(); using (var context = EidssUserContext.Instance) { StatisticHelper helper = new StatisticHelper(); int result = helper.Import(PathToTestFolder.Get(TestFolders.Db) + "Data\\StatisticData_Errors.csv", false); Assert.AreEqual(0, result); //Assert.AreEqual(4, helper.RowsAffected); Assert.AreEqual(10, helper.Errors.Count); Assert.AreEqual("errMissingField", helper.Errors[0].MessageID); Assert.AreEqual(0, helper.Errors[0].LineNumber); Assert.AreEqual("errInvalidStatisticType", helper.Errors[1].MessageID); Assert.AreEqual(1, helper.Errors[1].LineNumber); Assert.AreEqual("errInvalidStatisticValue", helper.Errors[2].MessageID); Assert.AreEqual(2, helper.Errors[2].LineNumber); Assert.AreEqual("errInvalidDateFormat", helper.Errors[3].MessageID); Assert.AreEqual(3, helper.Errors[3].LineNumber); Assert.AreEqual("errInvalidYearStartDate", helper.Errors[4].MessageID); Assert.AreEqual(4, helper.Errors[4].LineNumber); Assert.AreEqual("errInvalidCountry", helper.Errors[5].MessageID); Assert.AreEqual(5, helper.Errors[5].LineNumber); Assert.AreEqual("errInvalidRegion", helper.Errors[6].MessageID); Assert.AreEqual(6, helper.Errors[6].LineNumber); Assert.AreEqual("errInvalidRayon", helper.Errors[7].MessageID); Assert.AreEqual(7, helper.Errors[7].LineNumber); Assert.AreEqual("errInvalidParameter", helper.Errors[8].MessageID); Assert.AreEqual(8, helper.Errors[8].LineNumber); Assert.AreEqual("errMalFormedCvs", helper.Errors[9].MessageID); Assert.AreEqual(9, helper.Errors[9].LineNumber); Assert.IsTrue(helper.RowsAffected <= 3); result = helper.Import(PathToTestFolder.Get(TestFolders.Db) + "Data\\StatisticData_BadHeader.csv", false); Assert.AreEqual(-1, result); Assert.AreEqual(1, helper.Errors.Count); Assert.AreEqual("errStatisticImportFieldsQty", helper.Errors[0].MessageID); Assert.AreEqual(-1, helper.Errors[0].LineNumber); result = helper.Import(PathToTestFolder.Get(TestFolders.Db) + "Data\\StatisticData_BadHeader1.csv", false); Assert.AreEqual(-1, result); Assert.AreEqual(1, helper.Errors.Count); Assert.AreEqual("errStatisticImportFieldsQty", helper.Errors[0].MessageID); Assert.AreEqual(-1, helper.Errors[0].LineNumber); result = helper.Import(PathToTestFolder.Get(TestFolders.Db) + "Data\\StatisticData_Good.csv", false); Assert.AreEqual(0, result); Assert.AreEqual(9, helper.Errors.Count); Assert.AreEqual("errMissingField", helper.Errors[0].MessageID); Assert.AreEqual(0, helper.Errors[0].LineNumber); Assert.AreEqual("errInvalidStatisticType", helper.Errors[1].MessageID); Assert.AreEqual(1, helper.Errors[1].LineNumber); Assert.AreEqual("errInvalidStatisticValue", helper.Errors[2].MessageID); Assert.AreEqual(2, helper.Errors[2].LineNumber); Assert.AreEqual("errInvalidDateFormat", helper.Errors[3].MessageID); Assert.AreEqual(3, helper.Errors[3].LineNumber); Assert.AreEqual("errInvalidYearStartDate", helper.Errors[4].MessageID); Assert.AreEqual(4, helper.Errors[4].LineNumber); Assert.AreEqual("errInvalidCountry", helper.Errors[5].MessageID); Assert.AreEqual(5, helper.Errors[5].LineNumber); Assert.AreEqual("errInvalidRegion", helper.Errors[6].MessageID); Assert.AreEqual(6, helper.Errors[6].LineNumber); Assert.AreEqual("errInvalidRayon", helper.Errors[7].MessageID); Assert.AreEqual(7, helper.Errors[7].LineNumber); Assert.AreEqual("errInvalidParameter", helper.Errors[8].MessageID); Assert.AreEqual(8, helper.Errors[8].LineNumber); Assert.IsTrue(helper.RowsAffected <= 3); } }
public void LoadExcelFileTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; Assert.AreEqual(Upload506MasterState.ReadyForUpload, master.GetState()); var result = master.GetItems(path + "506FileUploadGood.xlsx"); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(4, master.Items.Count); Assert.AreEqual(Upload506MasterState.ReadyForValidation, master.GetState()); int i = 1; var rand = new Random(); foreach (var item in master.Items) { item.strCaseID = string.Format("00000{0}", i++); item.Resolution = rand.Next(3); } master.WriteResultToFile(path + "506FileUploadResult.xlsx"); result = master.GetItems(path + "506FileUploadExample.xlsx"); result = master.GetItems(path + "506FileUploadGood.xls"); Assert.AreEqual(Upload506FileError.Success, result); Assert.AreEqual(4, master.Items.Count); Assert.AreEqual(Upload506MasterState.ReadyForValidation, master.GetState()); foreach (var item in master.Items) { item.strCaseID = string.Format("00000{0}", i++); item.Resolution = rand.Next(3); } master.WriteResultToFile(path + "506FileUploadResult.xls"); result = master.GetItems(path + "506FileUploadBadHeader1.xlsx"); Assert.AreEqual(Upload506FileError.IvalidHeaderFormat, result); Assert.AreEqual(0, master.Items.Count); Assert.AreEqual(Upload506MasterState.HasErrors, master.GetState()); result = master.GetItems(path + "506FileUploadBadHeader2.xlsx"); Assert.AreEqual(Upload506FileError.IvalidHeaderFormat, result); Assert.AreEqual(0, master.Items.Count); Assert.AreEqual(Upload506MasterState.HasErrors, master.GetState()); result = master.GetItems(path + "UnexisitngFile.xlsx"); Assert.AreEqual(Upload506FileError.NullFile, result); Assert.AreEqual(Upload506MasterState.HasErrors, master.GetState()); result = master.GetItems(path + "506FileUploadBadCellFormat.xlsx"); master.Items[0].AddError("DISEASE", "Mandatory field in column DISEASE cannot be empty."); master.Items[2].AddError("ADDRESS", "Test Error1"); master.Items[2].AddError("ADDRESS", "Test Error2"); master.Items[0].AddError("Duplicate", "The record is a duplicate of the record in row 4."); master.Items[2].AddError("Duplicate", "The record is a duplicate of the record in row 2."); Assert.AreEqual(Upload506FileError.IncorrectDataFormat, result); Assert.AreEqual(4, master.Items.Count); Assert.AreEqual(4, master.Items[0].validationErrors.Count); Assert.AreEqual("SEX", master.Items[0].validationErrors[0].Item1); Assert.AreEqual(string.Format(EidssMessages.Get("msg506DataTypeError"), "SEX"), master.Items[0].validationErrors[0].Item2); Assert.AreEqual("DATEDEATH", master.Items[0].validationErrors[1].Item1); Assert.AreEqual(string.Format(EidssMessages.Get("msg506DataTypeError"), "DATEDEATH"), master.Items[0].validationErrors[1].Item2); Assert.AreEqual(1, master.Items[1].validationErrors.Count); Assert.AreEqual("ADDRCODE", master.Items[1].validationErrors[0].Item1); Assert.AreEqual(string.Format(EidssMessages.Get("msg506MaxLengthError"), "ADDRCODE"), master.Items[1].validationErrors[0].Item2); Assert.AreEqual(2, master.Items[2].validationErrors.Count); Assert.AreEqual("ADDRESS", master.Items[2].validationErrors[0].Item1); Assert.AreEqual("Test Error1\r\nTest Error2", master.Items[2].validationErrors[0].Item2); WriteErrorsToFile(path + "506FileUploadErrors.xlsx"); result = master.GetItems(path + "506FileUploadGood.tmp"); Assert.AreEqual(Upload506FileError.UsupportedExtension, result); }
public void LoadExcelFilePerformanceTest() { string path = PathToTestFolder.Get(TestFolders.Db) + "Data\\"; var timer = new PerformanceTimer("100 records loading", 0); var result = master.GetItems(path + "506File100records.xlsx"); timer.Stop(); var t = timer.Time(); Debug.WriteLine("100 records loading time: {0}", t); //Assert.IsTrue(t < 0.5, "100 record loading time is {0}", t); timer = new PerformanceTimer("1000 records loading", 0); result = master.GetItems(path + "506File1000records.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("1000 records loading time: {0}", t); Assert.IsTrue(t < 1, "1000 record loading time is {0}", t); timer = new PerformanceTimer("10000 records loading", 0); result = master.GetItems(path + "506File10000records.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("10000 records loading time: {0}", t); //Assert.IsTrue(t < 10, "1000 record loading time is {0}", t); timer = new PerformanceTimer("20000 records loading", 0); result = master.GetItems(path + "506FileUploadExample.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("20000 records loading time: {0}", t); //Assert.IsTrue(t < 15, "20000 record loading time is {0}", t); timer = new PerformanceTimer("20000 records validation", 0); var validate = master.ValidateItems(); Assert.IsFalse(validate); timer.Stop(); t = timer.Time(); Debug.WriteLine("20000 records validation time: {0}", t); //Assert.IsTrue(t < 10, "20000 record validation time is {0}", t); timer = new PerformanceTimer("20000 example records errors writing", 0); WriteErrorsToFile(path + "506FileUploadExampleErrors.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("20000 example records errors writing: {0}", t); timer = new PerformanceTimer("100 example records loading", 0); result = master.GetItems(path + "506FileUploadExample100.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("100 example records loading time: {0}", t); //Assert.IsTrue(t < 5, "100 example record loading time is {0}", t); timer = new PerformanceTimer("100 example records validation", 0); validate = master.ValidateItems(); Assert.IsTrue(validate); timer.Stop(); t = timer.Time(); Debug.WriteLine("100 example records validation time: {0}", t); //Assert.IsTrue(t < 5, "100 example record validation time is {0}", t); timer = new PerformanceTimer("100 example records errors writing", 0); WriteErrorsToFile(path + "506FileUploadExample100Errors.xlsx"); timer.Stop(); t = timer.Time(); Debug.WriteLine("100 example records errors writing: {0}", t); }
public static void Init(TestContext testContext) { ScriptLoader.RunScript(PathToTestFolder.Get(TestFolders.Db) + "Data\\CreateTestTables.sql"); }