json-2-c-sharp-code-generator/Json2CSharpCodeGenerator.Tests/Test_10_SETTINGS_IMMUTABLE_CLASSES.cs
2022-08-13 15:05:08 -07:00

40 lines
1.6 KiB
C#

using Json2CSharpCodeGenerator.Lib;
using Json2CSharpCodeGenerator.Lib.CodeWriters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Json2CSharpCodeGenerator.Tests;
[TestClass]
public class Test_10_SETTINGS_IMMUTABLE_CLASSES
{
[TestMethod]
public void Run()
{
string path = Path.Combine(AppContext.BaseDirectory, "Test_10_SETTINGS_IMMUTABLE_CLASSES_INPUT.txt");
string resultPath = Path.Combine(AppContext.BaseDirectory, "Test_10_SETTINGS_IMMUTABLE_CLASSES_OUTPUT.txt");
string input = File.ReadAllText(path);
JsonClassGenerator jsonClassGenerator = new()
{
CodeWriter = new CSharpCodeWriter(),
CollectionType = OutputCollectionType.IReadOnlyList,
OutputType = OutputTypes.ImmutableClass,
UseThisKeyWord = true,
AttributeLibrary = JsonLibrary.NewtonsoftJson,
AttributeUsage = JsonPropertyAttributeUsage.Always,
UsePascalCase = true,
};
string returnVal = jsonClassGenerator.GenerateClasses(input, errorMessage: out _).ToString();
string resultsCompare = File.ReadAllText(resultPath);
string expected = resultsCompare.NormalizeOutput();
string actual = returnVal.NormalizeOutput();
if (expected != actual)
{
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "Test_10_SETTINGS_IMMUTABLE_CLASSES_OUTPUT.actual.txt"), returnVal);
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "Test_10_SETTINGS_IMMUTABLE_CLASSES_OUTPUT.expected.txt"), resultsCompare);
}
Assert.AreEqual(expected, actual);
}
}