示例#1
0
        public void BundleTest()
        {
            // create bundle
            var bundle = CreateBundle();

            var bundleFile = new FileInfo(Path.Combine(_temporaryDirectory, Guid.NewGuid().ToString() + ".css.bundle"));
            var bundleOutputFile = new System.IO.FileInfo(bundleFile.FullName.Replace(".css.bundle", ".min.css"));
            Bundle.Serialize(bundle, bundleFile.FullName);

            // move the creation and last write back in time to simulate real world
            bundleFile.CreationTimeUtc = DateTime.UtcNow.AddHours(-1);
            bundleFile.LastWriteTimeUtc = bundleFile.CreationTimeUtc;

            Assert.False(bundleOutputFile.Exists);

            // bundle
            var bundler = new NUnitBundler();
            bundler.Bundle(bundleFile.FullName);

            // test to ensure the output file was created
            bundleOutputFile.Refresh();
            Assert.True(bundleOutputFile.Exists);
            var bundleOutputFileLastWriteUtc = bundleOutputFile.LastWriteTimeUtc;

            // create a new bundler and do it again
            bundler = new NUnitBundler();
            bundler.Bundle(bundleFile.FullName);

            // test to ensure the output file was created
            bundleOutputFile.Refresh();
            Assert.True(bundleOutputFile.Exists);

            // ensure it hasn't changed since nothing has changed
            Assert.AreEqual(bundleOutputFileLastWriteUtc, bundleOutputFile.LastWriteTimeUtc, "The file should not have changed.");

            // change the bundle file and do it again
            bundle.Includes.RemoveAt(0);
            Bundle.Serialize(bundle, bundleFile.FullName);

            // create a new bundler and do it again
            bundler = new NUnitBundler();
            bundler.Bundle(bundleFile.FullName);

            // test to ensure the output file was created
            bundleOutputFile.Refresh();
            Assert.True(bundleOutputFile.Exists);

            // ensure the output file HAS changed since we modified the bundle
            Assert.Greater(bundleOutputFile.LastWriteTimeUtc, bundleOutputFileLastWriteUtc, "The file should have changed.");
        }