public void GivenTopLevelDirectoryHasFilesAndSubDirectory_WhenAddPerSubDirectory_ThenBundleAlsoCreatedForTopLevel() { File.WriteAllText(Path.Combine(tempDirectory, "file-a.js"), ""); CreateDirectory("test"); File.WriteAllText(PathUtilities.Combine(tempDirectory, "test", "file-b.js"), ""); defaultAssetSource .SetupSequence(s => s.FindFiles(It.IsAny <IDirectory>())) .Returns(new[] { StubFile(mock => mock.SetupGet(f => f.Directory).Returns(settings.SourceDirectory)) }) .Returns(new[] { StubFile() }); bundles.AddPerSubDirectory <TestableBundle>("~"); bundles.Count().ShouldEqual(2); factory.Verify(f => f.CreateBundle( "~", It.Is <IEnumerable <IFile> >(files => files.Count() == 1), It.IsAny <BundleDescriptor>()) ); factory.Verify(f => f.CreateBundle( "~/test", It.Is <IEnumerable <IFile> >(files => files.Count() == 1), It.IsAny <BundleDescriptor>()) ); }
string HashFileContent(string filename) { using (var file = File.OpenRead(PathUtilities.Combine(root, "source", filename))) using (var sha1 = SHA1.Create()) { return(sha1.ComputeHash(file).ToHexString()); } }
public void WhenAddWithExplicitFileNotStartingWithTildeButBundleDirectoryExists_ThenAssetFileIsBundleRelative() { Directory.CreateDirectory(Path.Combine(tempDirectory, "bundle")); File.WriteAllText(PathUtilities.Combine(tempDirectory, "bundle", "file1.js"), ""); bundles.Add <TestableBundle>("~/bundle", new[] { "file1.js" }); FilesUsedToCreateBundle[0].ShouldEqual("~/bundle/file1.js"); }
public void GivenDirectoryWithExternalBundleDescriptorButNoAssets_WhenAddPerSubDirectory_ThenBundleCreatedForDirectory() { CreateDirectory("test"); File.WriteAllText( PathUtilities.Combine(tempDirectory, "test", "bundle.txt"), "[external]" + Environment.NewLine + "url=http://example.org/" ); bundles.AddPerSubDirectory <TestableBundle>("~"); bundles.Count().ShouldEqual(1); }
public void AddReferenceToSiblingFilenameInSubDirectory_ExpandsFilenameToAbsolutePath() { root.CreateSubdirectory("bundle\\sub"); File.WriteAllText(PathUtilities.Combine(root.FullName, "bundle", "sub", "another.js"), ""); var another = new FileAsset(StubFile(fullPath: "~/bundle/sub/another.js"), bundle); bundle.Assets.Add(another); asset.AddReference("sub\\another.js", 1); asset.References.First().ToPath.ShouldEqual("~/bundle/sub/another.js"); }
public void GivenNavigatedToSubDirectory_WhenGetFilePaths_ThenFullPathStillReturned() { using (var path = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(path, "test")); File.WriteAllText(PathUtilities.Combine(path, "test", "asset.js"), ""); var testDir = new FileSystemDirectory(path).GetDirectory("test"); var filePaths = testDir.GetFiles("*.js", SearchOption.AllDirectories).ToArray(); filePaths[0].FullPath.ShouldEqual("~/test/asset.js"); } }
public void FullPathsReturned() { using (var path = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(path, "test")); File.WriteAllText(PathUtilities.Combine(path, "test", "asset.js"), ""); var dir = new FileSystemDirectory(path); var filePaths = dir.GetFiles("*.js", SearchOption.AllDirectories).ToArray(); filePaths[0].FullPath.ShouldEqual("~/test/asset.js"); } }
public void GivenTopLevelDirectoryHasFilesAndSubDirectory_WhenAddPerSubDirectoryWithExcludeTopLevelTrue_ThenBundleNotCreatedForTopLevel() { File.WriteAllText(Path.Combine(tempDirectory, "file-a.js"), ""); CreateDirectory("test"); File.WriteAllText(PathUtilities.Combine(tempDirectory, "test", "file-b.js"), ""); defaultAssetSource .Setup(s => s.FindFiles(It.IsAny <IDirectory>())) .Returns(new[] { StubFile() }); bundles.AddPerSubDirectory <TestableBundle>("~", excludeTopLevel: true); bundles.Count().ShouldEqual(1); bundles["~/test"].ShouldBeType <TestableBundle>(); }
public void WhenAddWithExplicitFileNotStartingWithTildeButBundleDirectoryExists_ThenAssetFileIsBundleRelative() { using (var temp = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(temp, "bundle")); File.WriteAllText(PathUtilities.Combine(temp, "bundle", "file1.js"), ""); var settings = new CassetteSettings(""); var bundles = new BundleCollection(settings); settings.SourceDirectory = new FileSystemDirectory(temp); bundles.Add <ScriptBundle>("~/bundle", new[] { "file1.js" }); bundles["~/bundle"].Assets[0].SourceFile.FullPath.ShouldEqual("~/bundle/file1.js"); } }
void CompileTimeManifestWithBundleExists(string rootDirectory) { var bundle = StubBundle(); var bundleManifest = bundle.CreateBundleManifest(true); var cassetteManifest = new CassetteManifest("", new[] { bundleManifest }); var manifestFilename = PathUtilities.Combine(rootDirectory, "App_Data", "cassette.xml"); Directory.CreateDirectory(Path.Combine(rootDirectory, "App_Data")); using (var outputStream = File.Open(manifestFilename, FileMode.Create, FileAccess.Write)) { var writer = new CassetteManifestWriter(outputStream); writer.Write(cassetteManifest); } configurationSection.PrecompiledManifest = "App_Data/cassette.xml"; }
public CreateBundlesWithRawFilesTests() { root = new TempDirectory(); CreateDirectory("source"); CreateDirectory("source\\bin"); CreateDirectory("output"); WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }"); WriteFile("source\\test.png", "image"); var configurationDll = CompileConfigurationDll(); File.Move(configurationDll, PathUtilities.Combine(root, "source", "bin", "test.dll")); File.Copy("Cassette.dll", PathUtilities.Combine(root, "source", "bin", "Cassette.dll")); File.Copy("Cassette.pdb", PathUtilities.Combine(root, "source", "bin", "Cassette.pdb")); File.Copy("AjaxMin.dll", PathUtilities.Combine(root, "source", "bin", "AjaxMin.dll")); #if NET35 File.Copy("Iesi.Collections.dll", PathUtilities.Combine(root, "source", "bin", "Iesi.Collections.dll")); #endif buildEngine = new BuildEngineStub(); var task = new CreateBundles { BuildEngine = buildEngine }; var taskLoggingHelper = new TaskLoggingHelper(task); var command = new CreateBundlesCommand( PathUtilities.Combine(root, "source"), PathUtilities.Combine(root, "source", "bin"), PathUtilities.Combine(root, "output"), "/", true, taskLoggingHelper ); CreateBundlesCommand.ExecuteInSeparateAppDomain(command); }
public void GivenStylesheetWithExternalReference_WhenCreateContainer_ThenExternalBundleAddedToBundleCollection() { using (var path = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(path, "styles")); File.WriteAllText(PathUtilities.Combine(path, "styles", "asset.css"), "/* @reference http://example.com */"); var configuration = new StubConfiguration(bundles => bundles.Add <StylesheetBundle>("styles")); var factory = new CassetteApplicationContainerFactory( new DelegateCassetteConfigurationFactory(() => new[] { configuration }), new CassetteConfigurationSection(), path, "/", false, Mock.Of <HttpContextBase> ); var container = factory.CreateContainer(); container.Application.Bundles.Any( b => b is ExternalStylesheetBundle && b.Path == "http://example.com" ).ShouldBeTrue(); } }
void CreateFile(params string[] paths) { var filename = Path.Combine(temp, PathUtilities.Combine(paths)); File.WriteAllText(filename, ""); }
public void ImageFileIsCopiedToOutput() { var imageOutputFilename = PathUtilities.Combine(root, "output", "file", "test-" + HashFileContent("test.png") + ".png"); File.Exists(imageOutputFilename).ShouldBeTrue(); }