< Summary

Class:Mklinker.WindowsLinker
Assembly:Mklinker
File(s):/home/travis/build/rubenchristoffer/Mklinker/Mklinker/WindowsLinker.cs
Covered lines:12
Uncovered lines:36
Coverable lines:48
Total lines:81
Line coverage:25% (12 of 48)
Covered branches:8
Total branches:18
Branch coverage:44.4% (8 of 18)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)10100%100%
GetProcessInfo(...)100%100%
GetLinkTypeArgument(...)80100%100%
CreateLink(...)1000%0%

File(s)

/home/travis/build/rubenchristoffer/Mklinker/Mklinker/WindowsLinker.cs

#LineLine coverage
 1using System;
 2using System.Diagnostics;
 3using System.IO.Abstractions;
 4using Mklinker.Abstractions;
 5using LinkType = Mklinker.ConfigLink.LinkType;
 6
 7namespace Mklinker {
 8
 9  class WindowsLinker : ILinker {
 10
 11    readonly IConsole console;
 12    readonly IFileSystem fileSystem;
 13    readonly IProcess process;
 14
 015    public bool verbose { get; set; }
 16
 1017    public WindowsLinker (IConsole console, IFileSystem fileSystem, IProcess process) {
 518      this.console = console;
 519      this.fileSystem = fileSystem;
 520      this.process = process;
 521    }
 22
 023    internal ProcessStartInfo GetProcessInfo(IFileSystem fileSystem, string resolvedSourcePath, string resolvedTargetPat
 024      return new ProcessStartInfo {
 025        FileName = "cmd.exe",
 026
 027        Arguments = string.Format("/c mklink {0} \"{1}\" \"{2}\"",
 028        GetLinkTypeArgument(fileSystem, linkType, resolvedSourcePath),
 029        resolvedTargetPath,
 030        resolvedSourcePath),
 031
 032        RedirectStandardOutput = true,
 033        RedirectStandardError = true,
 034        UseShellExecute = false
 035      };
 036    }
 37
 538    internal string GetLinkTypeArgument(IFileSystem fileSystem, LinkType linkType, string resolvedSourcePath) {
 739      if (fileSystem.File.Exists(resolvedSourcePath)) {
 240        return linkType == LinkType.Hard ? "/H" : "";
 541      } else if (fileSystem.Directory.Exists(resolvedSourcePath)) {
 242        return linkType == LinkType.Symbolic ? "/D" : "/J";
 43      }
 44
 145      return "";
 546    }
 47
 048    public bool CreateLink(string resolvedSourcePath, string resolvedTargetPath, ConfigLink.LinkType linkType) {
 049      if (!fileSystem.File.Exists(resolvedSourcePath) && !fileSystem.Directory.Exists(resolvedSourcePath)) {
 050        console.WriteLine("Path '{0}' does not exist!", resolvedSourcePath);
 51
 052        return false;
 53      }
 54
 055      ProcessStartInfo processStartInfo = GetProcessInfo(fileSystem, resolvedSourcePath, resolvedTargetPath, linkType);
 56
 057      if (verbose) {
 058        console.WriteLine ($"$ {processStartInfo.FileName} {processStartInfo.Arguments}");
 059      }
 60
 061      IProcess mklinkProcess = process.Start(processStartInfo);
 062      bool success = false;
 63
 064      while (!mklinkProcess.StandardOutput.EndOfStream) {
 065        string output = mklinkProcess.StandardOutput.ReadLine();
 066        success = output.ToLower().Contains("created");
 67
 068        console.WriteLine(output);
 069      }
 70
 071      while (!mklinkProcess.StandardError.EndOfStream) {
 072        success = false;
 073        console.WriteLine(mklinkProcess.StandardError.ReadLine());
 074      }
 75
 076      return success;
 077    }
 78
 79  }
 80
 81}