private void InsertHyperlinks(string file) { var dic = new Dictionary <string, string> { { "A1", "https://www.url.com/" }, // with '/' on the end { "B2", "mailto:[email protected]" }, { "C3", "../sample.txt" }, { "D4", "Sheet2!E10" }, { "E5", "ftp://some.ftp.com" } // without '/' on the end }; foreach (var item in dic) { var workflow = new InsertHyperlink { UseScope = false, WorkbookPath = file, Cell = item.Key, Link = item.Value, SheetName = "Sheet1" }; WorkflowTester.Invoke(workflow); } }
public void ParallelPerformance() { var dt = DataTableHelper.Generate(10, 5, (i, j) => $"Row {i}, Col {j}"); var activitity = new DataTableEncryption { Algorithm = new ActivityFunc <IEncryption> { Handler = new AesAlgorithmEncryption() }, Key = new InArgument <string>(CryptoKey), }; long elapsed = 0; activitity.ParallelProcessing = false; var sw = System.Diagnostics.Stopwatch.StartNew(); WorkflowTester.Invoke(activitity, GetArgs(dt)); elapsed = sw.ElapsedMilliseconds; activitity.ParallelProcessing = true; var args = GetArgs(dt); args.Add(nameof(DataTableEncryption.Sort), "Col0 DESC"); sw.Restart(); WorkflowTester.Invoke(activitity, args); sw.Stop(); Trace.Write($"Parallel: No = {elapsed}, Yes = {sw.ElapsedMilliseconds}"); Assert.IsTrue(sw.ElapsedMilliseconds < elapsed); }
public void TypedColumnsAndDateTimeFormat(string dateTimeFormat) { var dt = new DataTable(); dt.Columns.Add("A", typeof(DateTime)); dt.Columns.Add("B", typeof(string)); dt.Columns.Add("C", typeof(char)); var row = dt.NewRow(); row["A"] = new DateTime(2022, 2, 1); row["B"] = "Yes"; row["C"] = "A"; dt.Rows.Add(row); var result = WorkflowTester.Invoke(new DataTableToText { TextFormat = TextFormat.JSON, DateTimeFormat = dateTimeFormat }, GetArgs(dt)); var dateRes = dateTimeFormat == null ? "2022-02-01T00:00:00.00000" : "01/02/2022"; Assert.AreEqual( $@"[{{""A"":""{dateRes}"",""B"":""Yes"",""C"":""A""}}]", result ); }
public void InvalidColumnArgument() { Assert.ThrowsException <InvalidWorkflowException>(() => WorkflowTester.Invoke(new ExtractDataColumnValues <int> { Column = new InArgument <bool>(true) }, GetArgs(Initialize(), 1))); }
public void DefaultInt() { var result = WorkflowTester.Invoke(new ExtractDataColumnValues <int>() { Column = new InArgument <int>(1) }, GetArgs(Initialize(), 1)); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, result); }
public void DefaultString() { var result = WorkflowTester.Invoke(new ExtractDataColumnValues <string>() { Column = new InArgument <string>("Col0") }, GetArgs(Initialize(), "Col0")); CollectionAssert.AreEqual(new[] { "A", "B", "C" }, result); }
[DataRow("A11", "ftp://some.ftp.com", "FTP")] // without '/' on the end public void OLE2(string cell, string link, string label) { var args = CreateInsertHyperlinkArgs(_ole2file, cell, link, label); var workflow = new InsertHyperlink { UseScope = false }; var result = WorkflowTester.Invoke(workflow, args); Assert.IsTrue(result); }
public void Default(DataRowEvaluationMode valuesMode, int expectedCount) { var dt = Initialize(); var result = WorkflowTester.Invoke(new RemoveEmptyRows() { Mode = valuesMode }, GetArgs(dt)); Assert.AreEqual(expectedCount, result.Rows.Count); }
public void OpenXML(int expectedResult, string cellRange) { InsertHyperlinks(_openXmlFile); var args = CreateRemoveHyperlinksArgs(_openXmlFile, cellRange); var workflow = new RemoveHyperlinks { UseScope = false }; var result = WorkflowTester.Invoke(workflow, args); Assert.AreEqual(expectedResult, result); }
public void OLE2(string file) { var path = IOSamples.GetTestPath(file); var args = new Dictionary <string, object> { { nameof(GetSheetNames.WorkbookPath), path } }; var result = WorkflowTester.Invoke(new GetSheetNames(), args); CollectionAssert.AreEqual(new[] { "Sheet1", "Sheet2", "Sheet3", "Sheet4" }, result); }
public void InvalidColumnReference() { Assert.ThrowsException <ArgumentException>(() => WorkflowTester.Invoke(new ExtractDataColumnValues <int> { Column = new InArgument <string>("InvalidColName") }, GetArgs(Initialize(), 1))); Assert.ThrowsException <ArgumentException>(() => WorkflowTester.Invoke(new ExtractDataColumnValues <int> { Column = new InArgument <int>(3) }, GetArgs(Initialize(), 1))); }
public void Default() { var result = WorkflowTester.Invoke(new TransposeData(), GetArgs(Initialize())); Assert.AreEqual("Col1", result.Columns[0].ColumnName); Assert.AreEqual("Col2", result.Columns[1].ColumnName); Assert.AreEqual("Col3", result.Columns[2].ColumnName); Assert.AreEqual("Col4", result.Columns[3].ColumnName); CollectionAssert.AreEqual(new[] { "Product", "A", "B", "C" }, result.Rows[0].ItemArray); CollectionAssert.AreEqual(new object[] { "Quantity", "1", "2", "3" }, result.Rows[1].ItemArray); CollectionAssert.AreEqual(new[] { "Color", "Red", "Green", "Blue" }, result.Rows[2].ItemArray); }
public void Default() { var tester = new ContainerTester(); var container = new Container(); container.Activities.Add(tester.PlusOne()); container.Activities.Add(tester.PlusOne()); container.Activities.Add(new Exit()); container.Activities.Add(tester.PlusOne()); tester.SetContainer(container); var result = WorkflowTester.Invoke(tester); Assert.AreEqual(2, result); }
public void Condition(bool condition, int expected) { var tester = new ContainerTester(); var container = new Container(); container.Activities.Add(tester.PlusOne()); container.Activities.Add(new Exit { Condition = new InArgument <bool>(condition) }); container.Activities.Add(tester.PlusOne()); tester.SetContainer(container); var result = WorkflowTester.Invoke(tester); Assert.AreEqual(expected, result); }
public void OLE2(int expectedRemovedLinks, string cellRange) { InsertHyperlinks(_ole2file); var args = CreateRemoveHyperlinksArgs(_ole2file, cellRange); var workflow = new RemoveHyperlinks { UseScope = false }; var result = WorkflowTester.Invoke(workflow, args); Assert.AreEqual(expectedRemovedLinks, result); using (var adapter = new OLE2WorkbookAdapter()) { adapter.Open(_ole2file); var links = adapter.GetHyperlinks("Sheet1", ""); Assert.AreEqual(5 - expectedRemovedLinks, links.Count(), "remaining links differ"); } }
public void OLE2(string file, int sheetIndex, string expectedSheetName) { var path = IOSamples.GetTestPath(file); var args = new Dictionary <string, object> { { nameof(GetSheetName.WorkbookPath), path }, { nameof(GetSheetName.SheetIndex), sheetIndex }, }; var workflow = new GetSheetName { UseScope = false }; var result = WorkflowTester.Invoke(workflow, args); Assert.AreEqual(expectedSheetName, result); }
public void Binary() { var dt = new DataTable("MyTable"); dt.Columns.Add("Bin", typeof(byte[])); var row = dt.NewRow(); row["Bin"] = new byte[] { 1, 2, 3 }; // it converts to base64 representation dt.Rows.Add(row); var result = WorkflowTester.Invoke(new DataTableToText { TextFormat = TextFormat.XML }, GetArgs(dt)); Assert.AreEqual( "<DocumentElement><MyTable><Bin>AQID</Bin></MyTable></DocumentElement>", result ); }
public void Default() { var dic = new Dictionary <string, object> { { "Name", "System" }, { "Year", 1983 }, { "Active", true }, { "Date", DateTime.Today }, { "Remarks", null }, { "Value", 90.7m } }; var result = WorkflowTester.Invoke(new DictionaryToDataTable(), new Dictionary <string, object> { { nameof(DictionaryToDataTable.InputDictionary), dic } }); Assert.AreEqual(1, result.Rows.Count); Assert.AreEqual(dic["Name"], result.Rows[0]["Name"]); Assert.AreEqual(dic["Year"], result.Rows[0]["Year"]); Assert.AreEqual(dic["Active"], result.Rows[0]["Active"]); Assert.AreEqual(dic["Date"], result.Rows[0]["Date"]); Assert.IsTrue(result.Rows[0].IsNull("Remarks")); Assert.AreEqual(dic["Value"], result.Rows[0]["Value"]); }
public void Default(string alg) { CodeActivity <IEncryption> handler = null; switch (alg) { case nameof(AesAlgorithmEncryption): handler = new AesAlgorithmEncryption(); break; case nameof(DESAlgorithmEncryption): handler = new DESAlgorithmEncryption(); break; case nameof(RC2AlgorithmEncryption): handler = new RC2AlgorithmEncryption(); break; case nameof(RijndaelAlgorithmEncryption): handler = new RijndaelAlgorithmEncryption(); break; case nameof(TripleDESAlgorithmEncryption): handler = new TripleDESAlgorithmEncryption(); break; } var dt = DataTableHelper.CreateDataTable <object>(6, new[] { new object[] { "Brazil", null, DBNull.Value, 1, "Latin", "America" }, new object[] { "Canada", "", DateTime.Today, 0, "North", "America" } }); var activity = new DataTableEncryption() { Algorithm = new ActivityFunc <IEncryption>() { Handler = handler }, ParallelProcessing = false, Key = new InArgument <string>(CryptoKey) }; var encrypted = WorkflowTester.Invoke(activity, GetArgs(dt)); var row = encrypted.Rows[0]; CollectionAssert.AreNotEqual(new object[] { "Brazil", 1, "Latin", "America" }, new object[] { row["Col0"], row["Col3"], row["Col4"], row["Col5"] }); CollectionAssert.AreEqual(new object[] { DBNull.Value, DBNull.Value }, new object[] { row["Col1"], row["Col2"] }); row = encrypted.Rows[1]; CollectionAssert.AreNotEqual(new object[] { "Canada", DateTime.Today, 0, "North", "America" }, new object[] { row["Col0"], row["Col2"], row["Col3"], row["Col4"], row["Col5"] }); Assert.AreEqual("", row[1]); activity.Action = Core.Enums.CryptoActions.Decrypt; var decrypted = WorkflowTester.Invoke(activity, GetArgs(encrypted)); for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { var dr = dt.Rows[i]; if (dr.IsNull(j)) { Assert.AreEqual(dr[j], decrypted.Rows[i][j]); } else { Assert.AreEqual(dr[j].ToString(), decrypted.Rows[i][j]); } } } }
public void NullColumn() { Assert.ThrowsException <ArgumentException>(() => WorkflowTester.Invoke(new ExtractDataColumnValues <int>(), GetArgs(Initialize(), 1))); }