public void PackagesManager_GetVirtualPathForGivenPackage_VerifyTheVirtualPathIsCorrect() { //Arrange: Initialize the PackagesManager and a fake package name var packageManager = new PackagesManager(); string packageName = "fakePackageName"; string packageVirtualpath; //Act: gets the package virtual path packageVirtualpath = packageManager.GetPackageVirtualPath(packageName); //Assert: Verify if the manager throws an error if the parameter is null and if the package virtual path is correct try { packageManager.GetPackageVirtualPath(null); Assert.Fail("Expected exception was not thrown"); } catch { } Assert.AreEqual<string>(string.Format("~/{0}/{1}", PackagesManager.PackagesFolder, packageName), packageVirtualpath, "Package virtual path is not correct"); }
/// <summary> /// Strips the name of the package name from template. /// If there is no existing package presented on the searched location the method will preserve the full template name. /// </summary> /// <param name="templateTitle">Title of the template.</param> /// <returns></returns> private string StripPackageNameFromTemplateName(string templateTitle) { var parts = templateTitle.Split('.'); if (parts.Length > 1) { var packagesManager = new PackagesManager(); var packageVirtualPath = packagesManager.GetPackageVirtualPath(parts[0]); var packagePath = HostingEnvironment.MapPath(packageVirtualPath); if (Directory.Exists(packagePath)) templateTitle = string.Join(".", parts, 1, parts.Length - 1); } return templateTitle; }