Skip to content

Commit f45e5c8

Browse files
committed
fix build
1 parent 62a09ed commit f45e5c8

6 files changed

Lines changed: 45 additions & 74 deletions

File tree

test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Linq;
88
using System.Threading.Tasks;
99
using FluentAssertions;
10-
using Microsoft.Extensions.CommandLineUtils;
10+
using System.CommandLine;
1111
using Microsoft.Internal.NuGet.Testing.SignedPackages.ChildProcess;
1212
using NuGet.CommandLine.XPlat;
1313
using NuGet.Common;
@@ -100,7 +100,7 @@ public async Task AddPkg_FileBasedApp()
100100

101101
// Generate DG file.
102102
var dgFile = Path.Join(tempDir, "dg.json");
103-
_fixture.RunDotnetExpectSuccess(fbaDir, $"build app.cs -t:GenerateRestoreGraphFile -p:RestoreGraphOutputPath={ArgumentEscaper.EscapeAndConcatenate([dgFile])}", testOutputHelper: _testOutputHelper);
103+
_fixture.RunDotnetExpectSuccess(fbaDir, $"build app.cs -t:GenerateRestoreGraphFile -p:RestoreGraphOutputPath=\"{dgFile}\"", testOutputHelper: _testOutputHelper);
104104

105105
// Get project content.
106106
var virtualProject = _fixture.GetFileBasedAppVirtualProject(appFile, _testOutputHelper);
@@ -113,35 +113,21 @@ public async Task AddPkg_FileBasedApp()
113113
await SimpleTestPackageUtility.CreateFolderFeedV3Async(pathContext.PackageSource, PackageSaveMode.Defaultv3, packageX);
114114

115115
// Add the package.
116-
using var outWriter = new StringWriter();
117-
using var errorWriter = new StringWriter();
118-
var testApp = new CommandLineApplication
119-
{
120-
Out = outWriter,
121-
Error = errorWriter,
122-
};
116+
var testApp = new RootCommand();
123117
AddPackageReferenceCommand.Register(
124118
testApp,
125-
() => new TestLogger(_testOutputHelper),
119+
() => new TestCommandOutputLogger(_testOutputHelper),
126120
() => new AddPackageReferenceCommandRunner(),
127121
() => builder);
128-
int result = testApp.Execute([
122+
int result = testApp.Parse([
129123
"add",
130124
"--project", appFile,
131125
"--package", "packageX",
132126
"--dg-file", dgFile,
133-
]);
134-
135-
var output = outWriter.ToString();
136-
var error = errorWriter.ToString();
137-
138-
_testOutputHelper.WriteLine(output);
139-
_testOutputHelper.WriteLine(error);
127+
]).Invoke();
140128

141129
Assert.Equal(0, result);
142130

143-
Assert.Empty(error);
144-
145131
var modifiedProjectContent = builder.ModifiedContent;
146132
_testOutputHelper.WriteLine("after:\n" + modifiedProjectContent);
147133
Assert.Contains("""<PackageReference Include="packageX" Version="1.0.0" />""", modifiedProjectContent);

test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using System.Threading.Tasks;
1313
using System.Xml.Linq;
1414
using FluentAssertions;
15-
using Microsoft.Extensions.CommandLineUtils;
15+
using System.CommandLine;
1616
using Microsoft.Internal.NuGet.Testing.SignedPackages.ChildProcess;
1717
using Newtonsoft.Json.Linq;
1818
using NuGet.CommandLine.XPlat;
@@ -108,37 +108,37 @@ public async Task DotnetListPackage_FileBasedApp()
108108

109109
// List packages.
110110
using var outWriter = new StringWriter();
111-
using var errorWriter = new StringWriter();
112-
var testApp = new CommandLineApplication
111+
var savedOut = Console.Out;
112+
Console.SetOut(outWriter);
113+
try
113114
{
114-
Out = outWriter,
115-
Error = errorWriter,
116-
};
117-
var logger = new TestLogger(_testOutputHelper);
118-
var msbuild = new MSBuildAPIUtility(logger, builder);
119-
ListPackageCommand.Register(
120-
testApp,
121-
() => logger,
122-
(_) => { },
123-
() => new ListPackageCommandRunner(msbuild));
124-
int result = testApp.Execute([
125-
"list", appFile,
126-
"--source", pathContext.PackageSource,
127-
"--format", "json",
128-
]);
129-
130-
var output = outWriter.ToString();
131-
var error = errorWriter.ToString();
132-
133-
_testOutputHelper.WriteLine(output);
134-
_testOutputHelper.WriteLine(error);
135-
136-
Assert.Equal(0, result);
137-
138-
Assert.Empty(error);
139-
140-
Assert.Contains("packageX", output);
141-
Assert.Contains("1.0.0", output);
115+
var testApp = new RootCommand();
116+
var logger = new TestCommandOutputLogger(_testOutputHelper);
117+
var msbuild = new MSBuildAPIUtility(logger, builder);
118+
ListPackageCommand.Register(
119+
testApp,
120+
() => logger,
121+
(_) => { },
122+
() => new ListPackageCommandRunner(msbuild));
123+
int result = testApp.Parse([
124+
"list", appFile,
125+
"--source", pathContext.PackageSource,
126+
"--format", "json",
127+
]).Invoke();
128+
129+
var output = outWriter.ToString();
130+
131+
_testOutputHelper.WriteLine(output);
132+
133+
Assert.Equal(0, result);
134+
135+
Assert.Contains("packageX", output);
136+
Assert.Contains("1.0.0", output);
137+
}
138+
finally
139+
{
140+
Console.SetOut(savedOut);
141+
}
142142

143143
Assert.Null(builder.ModifiedContent);
144144
}

test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRemovePackageTests.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
using System.IO;
55
using System.Threading.Tasks;
6-
using Microsoft.Extensions.CommandLineUtils;
6+
using System.CommandLine;
77
using NuGet.CommandLine.XPlat;
8-
using NuGet.Test.Utility;
98
using NuGet.XPlat.FuncTest;
109
using Xunit;
1110
using Xunit.Abstractions;
@@ -41,34 +40,20 @@ public async Task RemovePkg_FileBasedApp()
4140
using var builder = new TestVirtualProjectBuilder(virtualProject);
4241

4342
// Remove the package.
44-
using var outWriter = new StringWriter();
45-
using var errorWriter = new StringWriter();
46-
var testApp = new CommandLineApplication
47-
{
48-
Out = outWriter,
49-
Error = errorWriter,
50-
};
43+
var testApp = new RootCommand();
5144
RemovePackageReferenceCommand.Register(
5245
testApp,
53-
() => new TestLogger(_testOutputHelper),
46+
() => new TestCommandOutputLogger(_testOutputHelper),
5447
() => new RemovePackageReferenceCommandRunner(),
5548
() => builder);
56-
int result = testApp.Execute([
49+
int result = testApp.Parse([
5750
"remove",
5851
"--project", appFile,
5952
"--package", "packageX",
60-
]);
61-
62-
var output = outWriter.ToString();
63-
var error = errorWriter.ToString();
64-
65-
_testOutputHelper.WriteLine(output);
66-
_testOutputHelper.WriteLine(error);
53+
]).Invoke();
6754

6855
Assert.Equal(0, result);
6956

70-
Assert.Empty(error);
71-
7257
var modifiedProjectContent = builder.ModifiedContent;
7358
_testOutputHelper.WriteLine("after:\n" + modifiedProjectContent);
7459
Assert.DoesNotContain("PackageReference", modifiedProjectContent);

test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatTrustTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ private void TrustCommandArgs(Action<RootCommand, Func<LogLevel>> verify)
141141
verify(testApp, () => logLevel);
142142
}
143143
}
144-
}
144+
}

test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatVerifyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ private void VerifyCommandArgs(Action<Mock<IVerifyCommandRunner>, RootCommand, F
9090
verify(mockCommandRunner, testApp, () => logLevel);
9191
}
9292
}
93-
}
93+
}

test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XplatSignTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,4 @@ private void SignCommandArgs(Action<Mock<ISignCommandRunner>, RootCommand, Func<
540540
verify(mockCommandRunner, testApp, () => logLevel, () => parsedArgs, logger);
541541
}
542542
}
543-
}
543+
}

0 commit comments

Comments
 (0)