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); }
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); }