Exemple #1
0
 public void UnhandledException()
 {
     using (var directory = new DisposableDirectory(Temp))
     {
         var resolver = new NuGetPackageResolverImpl(directory.Path, startInfo => { throw new InvalidOperationException(); });
         Assert.Throws <InvalidOperationException>(() => resolver.ResolveNuGetPackage("A.B.C/1.2"));
     }
 }
Exemple #2
0
 public void HandledException()
 {
     using (var directory = new DisposableDirectory(Temp))
     {
         var resolver    = new NuGetPackageResolverImpl(directory.Path, startInfo => { throw new IOException(); });
         var actualPaths = resolver.ResolveNuGetPackage("A.B.C/1.2");
         Assert.True(actualPaths.IsDefault);
     }
 }
Exemple #3
0
        public void ResolveReference()
        {
            var expectedProjectJson =
                @"{
  ""dependencies"": {
    ""A.B.C"": ""1.2""
  },
  ""frameworks"": {
    ""net46"": {}
  }
}";
            var actualProjectLockJson =
                @"{
  ""locked"": false,
  ""version"": 1,
  ""targets"": {
    "".NETFramework,Version=v4.5"": { },
    "".NETFramework,Version=v4.6"": {
      ""System.Collections/4.0.10"": {
        ""dependencies"": {
          ""System.Runtime"": """"
        },
        ""compile"": {
          ""ref/dotnet/System.Runtime.dll"": {}
        },
        ""runtime"": {
          ""ref/dotnet/System.Collections.dll"": {}
        }
      },
      ""System.Diagnostics.Debug/4.0.10"": {
        ""dependencies"": {
          ""System.Runtime"": """"
        },
      },
      ""System.IO/4.0.10"": {
        ""dependencies"": {},
        ""runtime"": {
          ""ref/dotnet/System.Runtime.dll"": {},
          ""ref/dotnet/System.IO.dll"": {}
        }
      }
    }
  }
}";

            using (var directory = new DisposableDirectory(Temp))
            {
                var packagesDirectory = directory.Path;
                var resolver          = new NuGetPackageResolverImpl(
                    packagesDirectory,
                    startInfo =>
                {
                    var arguments = startInfo.Arguments.Split('"');
                    Assert.Equal(5, arguments.Length);
                    Assert.Equal("restore ", arguments[0]);
                    Assert.Equal("project.json", PathUtilities.GetFileName(arguments[1]));
                    Assert.Equal(" -PackagesDirectory ", arguments[2]);
                    Assert.Equal(packagesDirectory, arguments[3]);
                    Assert.Equal("", arguments[4]);
                    var projectJsonPath   = arguments[1];
                    var actualProjectJson = File.ReadAllText(projectJsonPath);
                    Assert.Equal(expectedProjectJson, actualProjectJson);
                    var projectLockJsonPath = PathUtilities.CombineAbsoluteAndRelativePaths(PathUtilities.GetDirectoryName(projectJsonPath), "project.lock.json");
                    using (var writer = new StreamWriter(projectLockJsonPath))
                    {
                        writer.Write(actualProjectLockJson);
                    }
                });
                var actualPaths = resolver.ResolveNuGetPackage("A.B.C/1.2");
                AssertEx.SetEqual(actualPaths,
                                  PathUtilities.CombineAbsoluteAndRelativePaths(packagesDirectory, PathUtilities.CombinePossiblyRelativeAndRelativePaths("System.Collections/4.0.10", "ref/dotnet/System.Collections.dll")),
                                  PathUtilities.CombineAbsoluteAndRelativePaths(packagesDirectory, PathUtilities.CombinePossiblyRelativeAndRelativePaths("System.IO/4.0.10", "ref/dotnet/System.Runtime.dll")),
                                  PathUtilities.CombineAbsoluteAndRelativePaths(packagesDirectory, PathUtilities.CombinePossiblyRelativeAndRelativePaths("System.IO/4.0.10", "ref/dotnet/System.IO.dll")));
            }
        }