void CreateExportFilesSqlServer(string folderTo) { if (!Directory.Exists(folderTo)) { Directory.CreateDirectory(folderTo); } string sqlserverFile = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderTo, "sqlserver.cshtml")); File.Copy(@"Views\sqlserver.cshtml", sqlserverFile); string databaseFile = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderTo, "databases.cshtml")); File.Copy(@"Views\databases.cshtml", databaseFile); databaseFile += ";"; string tableFile = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderTo, "tables.cshtml")); File.Copy(@"Views\tables.cshtml", tableFile); string columnFile = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderTo, "columns.cshtml")); File.WriteAllText(@"Views\columns.cshtml", columnFile); }
public async Task TestFileCSV() { #region ARRANGE StringBuilder sb = new StringBuilder(); sb.AppendLine("model,Track_number"); sb.AppendLine("Ford,B325ROS"); sb.AppendLine("Audi,PL654CSM"); sb.AppendLine("BMW,B325DFH"); sb.AppendLine("Ford,B325IYS"); string filename = SimpleJobConditionalTransformersTest.DeleteFileIfExists("mycsv.csv"); File.WriteAllText(filename, sb.ToString()); #endregion #region ACT var CSVfile = new ReceiverCSVFileInt(filename, Encoding.ASCII); await CSVfile.LoadData(); #endregion #region ASSERT Assert.AreEqual(4, CSVfile.valuesRead.Length); Assert.AreEqual("Ford", CSVfile.valuesRead[0].Values["model"].ToString()); Assert.AreEqual("B325ROS", CSVfile.valuesRead[0].Values["Track_number"].ToString()); #endregion }
public async Task TestExportRelationalHTMLSqlServer() { #region arrange string folderName = AppContext.BaseDirectory; //CreateExportFilesSqlServer(Path.Combine(folderName,"Views")); var connectionString = GetSqlServerConnectionString(); using (var conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @" IF OBJECT_ID('dbo.TestAndrei', 'U') IS NOT NULL DROP TABLE dbo.TestAndrei;"; await cmd.ExecuteNonQueryAsync(); cmd.CommandText = @"create table TestAndrei( ID int, FirstName varchar(64) not null )"; await cmd.ExecuteNonQueryAsync(); } } var rr = new ReceiverRelationalSqlServer(); rr.ConnectionString = connectionString; string OutputFileName = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(folderName, "relationalSqlServer.html")); var sender = new Sender_HTMLRazor("Views/sqlserver.cshtml", OutputFileName); var senderViz = new Sender_HTMLRelationViz("Name", OutputFileName); var filter = new FilterExcludeRelation("columns", "tables"); var job = new SimpleJobConditionalTransformers(); job.Receivers.Add(0, rr); job.AddSender(sender); job.Add(filter); job.Add(filter, senderViz); #endregion #region act await job.Execute(); #endregion #region assert Assert.IsTrue(File.Exists(OutputFileName), $"{OutputFileName} must exists"); //Process.Start("explorer.exe", OutputFileName); var text = File.ReadAllText(OutputFileName); Assert.IsTrue(text.Contains("TestAndrei"), "must contain table testandrei"); Assert.IsTrue(text.Contains("FirstName"), "must contain column FirstName "); #endregion }
public async Task TestReceiveFromJobConditional() { #region arrange var dir = AppContext.BaseDirectory; dir = Path.Combine(dir, "TestReceiveFromJobConditional"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); var job = SimpleJobConditionalTransformersTest.GetJobCSV(); var receiver = new ReceiverFromJob(job); string file = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(dir, "job.html")); //var sender = new Sender_HierarchicalVizJob(file,"Name"); //var sender = new SenderMediaToFile(file, // new MediaTransformStringToText("<html><body>"), // new MediaTransformDotJob(), // new MediaTransformStringToText("</body></html>") // ); var export = SimpleJobConditionalTransformersTest.DeleteFileIfExists(Path.Combine(dir, "export.cshtml")); File.WriteAllText(export, Sender_HTMLRazor.DefaultExport()); var sender = new SyncSenderMultiple( new Sender_Text(file, "<html><body>"), new Sender_HTMLRazor("TestReceiveFromJobConditional/" + Path.GetFileName(export), file), new Sender_HierarchicalVizJob(file, "Name"), new Sender_Text(file, "</body></html>") ); var newJob = new SimpleJob(); newJob.Receivers.Add(0, receiver); //newJob.Receivers.Add(1, new ReceiverFromJob(newJob)); newJob.Senders.Add(0, sender); #endregion #region act await newJob.Execute(); #endregion #region assert Assert.IsTrue(File.Exists(file)); //System.Diagnostics.Process.Start("explorer.exe", file); #endregion }
public async Task TestFile() { #region arrange StringBuilder sb = new StringBuilder(); sb.AppendLine("model,Track_number"); sb.AppendLine("Ford,B325ROS"); sb.AppendLine("Audi,PL654CSM"); sb.AppendLine("BMW,B325DFH"); sb.AppendLine("Ford,B325IYS"); string filename = SimpleJobConditionalTransformersTest.DeleteFileIfExists("mycsv.csv"); File.WriteAllText(filename, sb.ToString()); var CSVfile = new ReceiverCSVFileInt(filename, Encoding.ASCII); await CSVfile.LoadData(); string filenameJSON = SimpleJobConditionalTransformersTest.DeleteFileIfExists("cars.json"); var sjons = new Sender_JSON(filenameJSON); sjons.valuesToBeSent = CSVfile.valuesRead; await sjons.Send(); #endregion #region act var f = new ReceiverJSONFileInt(filenameJSON, Encoding.UTF8); await f.LoadData(); #endregion #region assert f?.valuesRead?.Length.ShouldBe(4); f.valuesRead[0].Values["model"].ShouldBe("Ford"); f.valuesRead[0].Values["Track_number"].ShouldBe("B325ROS"); f.valuesRead[1].Values["model"].ShouldBe("Audi"); f.valuesRead[1].Values["Track_number"].ShouldBe("PL654CSM"); f.valuesRead[3].Values["Track_number"].ShouldBe("B325IYS"); #endregion }
public async Task TransmitDataJob2JobFileHardDisk() { StringBuilder sb = new StringBuilder(); sb.AppendLine("model,Track_number"); sb.AppendLine("Ford,B325ROS"); sb.AppendLine("Audi,PL654CSM"); sb.AppendLine("BMW,B325DFH"); sb.AppendLine("Ford,B325IYS"); string filename = SimpleJobConditionalTransformersTest.DeleteFileIfExists("mycsv.csv"); File.WriteAllText(filename, sb.ToString()); var CSVReceiver = new ReceiverCSVFileInt(filename, Encoding.ASCII); string bin = SimpleJobConditionalTransformersTest.DeleteFileIfExists("a.bin"); var senderBinary = new Sender_Binary(bin); var job = new SimpleJob(); job.Receivers.Add(0, CSVReceiver); job.Senders.Add(0, senderBinary); var continueJob = new SimpleJob(); var binReceiver = new ReceiverFileFromStorageBinary(bin); continueJob.Receivers.Add(0, binReceiver); #region ACT await job.Execute(); await continueJob.Execute(); #endregion #region assert Assert.AreEqual(4, binReceiver.valuesRead.Length); Assert.AreEqual("Ford", binReceiver.valuesRead[0].Values["model"]); Assert.AreEqual("B325IYS", binReceiver.valuesRead[3].Values["Track_number"]); #endregion }