public void ShouldThrowExceptionOnRestoreError() { using (var projectFolder = new DisposableFolder()) { var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); var projectFile = new ProjectFile(); projectFile.PackageReferences.Add(ValidPackageReferenceA); projectFile.PackageReferences.Add(InvalidPackageReferenceA); projectFile.PackageReferences.Add(ValidPackageReferenceB); projectFile.Save(pathToProjectFile); var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); var logFactory = TestOutputHelper.CreateTestLogFactory(); var commandRunner = new CommandRunner(logFactory); var restorer = new DotnetRestorer(commandRunner, logFactory); var exception = Assert.Throws <Exception>(() => { restorer.Restore(projectFileInfo, Array.Empty <string>()); }); Assert.Contains("NU1101", exception.Message); // unable to find package } }
public void ShouldRestoreProjectPackageReferences() { using (var projectFolder = new DisposableFolder()) { var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); var projectFile = new ProjectFile(); projectFile.PackageReferences.Add(ValidPackageReferenceA); projectFile.PackageReferences.Add(ValidPackageReferenceB); projectFile.Save(pathToProjectFile); var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); var logFactory = TestOutputHelper.CreateTestLogFactory(); var commandRunner = new CommandRunner(logFactory); var restorer = new DotnetRestorer(commandRunner, logFactory); var pathToProjectObjDirectory = Path.Combine(projectFolder.Path, "obj"); Assert.False(Directory.Exists(pathToProjectObjDirectory)); restorer.Restore(projectFileInfo, Array.Empty <string>()); Assert.True(Directory.Exists(pathToProjectObjDirectory)); } }