UnitTests/PngWriterTests.cs

Unit test for PngWriter. Creates a temporary directory, writes a 2x2 RGBA PNG via PngWriter.Write, checks file exists and PNG signature bytes, then cleans up.

File Access
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GmodAssetImporter;

[TestClass]
public class PngWriterTests
{
	[TestMethod]
	public void WritesValidPngSignature()
	{
		var dir = Path.Combine( Path.GetTempPath(), "gmodassetimporter_tests", Guid.NewGuid().ToString( "N" ) );
		Directory.CreateDirectory( dir );
		var path = Path.Combine( dir, "pixel.png" );

		try
		{
			var rgba = new byte[] { 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255 };
			PngWriter.Write( path, 2, 2, rgba );
			Assert.IsTrue( File.Exists( path ) );
			var bytes = File.ReadAllBytes( path );
			Assert.IsTrue( bytes.Length > 8 );
			Assert.AreEqual( 137, bytes[0] );
			Assert.AreEqual( 80, bytes[1] );
			Assert.AreEqual( 78, bytes[2] );
			Assert.AreEqual( 71, bytes[3] );
		}
		finally
		{
			try { Directory.Delete( dir, true ); } catch { /* ignore */ }
		}
	}
}