|
10 | 10 | using Microsoft.DotNet.DarcLib.Helpers; |
11 | 11 | using Microsoft.DotNet.DarcLib.Models.Darc; |
12 | 12 | using Microsoft.Extensions.Logging.Abstractions; |
13 | | -using Microsoft.VisualStudio.Services.Profile; |
14 | 13 | using Moq; |
15 | 14 | using NUnit.Framework; |
16 | 15 |
|
@@ -235,4 +234,131 @@ public async Task RemoveDependencyShouldNotThrowWhenDependencyDoesNotExist() |
235 | 234 | Func<Task> act = async () => await manager.RemoveDependencyAsync(dependency.Name, string.Empty, string.Empty); |
236 | 235 | await act.Should().NotThrowAsync<DependencyException>(); |
237 | 236 | } |
| 237 | + |
| 238 | + [Test] |
| 239 | + public async Task AddDependencyShouldMatchAlternatePropNames() |
| 240 | + { |
| 241 | + string versionDetails = |
| 242 | + """ |
| 243 | + <?xml version="1.0" encoding="utf-8"?> |
| 244 | + <Dependencies> |
| 245 | + <ProductDependencies> |
| 246 | + </ProductDependencies> |
| 247 | + <ToolsetDependencies> |
| 248 | + <Dependency Name="Microsoft.DotNet.Build.Tasks.Packaging" Version="10.0.0-beta.25217.1"> |
| 249 | + <Uri>https://github.com/dotnet/arcade</Uri> |
| 250 | + <Sha>76dd1b4eb3b15881da350de93805ea6ab936364c</Sha> |
| 251 | + </Dependency> |
| 252 | + <Dependency Name="Microsoft.DotNet.Build.Tasks.Installers" Version="10.0.0-beta.25217.1"> |
| 253 | + <Uri>https://github.com/dotnet/arcade</Uri> |
| 254 | + <Sha>76dd1b4eb3b15881da350de93805ea6ab936364c</Sha> |
| 255 | + </Dependency> |
| 256 | + </ToolsetDependencies> |
| 257 | + </Dependencies> |
| 258 | + """; |
| 259 | + |
| 260 | + string versionProps = |
| 261 | + """ |
| 262 | + <?xml version="1.0" encoding="utf-8"?> |
| 263 | + <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 264 | + <PropertyGroup> |
| 265 | + <MicrosoftDotNetBuildTasksPackagingVersion>10.0.0-beta.25217.1</MicrosoftDotNetBuildTasksPackagingVersion> |
| 266 | + <MicrosoftDotNetBuildTasksInstallersPackageVersion>10.0.0-beta.25217.1</MicrosoftDotNetBuildTasksInstallersPackageVersion> |
| 267 | + </PropertyGroup> |
| 268 | + </Project> |
| 269 | + """; |
| 270 | + |
| 271 | + Mock<IGitRepo> repo = new(); |
| 272 | + Mock<IGitRepoFactory> repoFactory = new(); |
| 273 | + |
| 274 | + repo.Setup(r => r.GetFileContentsAsync(VersionFiles.VersionDetailsXml, It.IsAny<string>(), It.IsAny<string>())) |
| 275 | + .ReturnsAsync(() => versionDetails); |
| 276 | + repo.Setup(r => r.GetFileContentsAsync(VersionFiles.VersionProps, It.IsAny<string>(), It.IsAny<string>())) |
| 277 | + .ReturnsAsync(() => versionProps); |
| 278 | + repoFactory |
| 279 | + .Setup(repoFactory => repoFactory.CreateClient(It.IsAny<string>())) |
| 280 | + .Returns(repo.Object); |
| 281 | + |
| 282 | + repo.Setup(r => r.CommitFilesAsync( |
| 283 | + It.IsAny<List<GitFile>>(), |
| 284 | + It.IsAny<string>(), |
| 285 | + It.IsAny<string>(), |
| 286 | + It.IsAny<string>())) |
| 287 | + .Callback<List<GitFile>, string, string, string>((files, repoUri, branch, commitMessage) => |
| 288 | + { |
| 289 | + foreach(var file in files) |
| 290 | + { |
| 291 | + if (file.FilePath == VersionFiles.VersionDetailsXml) |
| 292 | + { |
| 293 | + versionDetails = file.Content; |
| 294 | + } |
| 295 | + else if (file.FilePath == VersionFiles.VersionProps) |
| 296 | + { |
| 297 | + versionProps = file.Content; |
| 298 | + } |
| 299 | + } |
| 300 | + }); |
| 301 | + |
| 302 | + DependencyFileManager manager = new( |
| 303 | + repoFactory.Object, |
| 304 | + new VersionDetailsParser(), |
| 305 | + NullLogger.Instance); |
| 306 | + |
| 307 | + await manager.AddDependencyAsync( |
| 308 | + new DependencyDetail() |
| 309 | + { |
| 310 | + Name = "Microsoft.DotNet.Build.Tasks.Packaging", |
| 311 | + Version = "10.0.0-beta.22222.3", |
| 312 | + Commit = "abc", |
| 313 | + Type = DependencyType.Toolset, |
| 314 | + RepoUri = "https://github.com/dotnet/arcade", |
| 315 | + }, |
| 316 | + string.Empty, |
| 317 | + string.Empty); |
| 318 | + |
| 319 | + await manager.AddDependencyAsync( |
| 320 | + new DependencyDetail() |
| 321 | + { |
| 322 | + Name = "Microsoft.DotNet.Build.Tasks.Installers", |
| 323 | + Version = "10.0.0-beta.33333.1", |
| 324 | + Commit = "def", |
| 325 | + Type = DependencyType.Toolset, |
| 326 | + RepoUri = "https://github.com/dotnet/arcade", |
| 327 | + }, |
| 328 | + string.Empty, |
| 329 | + string.Empty); |
| 330 | + |
| 331 | + string expectedVersionDetails = |
| 332 | + """ |
| 333 | + <?xml version="1.0" encoding="utf-8"?> |
| 334 | + <Dependencies> |
| 335 | + <ProductDependencies> |
| 336 | + </ProductDependencies> |
| 337 | + <ToolsetDependencies> |
| 338 | + <Dependency Name="Microsoft.DotNet.Build.Tasks.Packaging" Version="10.0.0-beta.22222.3"> |
| 339 | + <Uri>https://github.com/dotnet/arcade</Uri> |
| 340 | + <Sha>abc</Sha> |
| 341 | + </Dependency> |
| 342 | + <Dependency Name="Microsoft.DotNet.Build.Tasks.Installers" Version="10.0.0-beta.33333.1"> |
| 343 | + <Uri>https://github.com/dotnet/arcade</Uri> |
| 344 | + <Sha>def</Sha> |
| 345 | + </Dependency> |
| 346 | + </ToolsetDependencies> |
| 347 | + </Dependencies> |
| 348 | + """; |
| 349 | + |
| 350 | + string expectedVersionProps = |
| 351 | + """ |
| 352 | + <?xml version="1.0" encoding="utf-8"?> |
| 353 | + <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 354 | + <PropertyGroup> |
| 355 | + <MicrosoftDotNetBuildTasksPackagingVersion>10.0.0-beta.22222.3</MicrosoftDotNetBuildTasksPackagingVersion> |
| 356 | + <MicrosoftDotNetBuildTasksInstallersPackageVersion>10.0.0-beta.33333.1</MicrosoftDotNetBuildTasksInstallersPackageVersion> |
| 357 | + </PropertyGroup> |
| 358 | + </Project> |
| 359 | + """; |
| 360 | + |
| 361 | + versionDetails.Replace("\r\n", "\n").TrimEnd().Should().Be(expectedVersionDetails.Replace("\r\n", "\n").TrimEnd()); |
| 362 | + versionProps.Replace("\r\n", "\n").TrimEnd().Should().Be(expectedVersionProps.Replace("\r\n", "\n").TrimEnd()); |
| 363 | + } |
238 | 364 | } |
0 commit comments