private ImmutableList <ITemplate> LoadTemplates(IFileSystem fileSystem, ITemplateLoader templateLoader, ILogger <RepositoryLoader> logger) { var templates = ImmutableList.CreateBuilder <ITemplate>(); var templatePaths = fileSystem.Directory. EnumerateDirectories(this.RootPath.Join("templates").ToString()). Select(path => PurePath.Create(path)); foreach (var templatePath in templatePaths) { try { var templateFolderName = templatePath.Basename; ValidateTemplateFolderName(templateFolderName); var p = PurePath.Create("/opt/stamp/repos/TestRepo/templates/TestTemplate@1"); var template = templateLoader.LoadFromTemplateDirectory(templatePath); ValidateTemplateAgainstTemplateFolderName(template, templateFolderName); templates.Add(template); } catch (Exception ex) { logger.LogWarning(ex, $"Failed to load template from {templatePath}."); throw; } } return(templates.ToImmutable()); }
public TemplateTests() { this.FileSystem = new MockFileSystem(); this.TemplateLoader = new TemplateLoader(this.FileSystem); this.TestTemplatePath = PurePath.Create("/opt/template"); this.TestTemplateManifestPath = TestTemplatePath.Join("manifest.yml"); }
public void Compare_PosixFormat_Directory_With_Directory_OneWithTrailingSlash_ShouldBeEqual() { var firstPath = @"/mnt/dev/parent/"; var secondPath = @"/mnt/dev/parent"; var firstPurePath = PurePath.Create(firstPath); var secondPurePath = PurePath.Create(secondPath); Assert.Equal(firstPurePath, secondPurePath); }
public void Compare_WindowsFormat_Directory_With_TopLevelFile_ShouldBeNotEqual() { var firstPath = @"C:\foo\bar\"; var secondPath = @"C:\foo\bar\file.txt"; var firstPurePath = PurePath.Create(firstPath); var secondPurePath = PurePath.Create(secondPath); Assert.NotEqual(firstPurePath, secondPurePath); }
public void Compare_WindowsFormat_Directory_With_SubDirectory_ShouldBeNotEqual_ShouldBeTrue() { var firstPath = @"C:\foo\bar"; var secondPath = @"C:\foo\bar\other"; var firstPurePath = PurePath.Create(firstPath); var secondPurePath = PurePath.Create(secondPath); Assert.NotEqual(firstPurePath, secondPurePath); }
public void Compare_WindowsFormat_Directory_With_Directory_OneWithTrailingSlash_ShouldBeEqual() { var firstPath = @"C:\foo\bar"; var secondPath = @"C:\foo\bar\"; var firstPurePath = PurePath.Create(firstPath); var secondPurePath = PurePath.Create(secondPath); Assert.Equal(firstPurePath, secondPurePath); }
public void Compare_PosixFormat_Directory_With_TopLevelFile_ShouldBeNotEqual_ShouldBeTrue() { var parentPath = @"/mnt/dev/parent/"; var childPath = @"/mnt/dev/parent/someChild/someFile.txt"; var firstPurePath = PurePath.Create(parentPath); var secondPurePath = PurePath.Create(childPath); Assert.NotEqual(firstPurePath, secondPurePath); }
public void Compare_PosixFormat__DifferentRoots_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeFalse() { var parentPath = @"/mnt/other/parent"; var childPath = @"/dev/other/parent/someChild"; var purePathFactory = new PurePathFactory(); var parentPurePath = PurePath.Create(parentPath); var childPurePath = PurePath.Create(childPath); Assert.False(childPurePath > parentPurePath); }
public void Compare_PosixFormat_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeTrue() { var parentPath = @"/mnt/dev/parent"; var childPath = @"/mnt/dev/parent/someChild"; var purePathFactory = new PurePathFactory(); var parentPurePath = PurePath.Create(parentPath); var childPurePath = PurePath.Create(childPath); Assert.True(childPurePath > parentPurePath); }
public void Compare_WindowsFormat_DifferentDrives_ChildDirectory_IsGreaterThan_ParentDirectory_ShouldBeFalse() { var parentPath = @"C:\foo\bar"; var childPath = @"D:\foo\bar\other"; var purePathFactory = new PurePathFactory(); var parentPurePath = PurePath.Create(parentPath); var childPurePath = PurePath.Create(childPath); Assert.False(childPurePath > parentPurePath); }
public RepositoryTests() { this.Logger = NullLogger <RepositoryLoader> .Instance; this.FileSystem = new MockFileSystem(); this.RepositoryRootPath = PurePath.Create("/opt/stamp/repos/TestRepo"); this.RepositoryName = "TestRepo"; this.RepositoryDescription = "Test repository"; this.TemplateName = "TestTemplate"; this.TemplateVersion = SemVersion.Parse("1.0.0"); }
public StampConfig(ISystemEnvironment systemEnvironment, IFileSystem fileSystem) { this.SystemEnvironment = systemEnvironment; this.FileSystem = fileSystem; m_rootPath = new Lazy <IPurePath>(() => { var appDataPath = this.SystemEnvironment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create); return(PurePath.Create(appDataPath, StampConfigConstants.ConfigDirectoryName)); }); }
public void Compare_PosixFormat_ParentDirectory_IsLessThan_ChildDirectory_ShouldBeTrue() { var parentPath = @"/mnt/dev/parent"; var childPath = @"/mnt/dev/parent/someChild"; var parentPurePath = PurePath.Create(parentPath); var childPurePath = PurePath.Create(childPath); Assert.True(parentPurePath < childPurePath); }
public void Compare_WindowsFormat_ParentDirectory_IsLessThan_ChildDirectory_ShouldBeTrue() { var parentPath = @"C:\foo\bar"; var childPath = @"C:\foo\bar\other"; var parentPurePath = PurePath.Create(parentPath); var childPurePath = PurePath.Create(childPath); Assert.True(parentPurePath < childPurePath); }
public void ItGetsNullForMissingRepositoryPath() { const string repoName = "TestRepo"; var mockedFolderPath = PurePath.Create("/opt"); var environment = Mock.Of <ISystemEnvironment>( e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(), It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString() ); var fileSystem = new MockFileSystem(); IStampConfig stampConfig = new StampConfig(environment, fileSystem); stampConfig.GetRepositoryPath(repoName).Should().BeNull(); }
public void ItLoadStandardStampConfig() { var mockedFolderPath = PurePath.Create("/opt"); var expectedRootPath = mockedFolderPath.Join(StampConfigConstants.ConfigDirectoryName); var environment = Mock.Of <ISystemEnvironment>( e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(), It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString() ); var fileSystem = new MockFileSystem(); IStampConfig stampConfig = new StampConfig(environment, fileSystem); stampConfig.RootPath.Should().Be(expectedRootPath); }
public void ItGetsCreatesMissingRepositoryPath() { const string repoName = "TestRepo"; var mockedFolderPath = PurePath.Create("/opt"); var expectedRepoPath = mockedFolderPath.Join( StampConfigConstants.ConfigDirectoryName, StampConfigConstants.RepositoriesDirectoryName, repoName ); var environment = Mock.Of <ISystemEnvironment>( e => e.GetFolderPath(It.IsAny <Environment.SpecialFolder>(), It.IsAny <Environment.SpecialFolderOption>()) == mockedFolderPath.ToString() ); var fileSystem = new MockFileSystem(); IStampConfig stampConfig = new StampConfig(environment, fileSystem); stampConfig.GetRepositoryPath(repoName, createMissing: true).Should().Be(expectedRepoPath); }
//--------------------------------------- // 构造函数 //--------------------------------------- /// <summary>创建URL对象</summary> public Url(string url) { this.Dict = new FreeDictionary <string, string>(); if (url.IsEmpty()) { return; } try { // 分离路径和查询字符串部分 var queryString = ""; int n = url.IndexOf('?'); if (n == -1) { // 无问号但有等于号,认为该字符串就是querystring // 无问号且无等于号,认为该字符串就是purepath if (url.IndexOf('=') != -1) { queryString = url; } else { this.PurePath = url; } } else { this.PurePath = url.Substring(0, n); queryString = url.Substring(n + 1); } // 解析参数部分 Dict = queryString.ParseQueryDict(); // 分析前面的路径部分 int k = PurePath.LastIndexOf('.'); if (k != -1) { var ext = PurePath.Substring(k).ToLower(); this.FileExtesion = ""; if (!ext.Contains(@"/") && !ext.Contains(@"\")) { this.FileExtesion = ext; } } k = PurePath.LastIndexOf("/"); if (k != -1) { this.FileName = PurePath.Substring(k + 1); } // 解析协议、主机、端口、请求路径 Regex r = new Regex(@"^(?<proto>\w+)://(?<host>[^/:]+)(?<port>:\d+)(?<path>[\w\._/]+)", RegexOptions.Compiled); Match m = r.Match(PurePath); if (m.Success) { this.Protocol = m.Result("${proto}"); this.Host = m.Result("${host}"); this.Port = m.Result("${port}")?.TrimStart(':'); this.AbsolutePath = m.Result("${path}"); } else { this.AbsolutePath = PurePath.AddQueryString(this.QueryString); } } catch { } }
public void ItCanLoadLocalRepositoryWithTemplates() { var logger = NullLogger <RepositoryLoader> .Instance; var fileSystem = new MockFileSystem(); fileSystem.AddDirectory("/opt/stamp/repos/.local/templates/TestTemplate@1"); var stampConfig = Mock.Of <IStampConfig>(config => config.GetLocalRepositoryPath() == PurePath.Create("/opt/stamp/repos/.local") ); var expectedTemplateName = "TestTemplate"; var expectedTemplateVersion = SemVersion.Parse("1.0.0"); var templateLoader = Mock.Of <ITemplateLoader>(loader => loader.LoadFromTemplateDirectory(It.IsAny <IPurePath>()) == Mock.Of <ITemplate>(template => template.Name == expectedTemplateName && template.Version == expectedTemplateVersion ) ); var repositoryLoader = new RepositoryLoader(fileSystem, templateLoader, stampConfig, logger); var repository = repositoryLoader.LoadLocalRepository(); repository.Should().NotBeNull(); repository.Name.Should().Be(".local"); repository.Description.Should().Be("Local repository"); repository.Templates.Count.Should().Be(1); repository.Templates[0].Name.Should().Be(expectedTemplateName); repository.Templates[0].Version.Should().Be(expectedTemplateVersion); }