Added Json2CSharpCodeGenerator.Tests

This commit is contained in:
2022-08-13 14:15:28 -07:00
parent 2385affccb
commit 29fb70ce06
86 changed files with 61170 additions and 19 deletions
Json2CSharpCodeGenerator.Lib
Json2CSharpCodeGenerator.Tests
Json2CSharpCodeGenerator.Tests.csproj
TestUtility
Test_0_DIAGNOSTICS.csTest_0_DIAGNOSTICS_INPUT.txtTest_0_DIAGNOSTICS_OUTPUT.txtTest_10_SETTINGS_IMMUTABLE_CLASSES.csTest_10_SETTINGS_IMMUTABLE_CLASSES_INPUT.txtTest_10_SETTINGS_IMMUTABLE_CLASSES_OUTPUT.txtTest_11_NoListSetter.csTest_11_NoListSetter_INPUT.txtTest_11_NoListSetter_INPUT1.txtTest_11_NoListSetter_OUTPUT.txtTest_11_NoListSetter_OUTPUT1.txtTest_17_RECORD_TYPES.csTest_17_RECORD_TYPES_INPUT.txtTest_17_RECORD_TYPES_OUTPUT.txtTest_17_RECORD_TYPES_OUTPUT_NEWTONSOFT.txtTest_17_RECORD_TYPES_OUTPUT_SYSTEMTEXTJSON.txtTest_18_WRONG_NAME_RECURSIVE_BUG78.csTest_18_WRONG_NAME_RECURSIVE_BUG78_INPUT.txtTest_18_WRONG_NAME_RECURSIVE_BUG78_OUTPUT.txtTest_19_PLURAL_NAMES.csTest_19_PLURAL_NAMES_INPUT.txtTest_19_PLURAL_NAMES_OUTPUT.txtTest_1_2_SETTINGS_PASCAL.csTest_1_2_SETTINGS_PASCAL_INPUT.txtTest_1_2_SETTINGS_PASCAL_OUTPUT.txtTest_1_3_SETTINGS_FIELDS.csTest_1_3_SETTINGS_FIELDS_INPUT.txtTest_1_3_SETTINGS_FIELDS_OUTPUT.txtTest_1_4_SETTINGS_JSONPROPERTY.csTest_1_4_SETTINGS_JSONPROPERTY_INPUT.txtTest_1_4_SETTINGS_JSONPROPERTY_OUTPUT.txtTest_1_5_SETTINGS_FIELDS_JSONPROPERTY.csTest_1_5_SETTINGS_FIELDS_JSONPROPERTY_INPUT.txtTest_1_5_SETTINGS_FIELDS_JSONPROPERTY_OUTPUT.txtTest_1_6_SETTINGS_JSONPROPERTYNAME_NETCORE.csTest_1_6_SETTINGS_JSONPROPERTYNAME_NETCORE_INPUT.txtTest_1_6_SETTINGS_JSONPROPERTYNAME_NETCORE_OUTPUT.txtTest_1_SETTINGS.csTest_1_SETTINGS_INPUT.txtTest_1_SETTINGS_OUTPUT.txtTest_20_ROOT_ARRAY.csTest_20_ROOT_ARRAY_INPUT.txtTest_20_ROOT_ARRAY_OUTPUT.txtTest_2_CHECK_RESERVED_KEYWORDS.csTest_2_CHECK_RESERVED_KEYWORDS_INPUT.txtTest_2_CHECK_RESERVED_KEYWORDS_OUTPUT.txtTest_3_ReplaceSpecialCharacters.csTest_3_ReplaceSpecialCharacters_INPUT.txtTest_3_ReplaceSpecialCharacters_OUTPUT.txtTest_4_BracketError.csTest_4_BracketError_INPUT.txtTest_4_BracketError_INPUT_1.txtTest_4_BracketError_OUTPUT.txtTest_4_BracketError_OUTPUT_1.txtTest_5_BASIC_SCENARIO.csTest_5_BASIC_SCENARIO_INPUT.txtTest_5_BASIC_SCENARIO_OUTPUT.txtTest_6_DictionaryTest.csTest_6_DictionaryTest_INPUT.txtTest_6_DictionaryTest_INPUT1.txtTest_6_DictionaryTest_INPUT2.txtTest_6_DictionaryTest_OUTPUT.txtTest_6_DictionaryTest_OUTPUT1.txtTest_6_DictionaryTest_OUTPUT2.txtTest_7_DuplictedClasses.csTest_7_DuplictedClasses_INPUT.txtTest_7_DuplictedClasses_INPUT1.txtTest_7_DuplictedClasses_OUTPUT.txtTest_7_DuplictedClasses_OUTPUT1.txtTest_8_LargeArrayOfObjects.csTest_8_LargeArrayOfObjects_INPUT.txtTest_8_LargeArrayOfObjects_OUTPUT.txtTest_9_HANDLE_NUMBERS.csTest_9_HANDLE_NUMBERS_INPUT.txtTest_9_HANDLE_NUMBERS_INPUT1.txtTest_9_HANDLE_NUMBERS_OUTPUT.txtTest_9_HANDLE_NUMBERS_OUTPUT1.txt
Json2CSharpCodeGenerator.WinForms
Json2CSharpCodeGenerator.sln
TESTS-JSON-to-CSHARP

@ -0,0 +1,57 @@
#Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Confirm:$false -Force;
$TestName = Read-Host -Prompt 'Test Name With Number: THE FORMAT IS [TESTNUMBER]_[TESTNAME], EXAMPLE : 10_TESTNAME.'
$Dir = ($psise.CurrentFile.FullPath -replace "CreateTest.ps1", "")
$fullPath = $Dir + "Test_" + $TestName + ".cs"
$fullPathInput = $Dir + "Test_" + $TestName + "_INPUT"+ ".txt"
$fullPathOutput = $Dir + "Test_" + $TestName + "_OUTPUT"+".txt"
New-Item -Path $fullPath -ItemType File
New-Item -Path $fullPathInput -ItemType File
New-Item -Path $fullPathOutput -ItemType File
$testFileContentStart = "using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xamasoft.JsonClassGenerator;
using Xamasoft.JsonClassGenerator.CodeWriters;
namespace Json2CSharpCodeGenerator.Tests
{
`t[TestClass]";
$testFileClassName = "`r`n`tpublic class Test_{0}" -f $TestName;
$testFileContentStart1 =
"`r`n`t{
`t`t[TestMethod]
`t`tpublic void Run()
`t`t{";
$content1 = "`r`n`t`t`tstring path = Directory.GetCurrentDirectory().Replace(""bin\\Debug"", """") + @`"Test_{0}_INPUT.txt`";" -f $TestName;
$content2 = "`r`n`t`t`tstring resultPath = Directory.GetCurrentDirectory().Replace(""bin\\Debug"", """") + @`"Test_{0}_OUTPUT.txt`";" -f $TestName;
$testFileContentMiddle =
"`r`n`t`t`tstring input = File.ReadAllText(path);
`t`t`tstring errorMessage = string.Empty;
`t`t`tCSharpCodeWriter csharpCodeWriter = new CSharpCodeWriter();
`t`t`tJsonClassGenerator jsonClassGenerator = new JsonClassGenerator();
`t`t`tjsonClassGenerator.CodeWriter = csharpCodeWriter;
`t`t`tstring returnVal = jsonClassGenerator.GenerateClasses(input, out errorMessage).ToString();
`t`t`tstring resultsCompare = File.ReadAllText(resultPath);";
$testFileAssertion = "`r`n`t`t`tAssert.AreEqual(resultsCompare.Replace(Environment.NewLine, `"`").Replace(`" `", `"`").Replace(`"\t`", `"`"), returnVal.Replace(Environment.NewLine, `"`").Replace(`" `", `"`").Replace(`"\t`", `"`"));";
$testFileContentEnd = "
`t`t}
`t}
}";
$tesformattedString = $testFileContentStart + $testFileClassName + $testFileContentStart1 + $content1 + $content2 + $testFileContentMiddle + $testFileAssertion +$testFileContentEnd
Set-Content -Path $fullPath -Value $tesformattedString
Set-Content -Path $fullPathOutput -Value "dfasdfadfasdf" # DO NOT REMOVE : IF THIS IS EMPTY THE TEST WILL SUCCEED, WE WANT TO FAIL INITIALLY
#Set-ExecutionPolicy Restricted -Confirm:$false -Force;