Exemplo n.º 1
0
 public void UnhandledException()
 {
     using (var directory = new DisposableDirectory(Temp))
     {
         bool restored = false;
         var resolver = new NuGetPackageResolverImpl(directory.Path, startInfo => { restored = true; throw new InvalidOperationException(); });
         Assert.Throws<InvalidOperationException>(() => resolver.ResolveNuGetPackage("A.B.C", "1.2"));
         Assert.True(restored);
     }
 }
Exemplo n.º 2
0
        public void ResolveReference()
        {
            var expectedProjectJson =
@"{
  ""dependencies"": {
    ""A.B.C"": ""1.2""
  },
  ""frameworks"": {
    ""net46"": {}
  }
}";
            var expectedConfig =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <packageRestore>
    <add key=""enabled"" value=""True"" />
    <add key=""automatic"" value=""False"" />
  </packageRestore>
  <packageSources/>
</configuration>";
            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.Runtime/4.0.0"": {
        ""runtime"": {
          ""ref/dotnet/_._"": {}
        }
      },
      ""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 =>
                    {
                        // Verify arguments.
                        var arguments = startInfo.Arguments.Split('"');
                        Assert.Equal(7, arguments.Length);
                        Assert.Equal("restore ", arguments[0]);
                        Assert.Equal("project.json", PathUtilities.GetFileName(arguments[1]));
                        Assert.Equal(" -ConfigFile ", arguments[2]);
                        Assert.Equal("nuget.config", PathUtilities.GetFileName(arguments[3]));
                        Assert.Equal(" -PackagesDirectory ", arguments[4]);
                        Assert.Equal(packagesDirectory, arguments[5]);
                        Assert.Equal("", arguments[6]);
                        // Verify project.json contents.
                        var projectJsonPath = arguments[1];
                        var actualProjectJson = File.ReadAllText(projectJsonPath);
                        Assert.Equal(expectedProjectJson, actualProjectJson);
                        // Verify config file contents.
                        var configPath = arguments[3];
                        var actualConfig = File.ReadAllText(configPath);
                        Assert.Equal(expectedConfig, actualConfig);
                        // Generate project.lock.json.
                        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")));
            }
        }
Exemplo n.º 3
0
 public void HandledException()
 {
     using (var directory = new DisposableDirectory(Temp))
     {
         bool restored = false;
         var resolver = new NuGetPackageResolverImpl(directory.Path, startInfo => { restored = true; throw new IOException(); });
         var actualPaths = resolver.ResolveNuGetPackage("A.B.C", "1.2");
         Assert.True(actualPaths.IsEmpty);
         Assert.True(restored);
     }
 }