|
13 | 13 | using Xunit.Abstractions; |
14 | 14 | using Microsoft.NET.TestFramework.ProjectConstruction; |
15 | 15 | using System.Xml.Linq; |
| 16 | +using Xunit.Sdk; |
16 | 17 |
|
17 | 18 | namespace Microsoft.NET.Build.Tests |
18 | 19 | { |
@@ -362,5 +363,118 @@ BuildCommand BuildProject(string buildNumber) |
362 | 363 | return command; |
363 | 364 | } |
364 | 365 | } |
| 366 | + |
| 367 | + [Fact] |
| 368 | + public void It_includes_internals_visible_to() |
| 369 | + { |
| 370 | + var testAsset = _testAssetsManager |
| 371 | + .CopyTestAsset("HelloWorld") |
| 372 | + .WithSource() |
| 373 | + .WithTargetFramework("netstandard2.0") |
| 374 | + .WithProjectChanges((path, project) => |
| 375 | + { |
| 376 | + var ns = project.Root.Name.Namespace; |
| 377 | + |
| 378 | + project.Root.Add( |
| 379 | + new XElement(ns + "ItemGroup", |
| 380 | + new XElement(ns + "InternalsVisibleTo", |
| 381 | + new XAttribute("Include", "Tests")))); |
| 382 | + }); |
| 383 | + |
| 384 | + new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass(); |
| 385 | + |
| 386 | + var buildCommand = new BuildCommand(Log, testAsset.TestRoot); |
| 387 | + buildCommand.Execute().Should().Pass(); |
| 388 | + |
| 389 | + var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); |
| 390 | + |
| 391 | + AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests"); |
| 392 | + } |
| 393 | + |
| 394 | + [Fact] |
| 395 | + public void It_respects_out_out_of_internals_visible_to() |
| 396 | + { |
| 397 | + var testAsset = _testAssetsManager |
| 398 | + .CopyTestAsset("HelloWorld") |
| 399 | + .WithSource() |
| 400 | + .WithTargetFramework("netstandard2.0") |
| 401 | + .WithProjectChanges((path, project) => |
| 402 | + { |
| 403 | + var ns = project.Root.Name.Namespace; |
| 404 | + |
| 405 | + project.Root.Add( |
| 406 | + new XElement(ns + "PropertyGroup", |
| 407 | + new XElement(ns + "GenerateInternalsVisibleToAttributes", "false")), |
| 408 | + new XElement(ns + "ItemGroup", |
| 409 | + new XElement(ns + "InternalsVisibleTo", |
| 410 | + new XAttribute("Include", "Tests")))); |
| 411 | + }); |
| 412 | + |
| 413 | + new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass(); |
| 414 | + |
| 415 | + var buildCommand = new BuildCommand(Log, testAsset.TestRoot); |
| 416 | + buildCommand.Execute().Should().Pass(); |
| 417 | + |
| 418 | + var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); |
| 419 | + |
| 420 | + Assert.False(AssemblyInfo.Get(assemblyPath).ContainsKey("InternalsVisibleToAttribute")); |
| 421 | + } |
| 422 | + |
| 423 | + [Fact] |
| 424 | + public void It_includes_internals_visible_to_with_key() |
| 425 | + { |
| 426 | + var testAsset = _testAssetsManager |
| 427 | + .CopyTestAsset("HelloWorld") |
| 428 | + .WithSource() |
| 429 | + .WithTargetFramework("netstandard2.0") |
| 430 | + .WithProjectChanges((path, project) => |
| 431 | + { |
| 432 | + var ns = project.Root.Name.Namespace; |
| 433 | + |
| 434 | + project.Root.Add( |
| 435 | + new XElement(ns + "ItemGroup", |
| 436 | + new XElement(ns + "InternalsVisibleTo", |
| 437 | + new XAttribute("Include", "Tests"), |
| 438 | + new XAttribute("Key", "00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2")))); |
| 439 | + }); |
| 440 | + |
| 441 | + new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass(); |
| 442 | + |
| 443 | + var buildCommand = new BuildCommand(Log, testAsset.TestRoot); |
| 444 | + buildCommand.Execute().Should().Pass(); |
| 445 | + |
| 446 | + var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); |
| 447 | + |
| 448 | + AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2"); |
| 449 | + } |
| 450 | + |
| 451 | + [Fact] |
| 452 | + public void It_includes_internals_visible_to_with_project_publickey() |
| 453 | + { |
| 454 | + var testAsset = _testAssetsManager |
| 455 | + .CopyTestAsset("HelloWorld") |
| 456 | + .WithSource() |
| 457 | + .WithTargetFramework("netstandard2.0") |
| 458 | + .WithProjectChanges((path, project) => |
| 459 | + { |
| 460 | + var ns = project.Root.Name.Namespace; |
| 461 | + |
| 462 | + project.Root.Add( |
| 463 | + new XElement(ns + "PropertyGroup", |
| 464 | + new XElement(ns + "PublicKey", "00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2")), |
| 465 | + new XElement(ns + "ItemGroup", |
| 466 | + new XElement(ns + "InternalsVisibleTo", |
| 467 | + new XAttribute("Include", "Tests")))); |
| 468 | + }); |
| 469 | + |
| 470 | + new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass(); |
| 471 | + |
| 472 | + var buildCommand = new BuildCommand(Log, testAsset.TestRoot); |
| 473 | + buildCommand.Execute().Should().Pass(); |
| 474 | + |
| 475 | + var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll"); |
| 476 | + |
| 477 | + AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2"); |
| 478 | + } |
365 | 479 | } |
366 | 480 | } |
0 commit comments