public void AddPackageWithFrameworkReferenceCreatesWebConfigIfItDoesNotExist() { // Arrange string webConfigPath = @"x:\my-website\web.config"; MemoryStream memoryStream = new MemoryStream(); var fileSystem = new Mock <IFileSystem>(); fileSystem.SetupGet(f => f.Root).Returns("x:\\my-website"); fileSystem.Setup(f => f.FileExists(It.Is <string>(p => p.Equals(webConfigPath)))).Returns(false).Verifiable(); fileSystem.Setup(f => f.AddFile(It.Is <string>(p => p.Equals(webConfigPath)), It.IsAny <Stream>())) .Callback <string, Stream>((_, s) => { s.CopyTo(memoryStream); }); var references = "System"; // Act WebProjectSystem.AddReferencesToConfig(fileSystem.Object, references); // Assert memoryStream.Seek(0, SeekOrigin.Begin); XDocument document = XDocument.Load(memoryStream); var element = document.Root; Assert.Equal(element.Name, "configuration"); // Use SingleOrDefault to ensure there's exactly one element with that name var assemblies = document.Root .Elements().SingleOrDefault(e => e.Name.ToString().Equals("system.web")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("compilation")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("assemblies")); Assert.Equal(references, assemblies.Elements().First().Attribute("assembly").Value); }
public void GetRemotePackagesTest() { // Arrange var siteRoot = "x:\\"; var localRepository = new MockPackageRepository(); var sourceRepository = new MockServiceBasePackageRepository(); var projectSystem = new WebProjectSystem(siteRoot); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(sourceRepository, pathResolver, projectSystem, localRepository); var net40 = new FrameworkName(".NETFramework", new Version("4.0.0.0")); var net45 = new FrameworkName(".NETFramework", new Version("4.5.0.0")); IPackage packageA = PackageFactory.Create("A", new Version("1.0"), null, new FrameworkName[] { net40 }); IPackage packageB = PackageFactory.Create("B", new Version("1.0"), null, new FrameworkName[] { net45 }); IPackage packageC = PackageFactory.Create("C", new Version("1.0")); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageB); sourceRepository.AddPackage(packageC); // NOTE THAT target framework used by WebProjectManager would be .NETFramework, Version=4.0.0.0 var webProjectManager = new WebProjectManager(projectManager, siteRoot); // Act var packages = webProjectManager.GetRemotePackages(null, false).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal(packageA, packages[0]); Assert.Equal(packageC, packages[1]); }
public void GetRemotePackagesTest() { // Arrange var siteRoot = "x:\\"; var localRepository = new MockPackageRepository(); var sourceRepository = new MockServiceBasePackageRepository(); var projectSystem = new WebProjectSystem(siteRoot); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(sourceRepository, pathResolver, projectSystem, localRepository); var net40 = new FrameworkName(".NETFramework", new Version("4.0.0.0")); var net45 = new FrameworkName(".NETFramework", new Version("4.5.0.0")); IPackage packageA = PackageFactory.Create("A", new Version("1.0"), null, new FrameworkName[]{ net40 }); IPackage packageB = PackageFactory.Create("B", new Version("1.0"), null, new FrameworkName[]{ net45 }); IPackage packageC = PackageFactory.Create("C", new Version("1.0")); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageB); sourceRepository.AddPackage(packageC); // NOTE THAT target framework used by WebProjectManager would be .NETFramework, Version=4.0.0.0 var webProjectManager = new WebProjectManager(projectManager, siteRoot); // Act var packages = webProjectManager.GetRemotePackages(null, false).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal(packageA, packages[0]); Assert.Equal(packageC, packages[1]); }
// Methods public WebProjectManager(string remoteSource, string siteRoot) { string webRepositoryDirectory = GetWebRepositoryDirectory(siteRoot); var sourceRepository = PackageRepositoryFactory.Default.CreateRepository(remoteSource); var pathResolver = new DefaultPackagePathResolver(webRepositoryDirectory); var localRepository = PackageRepositoryFactory.Default.CreateRepository(webRepositoryDirectory); IProjectSystem project = new WebProjectSystem(siteRoot); _projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository); }
public void AddPackageWithFrameworkReferenceCreatesWebConfigIfItExistsWithoutAssembliesNode() { // Arrange var webConfigPath = @"x:\my-website\web.config"; var webConfigContent = @"<?xml version=""1.0""?> <configuration> <connectionStrings> <add name=""test"" /> </connectionStrings> <system.web> <profiles><add name=""awesomeprofile"" /></profiles> </system.web> </configuration> ".AsStream(); MemoryStream memoryStream = new MemoryStream(); var fileSystem = new Mock <IFileSystem>(); fileSystem.SetupGet(f => f.Root).Returns("x:\\my-website"); fileSystem.Setup(f => f.FileExists(It.Is <string>(p => p.Equals(webConfigPath)))).Returns(true).Verifiable(); fileSystem.Setup(f => f.OpenFile(It.Is <string>(p => p.Equals(webConfigPath)))).Returns(webConfigContent); fileSystem.Setup(f => f.AddFile(It.Is <string>(p => p.Equals(webConfigPath)), It.IsAny <Stream>())) .Callback <string, Stream>((_, s) => { s.CopyTo(memoryStream); }); var references = "System.Data"; // Act WebProjectSystem.AddReferencesToConfig(fileSystem.Object, references); // Assert memoryStream.Seek(0, SeekOrigin.Begin); XDocument document = XDocument.Load(memoryStream); var element = document.Root; Assert.Equal(element.Name, "configuration"); // Use SingleOrDefault to ensure there's exactly one element with that name var assemblies = document.Root .Elements().SingleOrDefault(e => e.Name.ToString().Equals("system.web")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("compilation")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("assemblies")); Assert.Equal(references, assemblies.Elements().First().Attribute("assembly").Value); // Make sure the original web.config content is unaffected Assert.Equal("test", document.Root .Elements().SingleOrDefault(e => e.Name.ToString().Equals("connectionStrings")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("add")) .Attributes().SingleOrDefault(e => e.Name.ToString().Equals("name")).Value); Assert.Equal("awesomeprofile", document.Root.Element("system.web").Element("profiles").Element("add").Attribute("name").Value); }
public void ResolvePathReturnsOriginalPathIfFileIsNotSource() { // Arrange var path = @"Foo.js"; var webProjectSystem = new WebProjectSystem(@"x:\"); // Act var resolvedPath = webProjectSystem.ResolvePath(path); // Assert Assert.Equal(path, resolvedPath); }
public void ResolvePathReturnsOriginalPathIfSourceFilePathIsAlreadyUnderAppCode() { // Arrange var path = @"App_Code\Foo.cs"; var webProjectSystem = new WebProjectSystem(@"x:\"); // Act var resolvedPath = webProjectSystem.ResolvePath(path); // Assert Assert.Equal(path, resolvedPath); }
public void ResolvePathReturnsAppCodePathIfPathIsSourceFile() { // Arrange var path = "Foo.cs"; var webProjectSystem = new WebProjectSystem(@"x:\"); // Act var resolvedPath = webProjectSystem.ResolvePath(path); // Assert Assert.Equal(@"App_Code\Foo.cs", resolvedPath); }
public WebProjectManager(string remoteSource, string siteRoot) { string webRepositoryDirectory = GetWebRepositoryDirectory(siteRoot); Uri uri = new Uri(remoteSource); IPackageRepository repository = new DataServicePackageRepository(uri); //PackageRepositoryFactory.Default.CreateRepository(remoteSource); IPackagePathResolver resolver = new DefaultPackagePathResolver(webRepositoryDirectory); IPackageRepository repository2 = new LocalPackageRepository(webRepositoryDirectory, false); //PackageRepositoryFactory.Default.CreateRepository(webRepositoryDirectory); IProjectSystem system = new WebProjectSystem(siteRoot); ((DataServicePackageRepository)repository).ProgressAvailable += new EventHandler <ProgressEventArgs>(repository_ProgressAvailable); //((DataServicePackageRepository)repository).SendingRequest += new EventHandler<WebRequestEventArgs>(repository_sendingRequest); this._projectManager = new ProjectManager(repository, resolver, system, repository2); _projectManager.Logger = new LoggerController(); }
public void IsFileSupportedRejectsAllVariationsOfAppConfig(string filePath) { // Arrange var mockFileSystemProvider = new Mock<IFileSystemProvider>(); mockFileSystemProvider.Setup(fs => fs.GetFileSystem(It.IsAny<string>())).Returns(new MockFileSystem()); Project project = TestUtils.GetProject("TestProject"); var projectSystem = new WebProjectSystem(project, mockFileSystemProvider.Object); // Act bool supported = projectSystem.IsSupportedFile(filePath); // Assert Assert.False(supported); }
public void IsFileSupportedRejectsAllVariationsOfAppConfig(string filePath) { // Arrange var mockFileSystemProvider = new Mock <IFileSystemProvider>(); mockFileSystemProvider.Setup(fs => fs.GetFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); Project project = TestUtils.GetProject("TestProject"); var projectSystem = new WebProjectSystem(project, mockFileSystemProvider.Object); // Act bool supported = projectSystem.IsSupportedFile(filePath); // Assert Assert.False(supported); }
public void ResolveAssemblyPartialNameForCommonAssemblies() { // Arrange var commonAssemblies = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "System.Data", "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" }, { "System.Data.Linq", "System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" }, { "System.Net", "System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }, { "System.Runtime.Caching", "System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }, { "System.Xml", "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" }, { "System.Web.DynamicData", "System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" }, }; // Act and Assert foreach (var item in commonAssemblies) { var resolvedName = WebProjectSystem.ResolvePartialAssemblyName(item.Key); Assert.Equal(item.Value, resolvedName); } }
public void AddPackageWithFrameworkReferenceDoesNotAffectWebConfigIfReferencesAlreadyExist() { // Arrange var webConfigPath = @"x:\my-website\web.config"; var memoryStream = new NeverCloseMemoryStream(@"<?xml version=""1.0""?> <configuration> <connectionStrings> <add name=""test"" /> </connectionStrings> <system.web> <compilation> <assemblies> <add assembly=""System.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"" /> </assemblies> </compilation> <profiles><add name=""awesomeprofile"" /></profiles> </system.web> </configuration> "); var fileSystem = new Mock <IFileSystem>(); fileSystem.SetupGet(f => f.Root).Returns("x:\\my-website"); fileSystem.Setup(f => f.FileExists(It.Is <string>(p => p.Equals(webConfigPath)))).Returns(true); fileSystem.Setup(f => f.OpenFile(It.Is <string>(p => p.Equals(webConfigPath)))).Returns(() => { memoryStream.Seek(0, SeekOrigin.Begin); return(memoryStream); }); fileSystem.Setup(f => f.AddFile(It.Is <string>(p => p.Equals(webConfigPath)), It.IsAny <Stream>())) .Callback <string, Stream>((_, stream) => { memoryStream = new NeverCloseMemoryStream(stream.ReadToEnd()); }); // Act WebProjectSystem.AddReferencesToConfig(fileSystem.Object, "System.Data"); WebProjectSystem.AddReferencesToConfig(fileSystem.Object, "Microsoft.Abstractions"); // Assert memoryStream.Seek(0, SeekOrigin.Begin); XDocument document = XDocument.Load(memoryStream); var element = document.Root; Assert.Equal(element.Name, "configuration"); // Use SingleOrDefault to ensure there's exactly one element with that name var assemblies = document.Root .Elements().SingleOrDefault(e => e.Name.ToString().Equals("system.web")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("compilation")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("assemblies")); Assert.Equal(2, assemblies.Elements("add").Count()); Assert.Equal("System.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35", assemblies.Elements().First().Attribute("assembly").Value); Assert.Equal("Microsoft.Abstractions", assemblies.Elements().Last().Attribute("assembly").Value); // Make sure the original web.config content is unaffected Assert.Equal("test", document.Root .Elements().SingleOrDefault(e => e.Name.ToString().Equals("connectionStrings")) .Elements().SingleOrDefault(e => e.Name.ToString().Equals("add")) .Attributes().SingleOrDefault(e => e.Name.ToString().Equals("name")).Value); Assert.Equal("awesomeprofile", document.Root.Element("system.web").Element("profiles").Element("add").Attribute("name").Value); }