public async Task TestCurrentDirHierarchical()
        {
            #region arrange
            var dir = AppContext.BaseDirectory;

            string filename = Path.Combine(dir, "a.html");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }


            string fileNameToWrite = Guid.NewGuid().ToString("N") + ".txt";
            string fullNameFile    = Path.Combine(dir, fileNameToWrite);
            File.WriteAllText(fullNameFile, "andrei ignat");

            #endregion
            #region act
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            #endregion
            #region assert
            Assert.IsTrue(r.valuesRead?.Length > 0, "must have a file");
            var rowDir = r.valuesRead.FirstOrDefault(it => it.Values["FullName"]?.ToString() == dir);
            Assert.IsNotNull(rowDir);
            var rowFile = r.valuesRead.FirstOrDefault(it => it.Values["FullName"]?.ToString() == fullNameFile);
            Assert.IsNotNull(rowFile);
            var rh = rowFile as IRowReceiveHierarchicalParent;
            Assert.IsNotNull(rh);
            Assert.AreEqual(rh.Parent, rowDir);
            #endregion
        }
Example #2
0
        public async Task TestFilterHierarchicalFiles()
        {
            #region arrange
            var dir = AppContext.BaseDirectory;
            dir = UtilsIO.DeleteCreateFolder(Path.Combine(dir, "TestFilterHierarchicalFiles"));
            string filename = Path.Combine(dir, "a.html");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }


            string fileNameToWrite = Guid.NewGuid().ToString("N") + ".txt";
            string fullNameFile    = Path.Combine(dir, fileNameToWrite);
            File.WriteAllText(fullNameFile, "andrei ignat");

            #endregion
            #region act
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            var fi = new FilterForFilesHierarchical();
            fi.valuesRead = r.valuesRead;
            await fi.Run();

            #endregion
            #region assert
            foreach (var item in fi.valuesTransformed)
            {
                item.Values.ShouldContainKeyAndValue("RowType", "file");
            }
            #endregion
        }
Example #3
0
        public async Task TestSampleDataMediaDot()
        {
            #region arrange
            var dir = AppContext.BaseDirectory;

            foreach (var item in Directory.GetFiles(dir, "*.txt", SearchOption.AllDirectories))
            {
                File.Delete(item);
            }

            string fileNameToWrite = "andrei.txt";
            string fullNameFile    = Path.Combine(dir, fileNameToWrite);
            File.WriteAllText(fullNameFile, "andrei ignat");
            #endregion
            #region act
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            var m = new MediaTransformDotFolderAndFiles();
            m.valuesToBeSent = r.valuesRead;
            await m.Run();

            #endregion
            #region assert
            Assert.IsTrue(m.Result.Contains("[label=\"andrei.txt"), "result should contain " + m.Result);
            Assert.IsTrue(m.Result.Contains(" -> "));
            #endregion
        }
Example #4
0
        public async Task TestFilterKeyEqualsRemains()
        {
            #region arrange
            var dir = AppContext.BaseDirectory;

            string filename = Path.Combine(dir, "a.html");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }


            string fileNameToWrite = Guid.NewGuid().ToString("N") + ".txt";
            string fullNameFile    = Path.Combine(dir, fileNameToWrite);
            File.WriteAllText(fullNameFile, "andrei ignat");

            #endregion
            #region act
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            IFilter f = new FilterRetainItemsWithKey("nrfiles", FilterType.Equal);
            f.valuesRead = r.valuesRead;
            await f.Run();

            #endregion
            #region assert
            bool haveFolder = false;
            foreach (var item in r.valuesRead)
            {
                if (haveFolder)
                {
                    break;
                }

                var keys = item.Values.Keys.ToArray();

                if (keys.Contains("nrfiles"))
                {
                    haveFolder = true;
                }
            }
            haveFolder.ShouldBeTrue();

            f.valuesTransformed.ShouldNotBeNull();
            f.valuesTransformed.Length.ShouldBeGreaterThan(0);
            foreach (var item in f.valuesTransformed)
            {
                var keys = item.Values.Keys.ToArray();
                keys.ShouldContain("nrfiles");
            }

            #endregion
        }
Example #5
0
        public async Task TestTransformerApplyReceiverFiles()
        {
            #region arrange
            var dir = AppContext.BaseDirectory;
            dir = UtilsIO.DeleteCreateFolder(Path.Combine(dir, "TestTransformerApplyReceiverFiles"));
            string filename = Path.Combine(dir, "a.html");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }


            string fileNameToWrite = Guid.NewGuid().ToString("N") + ".txt";
            string fullNameFile    = Path.Combine(dir, fileNameToWrite);
            File.WriteAllText(fullNameFile, "andrei ignat" + Environment.NewLine + "aaa");
            var readFile = new ReceiverFileFromStorageLines(fullNameFile, Encoding.UTF8);
            readFile.ReadAllFirstTime = false;
            #endregion
            #region act
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            var fi = new FilterForFilesHierarchical();
            fi.valuesRead = r.valuesRead;
            await fi.Run();

            var transformerApplyReceiver = new TransformerApplyReceiver(readFile, "FileToRead", "FullName");
            transformerApplyReceiver.valuesRead = fi.valuesTransformed;
            await transformerApplyReceiver.Run();

            #endregion
            #region assert
            transformerApplyReceiver.valuesTransformed.ShouldNotBeNull();
            transformerApplyReceiver.valuesTransformed.Length.ShouldBe(2, "2  lines above");
            #endregion
        }
Example #6
0
        public async Task TestSendHTMLDataHierarchical()
        {
            #region arange


            var dir = AppContext.BaseDirectory;
            dir = Path.Combine(dir, "TestSendDataHierarchical");
            if (Directory.Exists(dir))
            {
                Directory.Delete(dir, true);
            }
            Directory.CreateDirectory(dir);
            CreateFilesAndFolders(dir);
            string filename = Path.Combine(dir, "senderhtml.html");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            IReceive r = new ReceiverFolderHierarchical(dir, "*.txt");
            await r.LoadData();

            var fileRazor = Path.Combine(dir, "hierarFolder.cshtml");
            File.Copy(@"Views\hierarFolder.cshtml", fileRazor, true);


//            File.WriteAllText(fileRazor,
// @"@using System.Linq;
//@using StankinsInterfaces;
//@model StankinsInterfaces.IRow[]

//Number Rows: @Model.Length
//@{
//	bool showTable=(Model.Length>0);
//	if(!showTable){
//		return;
//    };
//	var FieldNames= Model[0]
//                .Values
//                .Select(it => it.Key).ToArray();
//}
//<table>
//<thead>
//<tr>
//<td>ID</td>
//@foreach(var col in FieldNames){

//<td>
//@col
//</td>

//}
//<td>Parent</td>
//</thead>

//<tbody>
//@foreach(var item in Model){
//    var m=item as IRowReceiveHierarchicalParent;

//<tr>
//<td>@m.ID</td>
//@foreach(var col in FieldNames){
//<td>
//@item.Values[col]
//</td>
//}
//<td>
//@if(m.Parent != null){
//    <text>@m.Parent.ID</text>
//}
//</td>
//</tr>

//}
//<tbody>
//</table>");

            #endregion
            #region act
            ISend sender = new SyncSenderMultiple(
                new Sender_Text(filename, "<html><body>"),
                new Sender_HTMLRazor("TestSendDataHierarchical/" + Path.GetFileName(fileRazor), filename),
                new Sender_HierarchicalVizFolder(filename, "Name"),
                new Sender_Text(filename, "</body></html>")
                );


            sender.valuesToBeSent = r.valuesRead;
            await sender.Send();

            #endregion
            #region assert
            Assert.IsTrue(File.Exists(filename), $"file {filename} must exists in export hierarchical");
            Assert.IsTrue(File.ReadAllText(filename).Contains("ignat.txt"), "must contain data");
            Assert.IsTrue(File.ReadAllText(filename).Contains("Viz("), "must contain viz ...");
            //System.Diagnostics.Process.Start("explorer.exe", filename);
            #endregion
        }