UnitTests/AlignOriginTests.cs

Unit test class for VMDL editing that verifies MeshEntryProperties align origin and import scale values are written into a KV3 VMDL representation. It loads a sample tool file, applies property changes through VmdlBulkEditor, then parses the resulting KV3 and asserts fields match expected values.

File Access
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModelPro.Vmdl;

[TestClass]
public class AlignOriginTests
{
	const string ToolFile = """
	{
		rootNode = 
		{
			_class = "RootNode"
			children = 
			[
				{
					_class = "RenderMeshList"
					children = 
					[
						{
							_class = "RenderMeshFile"
							filename = "models/vehicle_01_a.fbx"
							import_scale = 1.0
							align_origin_x_type = "Center"
							align_origin_y_type = "Center"
							align_origin_z_type = "Mins"
						},
					]
				},
			]
		}
	}
	""";

	[TestMethod]
	public void AllAlignOriginsRoundTrip()
	{
		foreach ( var value in Enum.GetValues<AlignOrigin>() )
		{
			var kv3 = value.ToKv3Value();

			var editor = VmdlBulkEditor.Load( ToolFile );
			var props = new MeshEntryProperties
			{
				AlignOriginX = value,
				AlignOriginY = value,
				AlignOriginZ = value
			};

			Assert.IsTrue( editor.Apply( props ), $"{value} should change the file" );

			var parsed = Kv3Document.Parse( editor.Source );
			var entry = parsed.FindObjects( "RenderMeshFile" ).Single();
			Assert.AreEqual( kv3, ((Kv3Scalar)entry.FindField( "align_origin_x_type" ).Value).Value, value.ToString() );
		}
	}

	[TestMethod]
	public void BoundsValuesAreWritable()
	{
		var editor = VmdlBulkEditor.Load( ToolFile );
		var props = new MeshEntryProperties
		{
			ImportScale = 0.3937f,
			AlignOriginX = AlignOrigin.BoundsCenter,
			AlignOriginY = AlignOrigin.BoundsCenter,
			AlignOriginZ = AlignOrigin.BoundsMin
		};

		Assert.IsTrue( editor.Apply( props ), "Bounds* align values should apply" );

		var parsed = Kv3Document.Parse( editor.Source );
		var entry = parsed.FindObjects( "RenderMeshFile" ).Single();
		Assert.AreEqual( "0.3937", ((Kv3Scalar)entry.FindField( "import_scale" ).Value).Value );
		Assert.AreEqual( "BoundsCenter", ((Kv3Scalar)entry.FindField( "align_origin_x_type" ).Value).Value );
		Assert.AreEqual( "BoundsCenter", ((Kv3Scalar)entry.FindField( "align_origin_y_type" ).Value).Value );
		Assert.AreEqual( "BoundsMin", ((Kv3Scalar)entry.FindField( "align_origin_z_type" ).Value).Value );
	}
}