Exemplo n.º 1
0
        public void String_Test()
        {
            #region String_.cs
            var  folderPath = Config_Info.Config_File_Test(_Debug, @"Text/cSharp/");
            bool error;
            ClassNTBlueprintRule_ blueprintRule;
            var Class = ClassNT_.Create(folderPath + "String_.cs", out error, out blueprintRule);
            Assert.Equal(enBlueprintClassNetworkType.Node_Link, Class.BlueprintRule.ClassType);
            Assert.Equal(7, Class.Properties.Count);
            Assert.Equal(0, Class.Methods.Count);
            Assert.Equal("String_", Class.ClassName);
            Assert.Equal("String_", Class.Header.ClassName);
            Assert.Equal("LamedalCore.Types.String", Class.Header.NameSpace_Name);
            Assert.Equal(115, Class.Statistics.ClassTotalLines);
            Assert.Equal(1, Class.Statistics.ClassTotalBlankLines);
            Assert.Equal(12, Class.Statistics.ClassTotalCodeLines);
            Assert.Equal(3, Class.Statistics.ClassTotalCommentLines);
            Assert.Equal(0, Class.Statistics.TotalMethods);
            Assert.Equal(0, Class.Statistics.TotalFields);
            Assert.Equal(0, Class.Statistics.CodeComplexity);
            Assert.Equal(0, Class.Statistics.CodeMaintainability);
            Assert.Equal(0, Class.Statistics.TotalProperties);
            #endregion

            #region InvalidFile.cs
            Assert.Throws <InvalidOperationException>(() => ClassNT_.Create(folderPath + "InvalidFile.cs", out error, out blueprintRule));
            #endregion
        }
Exemplo n.º 2
0
        public void Macro_Sheets_Test()
        {
            #region Get Input
            // ===================================
            var excelFile = "General_Input.xlsx";
            Config_Info.Config_File_Test(_Debug);

            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel_List/");
            var    file            = folderTestCases + excelFile;
            DebugLog("File: " + file, true);
            Assert.True(_lamed.lib.IO.File.Exists(file), $"File: '{file}' does not exist!");
            #endregion

            _lamed.lib.Excel.Macro.Dashboard_FromSheets(folderTestCases, excelFile);

            #region Test compile results
            // =================================================
            var           compile     = excelFile.Replace(".xlsx", "_Compile.xlsx");
            var           resultExcel = folderTestCases + "TestResult_Compile.xlsx";
            List <string> result      = _lamed.lib.Excel.IO_Read.CompareDataSheet(folderTestCases + compile, "", resultExcel, "");
            Assert.Equal(result.Count, 0);
            #endregion

            #region Test end result
            // ================================================
            var dashboard = excelFile.Replace(".xlsx", "_Result.xlsx");
            resultExcel = folderTestCases + "TestResult_Result.xlsx";
            result      = _lamed.lib.Excel.IO_Read.CompareDataSheet(folderTestCases + dashboard, "", resultExcel, "");
            Assert.Equal(result.Count, 0);
            #endregion
        }
Exemplo n.º 3
0
        public void ExcelFile_LoadAsExcelData_Test()
        {
            var excelInputFile = "Sheet_EqualTest.xlsx";

            Config_Info.Config_File_Test(_Debug);

            // Setup part
            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel/");
            var    file_input      = folderTestCases + excelInputFile;

            // Test if files exists
            Assert.True(_lamed.lib.IO.Folder.Exists(folderTestCases), folderTestCases);
            Assert.True(_lamed.lib.IO.File.Exists(file_input), file_input);

            // Valid sheets
            pcExcelData_ input1 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet1");
            pcExcelData_ input2 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet2");
            pcExcelData_ input3 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet3");

            // Invalid sheets
            var ex = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet334"));

            Assert.Equal("Error! Worksheet with name 'Sheet334' was not found!", ex.Message);
        }
Exemplo n.º 4
0
        public void Execute_Notepad_Test()
        {
            string folderTest = Config_Info.Config_File_Test(_Debug);
            string folderApplication;
            string folderTestCases;
            pcTest_Configuration config;
            string configFile;
            bool   result = _lamed.lib.Test.ConfigSettings(out folderApplication, out folderTestCases, out config, out configFile);

            if (result == false)
            {
                // This code will not be tested
                _lamed.lib.Command.Sleep(1000);  // Sleep 1 more seconds and try again
                result = _lamed.lib.Test.ConfigSettings(out folderApplication, out folderTestCases, out config, out configFile);
                if (result == false)
                {
                    return;                  //<======================================[ Lets give up
                }
            }

            // Lets do the tests
            Assert.Equal(folderTest, folderTestCases);
            Assert.True(_lamed.lib.IO.File.Exists(configFile));
            _lamed.lib.Command.Execute_Notepad(configFile);

            // Test if notepad is running
            // Kill notepad
            // Test if notepad is running
        }
Exemplo n.º 5
0
        public void ExecRightArrow_Test()
        {
            Config_Info.Config_File_Test(_Debug);

            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel/");

            #region Load the input ==========================================
            string fileInput              = folderTestCases + "Budget_Input1Data.xlsx";
            string fileConfig             = folderTestCases + "Budget_Input2Config.xlsx";
            string fileResult             = folderTestCases + "Budget_Output"; // The .xlsx will be added automatically
            string fileConfigCompile_Test = folderTestCases + "Budget_Result_Config_Compile.xlsx";
            string fileResult_Test        = folderTestCases + "Budget_Result_Output.xlsx";

            Assert.True(_lamed.lib.IO.Folder.Exists(folderTestCases), $"Folder: '{folderTestCases}' does not exist!");
            Assert.True(_lamed.lib.IO.File.Exists(fileInput), $"File: '{fileInput}' does not exist!");
            Assert.True(_lamed.lib.IO.File.Exists(fileConfig), $"File: '{fileConfig}' does not exist!");
            Assert.True(_lamed.lib.IO.File.Exists(fileConfigCompile_Test), $"File: '{fileConfigCompile_Test}' does not exist!");
            Assert.True(_lamed.lib.IO.File.Exists(fileResult_Test), $"File: '{fileResult_Test}' does not exist!");
            #endregion

            #region TestCase
            string errorMsg;
            _lamed.lib.Excel.Macro.Execute_ExcelMacro(fileInput, fileConfig, fileResult, out errorMsg);
            string fileConfigCompile = fileConfig.Replace(".xlsx", "_Compile.xlsx");
            Assert.True(_lamed.lib.IO.File.Exists(fileResult + ".xlsx"), $"File: '{fileResult}' does not exist!");
            Assert.True(_lamed.lib.IO.File.Exists(fileConfigCompile), $"File: '{fileConfigCompile}' does not exist!");

            // Test the results
            // Budget_Input2Config_Compile <-> Budget_Result_Config_Compile
            var msg = $"Test Sheets: '{_lamed.lib.IO.Parts.File(fileConfigCompile)}' and '{_lamed.lib.IO.Parts.File(fileConfigCompile_Test)}'";
            DebugLog(msg, true);
            List <string> results = _lamed.lib.Excel.IO_Read.CompareDataSheet(fileConfigCompile, "", fileConfigCompile_Test, "");
            Assert.Equal(0, results.Count); // Test that there is no differences

            // Budget_Output <-> Budget_Result_Output
            msg = $"Test Sheets: '{_lamed.lib.IO.Parts.File(fileResult)}' and '{_lamed.lib.IO.Parts.File(fileResult_Test)}'";
            DebugLog(msg);
            results = _lamed.lib.Excel.IO_Read.CompareDataSheet(fileResult + ".xlsx", "", fileResult_Test, "");
            Assert.Equal(0, results.Count); // Test that there is no differences
            #endregion

            #region Exceptions
            string fileInput2  = folderTestCases + "Budget_Input1Data123.xlsx";
            string fileConfig2 = folderTestCases + "Budget_Input2Config123.xlsx";
            Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.Execute_ExcelMacro(fileInput2, fileConfig, fileResult, out errorMsg));
            Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.Execute_ExcelMacro(fileInput, fileConfig2, fileResult, out errorMsg));

            #endregion
        }
Exemplo n.º 6
0
        public void ArrowLeft_Test()
        {
            var excelFile = "TestArrowLeft.xlsx";

            Config_Info.Config_File_Test(_Debug);

            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel/");
            //string folderApplication;
            //string folderTestCases;
            //pcTest_Configuration config;
            //_lamed.lib.Test.ConfigSettings(out folderApplication, out folderTestCases, out config);

            var file = folderTestCases + excelFile;

            DebugLog("File: " + file, true);
            Assert.True(_lamed.lib.IO.File.Exists(file), $"File: '{file}' does not exist!");

            // Load the Test ==========================================
            pcExcelData_ input  = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file, "Input");
            pcExcelData_ result = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file, "Result");
            // =========================================================

            // Test sheet integrity ====================================
            string resultMsg1, resultMsg2;

            if (_lamed.lib.Excel.Macro.DataIntegrity_Check(input, out resultMsg1) == false)
            {
                throw new Exception(resultMsg1);
            }
            if (_lamed.lib.Excel.Macro.DataIntegrity_Check(result, out resultMsg2) == false)
            {
                throw new Exception(resultMsg2);
            }
            var msg = "Input:".NL() + resultMsg1.NL(2) + "Result:".NL() + resultMsg2;

            DebugLog(msg);
            // ============================================================

            // Execute macro and test the results =========================
            string resultMsg;

            _lamed.lib.Excel.Macro.Compile(input, out resultMsg);
            if (_lamed.lib.IO.Json.Object_IsEqual(result.Normalize(), input.Normalize(), out resultMsg) == false)
            {
                resultMsg.zException_Show();
            }
            // ============================================================
        }
Exemplo n.º 7
0
        public void String_Edit_Test()
        {
            var  folderPath = Config_Info.Config_File_Test(_Debug, @"Text/cSharp/");
            bool error;
            ClassNTBlueprintRule_ blueprintRule;
            var Class = ClassNT_.Create(folderPath + "String_Edit.cs", out error, out blueprintRule);

            Assert.Equal(0, Class.Properties.Count);
            Assert.Equal(13, Class.Methods.Count);
            Assert.Equal("String_Edit", Class.ClassName);
            Assert.Equal("String_Edit", Class.Header.ClassName);
            Assert.Equal("String", Class.Header.ClassName1);
            Assert.Equal("Edit", Class.Header.ClassName2);
            Assert.Equal("LamedalCore.Types.String", Class.Header.NameSpace_Name);
            Assert.Equal(218, Class.Statistics.ClassTotalLines);
            Assert.Equal(1, Class.Statistics.ClassTotalBlankLines);
            Assert.Equal(12, Class.Statistics.ClassTotalCodeLines);
            Assert.Equal(49, Class.Statistics.ClassTotalCommentLines);
            Assert.Equal(13, Class.Statistics.TotalMethods);
            Assert.Equal(0, Class.Statistics.TotalFields);
            Assert.Equal(32, Class.Statistics.CodeComplexity);
            Assert.Equal(17, Class.Statistics.CodeMaintainability);
            Assert.Equal(0, Class.Statistics.TotalProperties);
        }
Exemplo n.º 8
0
        public void SheetDef_Test()
        {
            #region Get Input
            // ===================================
            var excelFile = "General_Input.xlsx";
            Config_Info.Config_File_Test(_Debug);

            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel_List/");

            //string folderApplication;
            //string folderExcelTestCases;
            //pcTest_Configuration config;
            //_lamed.lib.Test.ConfigSettings(out folderApplication, out folderExcelTestCases, out config);

            var file = folderTestCases + excelFile;
            DebugLog("File: " + file, true);
            Assert.True(_lamed.lib.IO.File.Exists(file), $"File: '{file}' does not exist!");

            // =============================
            //var folder = folderExcelTestCases + @"Excel_list\";
            var          fileCompile = folderTestCases + excelFile;
            pcExcelData_ excelData   = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(fileCompile);
            #endregion

            #region Test Sheet definition string
            // ===================================================
            string sheetDefStr, sheetDefStr2;
            if (excelData.Find_First(out sheetDefStr, "{Sheet}->") == false)
            {
                "Error! Unable to find '{Sheet}->' in Excel sheet".zException_Show();
            }
            Assert.Equal("{Sheet}->\"Q22\";{Data}->|A5|;|A10|->\"Name or Nickname:\";|A14|->\"1\";|A35|->\"22\";|K12|->\"Total\"", sheetDefStr);
            Assert.Equal(false, excelData.Find_First(out sheetDefStr2, "{Invalid search}->"));
            #endregion

            #region Test sheet definition
            // ================================================
            pcExcelDef_Sheet sheetDef = _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefStr);
            Assert.Equal(sheetDef.SheetName, "Q22");
            Assert.Equal(sheetDef.DataCellAddress, "A5");
            Assert.Equal(sheetDef.Cells[0].CellAddress, "A10");
            Assert.Equal(sheetDef.Cells[0].CellValue, "Name or Nickname:");
            Assert.Equal(sheetDef.Cells[1].CellAddress, "A14");
            Assert.Equal(sheetDef.Cells[1].CellValue, "1");
            Assert.Equal(sheetDef.Cells[2].CellAddress, "A35");
            Assert.Equal(sheetDef.Cells[2].CellValue, "22");
            Assert.Equal(sheetDef.Cells[3].CellAddress, "K12");
            Assert.Equal(sheetDef.Cells[3].CellValue, "Total");
            #endregion

            #region Test found Excel files
            // ======================================
            List <string> filesGood = _lamed.lib.Excel.Macro.Dashbaord_FindSheetFiles(folderTestCases, sheetDef);
            Assert.Equal(filesGood.Count, 8);
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[0]), "Q22_Bruce.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[1]), "Q22_Charles.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[2]), "Q22_Danie.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[3]), "Q22_Erik.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[4]), "Q22_Henk.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[5]), "Q22_Jerrie.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[6]), "Q22_Joe.xlsx");
            Assert.Equal(_lamed.lib.IO.Parts.File(filesGood[7]), "Q22_Leon.xlsx");
            #endregion

            #region Exceptions
            // Sheet
            var sheetDefError1 = "{Sheet}-->\"Q22\";{Data}->|A5|;|A10|->\"Name or Nickname:\";|A14|->\"1\";|A35|->\"22\";|K12|->\"Total\"";
            var ex             = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefError1));
            Assert.Equal("Error! '{Sheet}->' was not found.", ex.Message);

            // Data
            var sheetDefError2 = "{Sheet}->\"Q22\";{Data}-->|A5|;|A10|->\"Name or Nickname:\";|A14|->\"1\";|A35|->\"22\";|K12|->\"Total\"";
            ex = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefError2));
            Assert.Equal("Error! ';{Data}->' was not found.", ex.Message);

            // '|->'
            var sheetDefError3 = "{Sheet}->\"Q22\";{Data}->|A5|;|A10->\"Name or Nickname:\";|A14->\"1\";|A35->\"22\";|K12->\"Total\"";
            ex = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefError3));
            Assert.Equal("Error! '|->' cell reference was not found.", ex.Message);

            // ';|'
            var sheetDefError4 = "{Sheet}->\"Q22\";{Data}->|A5|; |A10|->\"Name or Nickname:\"; |A14|->\"1\"; |A35|->\"22\";|K12|->\"Total\"";
            ex = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefError4));
            Assert.Equal("Error! No cell references checks defined.", ex.Message);

            // Sheet name has not quotes
            var sheetDefError5 = "{Sheet}->Q22;{Data}->|A5|;|A10|->\"Name or Nickname:\";|A14|->\"1\";|A35|->\"22\";|K12|->\"Total\"";
            ex = Assert.Throws <InvalidOperationException>(() => _lamed.lib.Excel.Macro.MacroItem.SheetDef_Parse(sheetDefError5));
            Assert.Equal("Error! Sheet ref 'Q22' does not contain quotes.", ex.Message);

            #endregion
        }
Exemplo n.º 9
0
        public void SheetsEquality_Test()
        {
            #region Input
            var excelInputFile  = "Sheet_EqualTest.xlsx";
            var excelResultFile = "Sheet_EqualTest2.xlsx";
            Config_Info.Config_File_Test(_Debug);

            // Setup part
            // Test if file exists =====================================
            string folderTestCases = Config_Info.Config_File_Test(_Debug, @"Excel/");
            var    file_input      = folderTestCases + excelInputFile;
            var    file_result     = folderTestCases + excelResultFile;

            // Test if files exists
            Assert.True(_lamed.lib.IO.Folder.Exists(folderTestCases), folderTestCases);
            Assert.True(_lamed.lib.IO.File.Exists(file_input), file_input);
            Assert.True(_lamed.lib.IO.File.Exists(file_result), file_result);

            // Read test cases
            pcExcelData_ input1 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet1");
            pcExcelData_ input2 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet2");
            pcExcelData_ input3 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_input, "Sheet3");

            pcExcelData_ result1 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_result, "Sheet1");
            pcExcelData_ result2 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_result, "Sheet2");
            pcExcelData_ result3 = _lamed.lib.Excel.IO_Read.ExcelFile_LoadAsExcelData(file_result, "Sheet3");
            #endregion

            #region Compare results - Sheet1
            // ===========================================================
            DebugLog("Test Sheet1:", true);
            List <string> results = _lamed.lib.Excel.Data.CompareDataSheet(input1, result1);
            Assert.Equal(0, results.Count);
            #endregion

            #region Sheet2 ==================================================
            DebugLog("Test Sheet2:");
            // Addess test
            List <string> results2 = _lamed.lib.Excel.Data.CompareDataSheet(input2, result2);
            Assert.Equal(2, results2.Count);
            Assert.Equal(results2[0], "A1");
            Assert.Equal(results2[1], "B5");

            // Value test
            results2 = _lamed.lib.Excel.Data.CompareDataSheet(input2, result2, enExcel_FindReturnValue.CellValue);
            Assert.Equal(results2[0], "Value 'Field1' != 'Field1_'");
            Assert.Equal(results2[1], "Value 'f' != 'f_'");

            // Address & Value test
            results2 = _lamed.lib.Excel.Data.CompareDataSheet(input2, result2, enExcel_FindReturnValue.CellAddressAndValue);
            Assert.Equal(results2[0], "A1 -> Value 'Field1' != 'Field1_'");
            Assert.Equal(results2[1], "B5 -> Value 'f' != 'f_'");
            // ========================================================
            #endregion

            #region Sheet3 =================================================
            DebugLog("Test Sheet3:");
            // Addess test
            List <string> results3 = _lamed.lib.Excel.Data.CompareDataSheet(input3, result3);
            Assert.Equal(2, results3.Count);
            Assert.Equal(results3[0], "B1");
            Assert.Equal(results3[1], "C4");

            // Value test
            results3 = _lamed.lib.Excel.Data.CompareDataSheet(input3, result3, enExcel_FindReturnValue.CellValue);
            Assert.Equal(results3[0], "Value 'Field2' != 'Field2_'");
            Assert.Equal(results3[1], "Value 'h' != 'h_'");

            // Address & Value test
            results3 = _lamed.lib.Excel.Data.CompareDataSheet(input3, result3, enExcel_FindReturnValue.CellAddressAndValue);
            Assert.Equal(results3[0], "B1 -> Value 'Field2' != 'Field2_'");
            Assert.Equal(results3[1], "C4 -> Value 'h' != 'h_'");
            // ====================================================================
            #endregion
        }
Exemplo n.º 10
0
        public void ClassNT_ReadWrite_Test()
        {
            List <string>         source;
            ClassNTBlueprintRule_ blueprintRule;

            #region Test1: public sealed class Types_Money

            //      ===========================================
            source = new List <string>
            {
                "using System;",
                "",
                "namespace Blueprint.lib.Rules.Types",
                "{",
                "    /// <summary>",
                "    /// Money convertions",
                "    /// </summary>",
                "    [BlueprintRule_Class(enBlueprintClassNetworkType.Node_Action)]",
                "    public sealed class Types_Money",
                "    {",
                "        /// <summary>",
                "        ///     A Double extension method that converts the @this to a money.",
                "        /// </summary>",
                "        /// <param name=\"this\">The @this to act on.</param>",
                "        /// <returns>@this as a Double.</returns>",
                "        public Double ToMoney(Double @this)",
                "        {",
                "            return Math.Round(@this, 2);",
                "        }",
                "    }",
                "}",
                ""
            };
            bool error;
            var  Class = ClassNT_.Create(source, out error, out blueprintRule);
            Assert.Equal(1, Class.Header.NameSpace_UsingLines.Count);
            Assert.Equal("Blueprint.lib.Rules.Types", Class.Header.NameSpace_Name);
            Assert.Equal("Money convertions", Class.Header.Header_Comment);
            Assert.Equal(1, Class.Header.Namespace_Attributes.Items.Count);
            Assert.Equal(enBlueprintClassNetworkType.Node_Action, blueprintRule.ClassType);

            #endregion

            #region Test2: Write & Read the class object

            var folderPath = Config_Info.Config_File_Test(_Debug) + @"Text/ClassNT/"; //@"C:\test\stream\header.txt";
            _lamed.lib.IO.Folder.Create(folderPath);
            var file = folderPath + "classTest.txt";

            // Writing
            string json1 = _lamed.lib.Test.Object_2JsonStr(Class);
            1f.zIO().RW.File_Write(file, json1, true);

            // Reading
            string json2  = 1f.zIO().RW.File_Read2Str(file);
            var    Class2 = _lamed.lib.Test.Object_FromJsonStr <ClassNT_>(json2);

            // Testing
            Assert.Equal(json1, json2);
            Assert.Equal(1, Class2.Header.NameSpace_UsingLines.Count);
            Assert.Equal("Blueprint.lib.Rules.Types", Class2.Header.NameSpace_Name);
            Assert.Equal("Money convertions", Class2.Header.Header_Comment);
            Assert.Equal(1, Class2.Header.Namespace_Attributes.Items.Count);

            #endregion
        }
Exemplo n.º 11
0
        public void ClassWriteRead_Test()
        {
            #region Create the test data
            //      ===========================================
            var source = new List <string>
            {
                "using System;",
                "",
                "namespace Blueprint.lib.Rules.Types",
                "{",
                "    /// <summary>",
                "    /// Money convertions",
                "    /// </summary>",
                "    [BlueprintRule_Class(enBlueprintClassNetworkType.Node_Action)]",
                "    [BlueprintCodeInjection_(typeof(Controller_BlueprintLogger), true)]",
                "    public sealed class Types_Money",
                "    {",
                "        public string Method1()",
                "        {",
                "            return \"Test\";",
                "        }",
                "        ",
                "        /// <summary>",
                "        ///     A Double extension method that converts the @this to a money.",
                "        /// </summary>",
                "        /// <param name=\"this\">The @this to act on.</param>",
                "        /// <returns>@this as a Double.</returns>",
                "        public Double ToMoney(Double @this)",
                "        {",
                "            return Math.Round(@this, 2);",
                "        }",
                "    }",
                "}"
            };

            // Write the lines
            var folderPath = Config_Info.Config_File_Test(_Debug, @"Text/cSharp/"); //@"C:\test\stream\header.txt";
            var file       = folderPath + "Types_Money.cs";
            _lamed.lib.IO.RW.File_Write(file, source.ToArray(), true);


            #endregion

            bool error;
            ClassNTBlueprintRule_ methodRule;
            var       Class1 = ClassNT_.Create(source, out error, out methodRule, file);
            var       Class2 = ClassNT_.Create(file, out error, out methodRule);
            MethodNT_ method = Class1.Method_Find("public Double ToMoney(Double @this)");

            string errorMsg;
            Assert.True(_lamed.Types.Object.IsEqual(Class1, Class2, out errorMsg), errorMsg);
            //Assert.Equal(Class1, Class2);
            Assert.NotNull(method);
            Assert.Equal("public Double ToMoney(Double @this)", method.Header.Method_HeaderLine);

            // Test exceptions
            var method1 = Class1.Method_Find("public Double ToMoney(Double @this)", true);
            var method2 = Class1.Method_Find("public Double ToMoney(Double @this)");
            Assert.Equal(method, method1);
            Assert.Equal(null, method2);
        }
Exemplo n.º 12
0
        public void ClassHeaderReadWrite_Test()
        {
            #region Test1: public sealed class Types_Money

            //      ===========================================
            var source = new List <string>
            {
                "using System;",
                "",
                "namespace Blueprint.lib.Rules.Types",
                "{",
                "    /// <summary>",
                "    /// Money convertions",
                "    /// </summary>",
                "    [BlueprintRule_Class(enBlueprintClassNetworkType.Node_Action)]",
                "    [BlueprintCodeInjection_(typeof(Controller_BlueprintLogger), true)]",
                "    public sealed class Types_Money",
                "    {",
                "        /// <summary>",
                "        ///     A Double extension method that converts the @this to a money.",
                "        /// </summary>",
                "        /// <param name=\"this\">The @this to act on.</param>",
                "        /// <returns>@this as a Double.</returns>",
                "        public Double ToMoney(Double @this)",
                "        {",
                "            return Math.Round(@this, 2);",
                "        }",
                "    }",
                "}"
            };

            // Write the lines
            var folderPath = Config_Info.Config_File_Test(_Debug) + @"Text/ClassNT/"; //@"C:\test\stream\header.txt";
            _lamed.lib.IO.Folder.Create(folderPath);
            var file = folderPath + "Types_Money.txt";
            _lamed.lib.IO.RW.File_Write(file, source.ToArray(), true);

            // Reading the lines back
            var sourceRead = _lamed.lib.IO.RW.File_Read2StrArray(file).ToList();
            Assert.Equal(source, sourceRead);

            #endregion

            #region Test3: Create header class

            int           ii;
            ClassNTStats_ stats   = ClassNTStats_.Create();
            var           header1 = ClassNTHeader_.Create(source, out ii, stats);
            Assert.Equal("System", header1.NameSpace_UsingLines[0]);
            Assert.Equal("Blueprint.lib.Rules.Types", header1.NameSpace_Name);
            Assert.Equal("Money convertions", header1.Header_Comment);
            Assert.Equal("[BlueprintRule_Class(enBlueprintClassNetworkType.Node_Action)]", header1.NameSpace_AttributeLines[0]);
            Assert.Equal("[BlueprintCodeInjection_(typeof(Controller_BlueprintLogger), true)]",
                         header1.NameSpace_AttributeLines[1]);
            Assert.Equal("Types_Money", header1.ClassName);
            Assert.Equal("Types", header1.ClassName1);
            Assert.Equal("Money", header1.ClassName2);

            #endregion

            #region Test4: Write, Read and re-Create the header class
            file = folderPath + "ClassNTHeader.txt";

            string json1 = _lamed.lib.Test.Object_2JsonStr(header1);
            1f.zIO().RW.File_Write(file, json1, overwrite: true);

            // Read the object and test it
            string json2   = 1f.zIO().RW.File_Read2Str(file);
            var    header2 = _lamed.lib.Test.Object_FromJsonStr <ClassNTHeader_>(json2);
            // Testing
            Assert.Equal(json1, json2);
            Assert.Equal("System", header2.NameSpace_UsingLines[0]);
            Assert.Equal("Blueprint.lib.Rules.Types", header2.NameSpace_Name);
            Assert.Equal("Money convertions", header2.Header_Comment);
            Assert.Equal("[BlueprintRule_Class(enBlueprintClassNetworkType.Node_Action)]", header2.NameSpace_AttributeLines[0]);
            Assert.Equal("[BlueprintCodeInjection_(typeof(Controller_BlueprintLogger), true)]",
                         header2.NameSpace_AttributeLines[1]);
            Assert.Equal("Types_Money", header2.ClassName);
            Assert.Equal("Types", header2.ClassName1);
            Assert.Equal("Money", header2.ClassName2);

            #endregion
        }