public void TestPackagedContentLoading() { // Extract the .xnb test file for the unit test and compress it string packagePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.package"); { string filePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb"); writeBytesToFile( Resources.UnitTestResources.UnitTestEffect, filePath ); LzmaPackageBuilder.Build( packagePath, new LzmaPackageBuilder.PackageFile(filePath, "UnitTestEffect") ); File.Delete(filePath); } using ( LzmaContentManager contentManager = new LzmaContentManager( GraphicsDeviceServiceHelper.MakePrivateServiceProvider( this.mockedGraphicsDeviceService ), packagePath ) ) { contentManager.RootDirectory = Path.GetDirectoryName(packagePath); Effect effect = contentManager.Load <Effect>("UnitTestEffect"); Assert.IsNotNull(effect); } }
public void TestPackagedContentReplacement() { // Extract the .xnb test file for the unit test and compress it string packagePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.package"); { string filePath = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb"); // We will compress this nonsense file so that if the replacement isn't // honored, the content manager will fail. writeBytesToFile( new byte[] { (byte)'C', (byte)'r', (byte)'a', (byte)'p' }, filePath ); LzmaPackageBuilder.Build( packagePath, new LzmaPackageBuilder.PackageFile(filePath, "UnitTestEffect") ); File.Delete(filePath); // Now write the replacement, which actually contains valid data writeBytesToFile( Resources.UnitTestResources.UnitTestEffect, filePath ); } using ( LzmaContentManager contentManager = new LzmaContentManager( GraphicsDeviceServiceHelper.MakePrivateServiceProvider( this.mockedGraphicsDeviceService ), packagePath ) ) { contentManager.RootDirectory = this.tempDirectory.Path; // This only works if the content manager loads the replacement instead // of the packaged file Effect effect = contentManager.Load <Effect>("UnitTestEffect"); Assert.IsNotNull(effect); } }