public void ShouldThrowIfPathIsNull() { // Given DirectoryPath path = new DirectoryPath("assets"); // When TestDelegate test = () => path.CombineFile(null); // Then Assert.Throws<ArgumentNullException>(test); }
// Add all reference items to the assembly list private void AddReferencedAssemblies(DirectoryPath installedPath, PackageArchiveReader archiveReader) { FrameworkSpecificGroup referenceGroup = GetMostCompatibleGroup(_reducer, _currentFramework, archiveReader.GetReferenceItems().ToList()); if (referenceGroup != null) { foreach (FilePath itemPath in referenceGroup.Items .Select(x => new FilePath(x)) .Where(x => x.FileName.Extension == ".dll" || x.FileName.Extension == ".exe")) { FilePath assemblyPath = installedPath.CombineFile(itemPath); _assemblyLoader.Add(assemblyPath.FullPath); Trace.Verbose($"Added NuGet reference {assemblyPath} for loading"); } } }
public void GetCommitsForInputDocument() { // Given DirectoryPath inputPath = new DirectoryPath(TestContext.CurrentContext.TestDirectory).Parent.Parent.Parent.Parent; IExecutionContext context = Substitute.For<IExecutionContext>(); context.FileSystem.RootPath.Returns(new DirectoryPath("/")); context.FileSystem.InputPaths.Returns(x => new[] { inputPath }); context.GetDocument(Arg.Any<IEnumerable<KeyValuePair<string, object>>>()).Returns(getNewDocumentCallInfo => { IDocument newDocument = Substitute.For<IDocument>(); newDocument.GetEnumerator() .Returns(getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).GetEnumerator()); newDocument.Get<IReadOnlyDictionary<FilePath, string>>(Arg.Any<string>()) .Returns(getCallInfo => (IReadOnlyDictionary<FilePath, string>)getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).First(x => x.Key == getCallInfo.ArgAt<string>(0)).Value); return newDocument; }); IDocument document = Substitute.For<IDocument>(); document.Source.Returns(inputPath.CombineFile("Wyam.Core/IModule.cs")); // Use file that no longer exists so commit count is stable context.GetDocument(Arg.Any<IDocument>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>()).Returns(x => { IDocument newDocument = Substitute.For<IDocument>(); newDocument.GetEnumerator().Returns(x.ArgAt<IEnumerable<KeyValuePair<string, object>>>(1).GetEnumerator()); return newDocument; }); GitCommits gitCommits = new GitCommits().ForEachInputDocument(); // When List<IDocument> results = gitCommits.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then Assert.AreEqual(1, results.Count); List<IDocument> commits = ((IEnumerable<IDocument>) results[0].First(x => x.Key == GitKeys.Commits).Value).ToList(); Assert.AreEqual(6, commits.Count); Assert.AreEqual("6274fb76a0380760ab2dc83f90748b7d953aceb4", commits.Last().First(x => x.Key == GitKeys.Sha).Value); }
private FilePath DefaultWritePath(IMetadata metadata, DirectoryPath prefix) { IDocument namespaceDocument = metadata.Get<IDocument>(CodeAnalysisKeys.ContainingNamespace); FilePath writePath = null; // Namespaces output to the index page in a folder of their full name if (metadata.String(CodeAnalysisKeys.Kind) == SymbolKind.Namespace.ToString()) { // If this namespace does not have a containing namespace, it's the global namespace writePath = new FilePath(namespaceDocument == null ? "global/index.html" : $"{metadata[CodeAnalysisKeys.DisplayName]}/index.html"); } // Types output to the index page in a folder of their SymbolId under the folder for their namespace else if (metadata.String(CodeAnalysisKeys.Kind) == SymbolKind.NamedType.ToString()) { // If containing namespace is null (shouldn't happen) or our namespace is global, output to root folder writePath = new FilePath(namespaceDocument?[CodeAnalysisKeys.ContainingNamespace] == null ? $"global/{metadata[CodeAnalysisKeys.SymbolId]}/index.html" : $"{namespaceDocument[CodeAnalysisKeys.DisplayName]}/{metadata[CodeAnalysisKeys.SymbolId]}/index.html"); } else { // Members output to a page equal to their SymbolId under the folder for their type IDocument containingTypeDocument = metadata.Get<IDocument>(CodeAnalysisKeys.ContainingType, null); writePath = new FilePath(containingTypeDocument?.FilePath(Keys.WritePath).FullPath.Replace("index.html", metadata.String(CodeAnalysisKeys.SymbolId) + ".html")); } // Add the prefix if (prefix != null) { writePath = prefix.CombineFile(writePath); } return writePath; }
public void CombiningWithAbsolutePathKeepsSecondProvider(string first, string second) { // Given DirectoryPath path = new DirectoryPath(new Uri("first:///"), first); // When FilePath result = path.CombineFile(new FilePath(new Uri("second:///"), second)); // Then Assert.AreEqual(new Uri("second:///"), result.FileProvider); }
public void CombiningWithRelativePathKeepsFirstProvider(string first, string second) { // Given DirectoryPath path = new DirectoryPath(new Uri("foo:///"), first); // When FilePath result = path.CombineFile(new FilePath(second)); // Then Assert.AreEqual(new Uri("foo:///"), result.FileProvider); }
public void ShouldCombinePaths(string first, string second, string expected) { // Given DirectoryPath path = new DirectoryPath(first); // When FilePath result = path.CombineFile(new FilePath(second)); // Then Assert.AreEqual(expected, result.FullPath); }
private int Run(string[] args) { AssemblyInformationalVersionAttribute versionAttribute = Attribute.GetCustomAttribute(typeof(Program).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; Console.WriteLine("Wyam version {0}", versionAttribute == null ? "unknown" : versionAttribute.InformationalVersion); // Parse the command line bool hasParseArgsErrors; if (!ParseArgs(args, out hasParseArgsErrors)) { return hasParseArgsErrors ? (int)ExitCode.CommandLineError : (int)ExitCode.Normal; } // It's not a serious console app unless there's some ASCII art OutputLogo(); // Fix the root folder and other files DirectoryPath currentDirectory = Environment.CurrentDirectory; _rootPath = _rootPath == null ? currentDirectory : currentDirectory.Combine(_rootPath); _logFilePath = _logFilePath == null ? null : _rootPath.CombineFile(_logFilePath); _configFilePath = _rootPath.CombineFile(_configFilePath ?? "config.wyam"); // Get the engine Engine engine = GetEngine(); if (engine == null) { return (int)ExitCode.CommandLineError; } // Pause if (_pause) { Trace.Information("Pause requested, hit any key to continue"); Console.ReadKey(); } // Configure and execute if (!Configure(engine)) { return (int)ExitCode.ConfigurationError; } if (_verifyConfig) { Trace.Information("No errors. Exiting."); return (int)ExitCode.Normal; } Console.WriteLine($"Root path:{Environment.NewLine} {engine.FileSystem.RootPath}"); Console.WriteLine($"Input path(s):{Environment.NewLine} {string.Join(Environment.NewLine + " ", engine.FileSystem.InputPaths)}"); Console.WriteLine($"Output path:{Environment.NewLine} {engine.FileSystem.OutputPath}"); if (!Execute(engine)) { return (int)ExitCode.ExecutionError; } bool messagePump = false; // Start the preview server IDisposable previewServer = null; if (_preview) { messagePump = true; try { var rootPath = _previewRoot == null ? engine.FileSystem.GetOutputDirectory().Path.FullPath : _previewRoot.FullPath; Trace.Information("Preview server listening on port {0} and serving from path {1}", _previewPort, rootPath); previewServer = Preview(engine, rootPath); } catch (Exception ex) { Trace.Critical("Error while running preview server: {0}", ex.Message); } } // Start the watchers IDisposable inputFolderWatcher = null; IDisposable configFileWatcher = null; if (_watch) { messagePump = true; Trace.Information("Watching paths(s) {0}", string.Join(", ", engine.FileSystem.InputPaths)); inputFolderWatcher = new ActionFileSystemWatcher(engine.FileSystem.GetOutputDirectory().Path, engine.FileSystem.GetInputDirectories().Select(x => x.Path), true, "*.*", path => { _changedFiles.Enqueue(path); _messageEvent.Set(); }); if (_configFilePath != null) { Trace.Information("Watching configuration file {0}", _configFilePath); Engine closureEngine = engine; configFileWatcher = new ActionFileSystemWatcher(engine.FileSystem.GetOutputDirectory().Path, new[] { _configFilePath.GetDirectory() }, false, _configFilePath.GetFilename().FullPath, path => { if (closureEngine.FileSystem.PathComparer.Equals((FilePath)path, _configFilePath)) { _newEngine.Set(); _messageEvent.Set(); } }); } } // Start the message pump if an async process is running ExitCode exitCode = ExitCode.Normal; if (messagePump) { // Start the key listening thread Trace.Information("Hit any key to exit"); var thread = new Thread(() => { Console.ReadKey(); _exit.Set(); _messageEvent.Set(); }) { IsBackground = true }; thread.Start(); // Wait for activity while (true) { _messageEvent.WaitOne(); // Blocks the current thread until a signal if (_exit) { break; } // See if we need a new engine if (_newEngine) { // Get a new engine Trace.Information("Configuration file {0} has changed, re-running", _configFilePath); engine.Dispose(); engine = GetEngine(); // Configure and execute if (!Configure(engine)) { exitCode = ExitCode.ConfigurationError; break; } Console.WriteLine($"Root path:{Environment.NewLine} {engine.FileSystem.RootPath}"); Console.WriteLine($"Input path(s):{Environment.NewLine} {string.Join(Environment.NewLine + " ", engine.FileSystem.InputPaths)}"); Console.WriteLine($"Root path:{Environment.NewLine} {engine.FileSystem.OutputPath}"); if (!Execute(engine)) { exitCode = ExitCode.ExecutionError; break; } // Clear the changed files since we just re-ran string changedFile; while (_changedFiles.TryDequeue(out changedFile)) { } _newEngine.Unset(); } else { // Execute if files have changed HashSet<string> changedFiles = new HashSet<string>(); string changedFile; while (_changedFiles.TryDequeue(out changedFile)) { if (changedFiles.Add(changedFile)) { Trace.Verbose("{0} has changed", changedFile); } } if (changedFiles.Count > 0) { Trace.Information("{0} files have changed, re-executing", changedFiles.Count); if (!Execute(engine)) { exitCode = ExitCode.ExecutionError; break; } } } // Check one more time for exit if (_exit) { break; } Trace.Information("Hit any key to exit"); _messageEvent.Reset(); } // Shutdown Trace.Information("Shutting down"); engine.Dispose(); inputFolderWatcher?.Dispose(); configFileWatcher?.Dispose(); previewServer?.Dispose(); } return (int)exitCode; }
public void GetCommittersForInputDocument() { // Given DirectoryPath inputPath = new DirectoryPath(TestContext.CurrentContext.TestDirectory).Parent.Parent.Parent.Parent; IExecutionContext context = Substitute.For<IExecutionContext>(); context.FileSystem.RootPath.Returns(new DirectoryPath("/")); context.FileSystem.InputPaths.Returns(x => new[] { inputPath }); context.GetDocument(Arg.Any<IEnumerable<KeyValuePair<string, object>>>()).Returns(getNewDocumentCallInfo => { IDocument newDocument = Substitute.For<IDocument>(); newDocument.GetEnumerator() .Returns(getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).GetEnumerator()); newDocument.String(Arg.Any<string>()) .Returns(stringCallInfo => (string)getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).First(x => x.Key == stringCallInfo.ArgAt<string>(0)).Value); newDocument.Get<IReadOnlyDictionary<FilePath, string>>(Arg.Any<string>()) .Returns(getCallInfo => (IReadOnlyDictionary<FilePath, string>)getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).First(x => x.Key == getCallInfo.ArgAt<string>(0)).Value); newDocument.Get<IReadOnlyList<IDocument>>(Arg.Any<string>()) .Returns(getCallInfo => (IReadOnlyList<IDocument>)getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).First(x => x.Key == getCallInfo.ArgAt<string>(0)).Value); newDocument[Arg.Any<string>()] .Returns(getCallInfo => getNewDocumentCallInfo.ArgAt<IEnumerable<KeyValuePair<string, object>>>(0).First(x => x.Key == getCallInfo.ArgAt<string>(0)).Value); return newDocument; }); IDocument document = Substitute.For<IDocument>(); document.Source.Returns(inputPath.CombineFile("Wyam.Core/IModule.cs")); // Use file that no longer exists so commit count is stable context.GetDocument(Arg.Any<IDocument>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>()).Returns(x => { IDocument newDocument = Substitute.For<IDocument>(); newDocument.GetEnumerator().Returns(x.ArgAt<IEnumerable<KeyValuePair<string, object>>>(1).GetEnumerator()); return newDocument; }); GitContributors gitContributors = new GitContributors().ForEachInputDocument(); // When List<IDocument> results = gitContributors.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then Assert.AreEqual(1, results.Count); List<IDocument> contributors = ((IEnumerable<IDocument>)results[0].First(x => x.Key == GitKeys.Contributors).Value).ToList(); Dictionary<string, object> contributor = contributors .Single(x => x.String(GitKeys.ContributorEmail) == "*****@*****.**" && x.String(GitKeys.ContributorName) == "Dave Glick") .ToDictionary(x => x.Key, x => x.Value); List<Dictionary<string, object>> commits = ((IEnumerable<IDocument>)contributor[GitKeys.Commits]) .Select(x => x.ToDictionary(y => y.Key, y => y.Value)).ToList(); Assert.That(commits.Count, Is.LessThan(10)); Assert.IsTrue(commits.All(x => (string)x[GitKeys.CommitterEmail] == "*****@*****.**" || (string)x[GitKeys.AuthorEmail] == "*****@*****.**")); }