public void TestPackagedContentReplacementWhenNoPackageExists()
        {
            string packagePath = Path.Combine(
                this.tempDirectory.Path, "PackagedUnitTestEffect.package"
                );

            writeBytesToFile(
                Resources.UnitTestResources.UnitTestEffect,
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                // The package doesn't even exist, but because replacement is allowed,
                // no error should occur if the requested asset is available directly
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        public void TestCompressedContentLoading()
        {
            // Extract the .xnb test file for the unit test and compress it
            {
                string path = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb");
                writeBytesToFile(
                    Resources.UnitTestResources.UnitTestEffect,
                    path
                    );
                LzmaContentCompressor.CompressContentFile(path);
                File.Delete(path);
            }

            // Now try to load the compressed file
            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        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 TestCompressedContentReplacement()
        {
            // If the replacement doesn't work, the test will load this file which,
            // as the observant programmer might notice, contains 'Crap' :-)
            writeBytesToFile(
                new byte[] { (byte)'C', (byte)'r', (byte)'a', (byte)'p' },
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.lzma")
                );

            // Write the real file the test should be loading
            writeBytesToFile(
                Resources.UnitTestResources.UnitTestEffect,
                Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                // The .lzma file contains 'Crap' (literally :D), so if the content manager
                // didn't see the replacement file, it would fall on its nose here!
                Effect effect = contentManager.Load <Effect>("UnitTestEffect");
                Assert.IsNotNull(effect);
            }
        }
        public void TestThrowOnMissingCompressedAsset()
        {
            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        )
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Assert.Throws <ArgumentException>(
                    delegate() {
                    contentManager.Load <Effect>("DoesNotExist");
                }
                    );
            }
        }
        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);
            }
        }
        public void TestThrowsOnMissingPackagedAsset()
        {
            string packagePath = Path.Combine(
                this.tempDirectory.Path, "PackagedUnitTestEffect.package"
                );

            using (
                LzmaContentManager contentManager = new LzmaContentManager(
                    GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                        this.mockedGraphicsDeviceService
                        ),
                    packagePath
                    )
                ) {
                contentManager.RootDirectory = this.tempDirectory.Path;

                Assert.Throws <ArgumentException>(
                    delegate() {
                    contentManager.Load <Effect>("DoesNotExist");
                }
                    );
            }
        }
    public void TestCompressedContentLoading() {

      // Extract the .xnb test file for the unit test and compress it
      {
        string path = Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb");
        writeBytesToFile(
          Resources.UnitTestResources.UnitTestEffect,
          path
        );
        LzmaContentCompressor.CompressContentFile(path);
        File.Delete(path);
      }

      // Now try to load the compressed file
      using(
        LzmaContentManager contentManager = new LzmaContentManager(
          GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
            this.mockedGraphicsDeviceService
          )
        )
      ) {
        contentManager.RootDirectory = this.tempDirectory.Path;

        Effect effect = contentManager.Load<Effect>("UnitTestEffect");
        Assert.IsNotNull(effect);
      }
    }
    public void TestThrowOnMissingCompressedAsset() {
      using(
        LzmaContentManager contentManager = new LzmaContentManager(
          GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
            this.mockedGraphicsDeviceService
          )
        )
      ) {
        contentManager.RootDirectory = this.tempDirectory.Path;

        Assert.Throws<ArgumentException>(
          delegate() {
            contentManager.Load<Effect>("DoesNotExist");
          }
        );
      }
    }
    public void TestThrowsOnMissingPackagedAsset() {
      string packagePath = Path.Combine(
        this.tempDirectory.Path, "PackagedUnitTestEffect.package"
      );
      using(
        LzmaContentManager contentManager = new LzmaContentManager(
          GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
            this.mockedGraphicsDeviceService
          ),
          packagePath
        )
      ) {
        contentManager.RootDirectory = this.tempDirectory.Path;

        Assert.Throws<ArgumentException>(
          delegate() {
            contentManager.Load<Effect>("DoesNotExist");
          }
        );
      }
    }
    public void TestPackagedContentReplacementWhenNoPackageExists() {
      string packagePath = Path.Combine(
        this.tempDirectory.Path, "PackagedUnitTestEffect.package"
      );
      writeBytesToFile(
        Resources.UnitTestResources.UnitTestEffect,
        Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
      );

      using(
        LzmaContentManager contentManager = new LzmaContentManager(
          GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
            this.mockedGraphicsDeviceService
          ),
          packagePath
        )
      ) {
        contentManager.RootDirectory = this.tempDirectory.Path;

        // The package doesn't even exist, but because replacement is allowed,
        // no error should occur if the requested asset is available directly
        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);
      }
    }
    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 TestCompressedContentReplacement() {

      // If the replacement doesn't work, the test will load this file which,
      // as the observant programmer might notice, contains 'Crap' :-)
      writeBytesToFile(
        new byte[] { (byte)'C', (byte)'r', (byte)'a', (byte)'p' },
        Path.Combine(this.tempDirectory.Path, "UnitTestEffect.lzma")
      );

      // Write the real file the test should be loading
      writeBytesToFile(
        Resources.UnitTestResources.UnitTestEffect,
        Path.Combine(this.tempDirectory.Path, "UnitTestEffect.xnb")
      );

      using(
        LzmaContentManager contentManager = new LzmaContentManager(
          GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
            this.mockedGraphicsDeviceService
          )
        )
      ) {
        contentManager.RootDirectory = this.tempDirectory.Path;

        // The .lzma file contains 'Crap' (literally :D), so if the content manager
        // didn't see the replacement file, it would fall on its nose here!
        Effect effect = contentManager.Load<Effect>("UnitTestEffect");
        Assert.IsNotNull(effect);
      }
    }