3
3
4
4
#nullable disable
5
5
6
+ using Microsoft . VisualBasic ;
7
+
6
8
namespace Microsoft . NET . Build . Tests
7
9
{
8
10
public class GivenThatWeWantToControlGeneratedAssemblyInfo : SdkTest
@@ -50,19 +52,19 @@ public void It_respects_opt_outs(string attributeToOptOut)
50
52
. Should ( )
51
53
. Pass ( ) ;
52
54
53
- var expectedInfo = new SortedDictionary < string , string >
54
- {
55
- { "AssemblyInformationalVersionAttribute" , "1.2.3-beta" } ,
56
- { "AssemblyFileVersionAttribute" , "4.5.6.7" } ,
57
- { "AssemblyVersionAttribute" , "8.9.10.11" } ,
58
- { "AssemblyCompanyAttribute" , "TestCompany" } ,
59
- { "AssemblyConfigurationAttribute" , "Release" } ,
60
- { "AssemblyCopyrightAttribute" , "TestCopyright" } ,
61
- { "AssemblyDescriptionAttribute" , "TestDescription" } ,
62
- { "AssemblyProductAttribute" , "TestProduct" } ,
63
- { "AssemblyTitleAttribute" , "TestTitle" } ,
64
- { "AssemblyTrademarkAttribute" , "TestTrademark" } ,
65
- { "NeutralResourcesLanguageAttribute" , "fr" } ,
55
+ var expectedInfo = new HashSet < ( string Key , string Value ) >
56
+ {
57
+ ( "AssemblyInformationalVersionAttribute" , "1.2.3-beta" ) ,
58
+ ( "AssemblyFileVersionAttribute" , "4.5.6.7" ) ,
59
+ ( "AssemblyVersionAttribute" , "8.9.10.11" ) ,
60
+ ( "AssemblyCompanyAttribute" , "TestCompany" ) ,
61
+ ( "AssemblyConfigurationAttribute" , "Release" ) ,
62
+ ( "AssemblyCopyrightAttribute" , "TestCopyright" ) ,
63
+ ( "AssemblyDescriptionAttribute" , "TestDescription" ) ,
64
+ ( "AssemblyProductAttribute" , "TestProduct" ) ,
65
+ ( "AssemblyTitleAttribute" , "TestTitle" ) ,
66
+ ( "AssemblyTrademarkAttribute" , "TestTrademark" ) ,
67
+ ( "NeutralResourcesLanguageAttribute" , "fr" ) ,
66
68
} ;
67
69
68
70
if ( attributeToOptOut == "All" )
@@ -71,10 +73,10 @@ public void It_respects_opt_outs(string attributeToOptOut)
71
73
}
72
74
else
73
75
{
74
- expectedInfo . Remove ( attributeToOptOut ) ;
76
+ expectedInfo . RemoveWhere ( i => i . Key == attributeToOptOut ) ;
75
77
}
76
78
77
- expectedInfo . Add ( "TargetFrameworkAttribute" , $ ".NETCoreApp,Version=v{ ToolsetInfo . CurrentTargetFrameworkVersion } ") ;
79
+ expectedInfo . Add ( ( "TargetFrameworkAttribute" , $ ".NETCoreApp,Version=v{ ToolsetInfo . CurrentTargetFrameworkVersion } ") ) ;
78
80
79
81
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( ToolsetInfo . CurrentTargetFramework , "Release" ) . FullName , "HelloWorld.dll" ) ;
80
82
var actualInfo = AssemblyInfo . Get ( assemblyPath ) ;
@@ -258,9 +260,9 @@ public void It_respects_version_prefix(string targetFramework)
258
260
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( targetFramework ) . FullName , "HelloWorld.dll" ) ;
259
261
var info = AssemblyInfo . Get ( assemblyPath ) ;
260
262
261
- info [ "AssemblyVersionAttribute" ] . Should ( ) . Be ( " 1.2.3.0") ;
262
- info [ "AssemblyFileVersionAttribute" ] . Should ( ) . Be ( " 1.2.3.0") ;
263
- info [ "AssemblyInformationalVersionAttribute" ] . Should ( ) . Be ( " 1.2.3") ;
263
+ info . Should ( ) . Contain ( ( "AssemblyVersionAttribute" , " 1.2.3.0") ) ;
264
+ info . Should ( ) . Contain ( ( "AssemblyFileVersionAttribute" , " 1.2.3.0") ) ;
265
+ info . Should ( ) . Contain ( ( "AssemblyInformationalVersionAttribute" , " 1.2.3") ) ;
264
266
}
265
267
266
268
[ WindowsOnlyTheory ]
@@ -285,7 +287,7 @@ public void It_respects_version_changes_on_incremental_build(string targetFramew
285
287
// Then the version of the built assembly shall match the provided VersionPrefix
286
288
var assemblyPath = Path . Combine ( incrementalBuildCommand . GetOutputDirectory ( targetFramework ) . FullName , "HelloWorld.dll" ) ;
287
289
var info = AssemblyInfo . Get ( assemblyPath ) ;
288
- info [ "AssemblyVersionAttribute" ] . Should ( ) . Be ( " 1.2.4.0") ;
290
+ info . Should ( ) . Contain ( ( "AssemblyVersionAttribute" , " 1.2.4.0") ) ;
289
291
290
292
BuildCommand BuildProject ( string versionPrefix )
291
293
{
@@ -307,7 +309,7 @@ public void It_respects_custom_assembly_attribute_items_on_incremental_build()
307
309
308
310
var firstBuildCommand = BuildProject ( buildNumber : "1" ) ;
309
311
var assemblyPath = Path . Combine ( firstBuildCommand . GetOutputDirectory ( targetFramework ) . FullName , "TestLibrary.dll" ) ;
310
- AssemblyInfo . Get ( assemblyPath ) [ "AssemblyMetadataAttribute" ] . Should ( ) . Be ( " BuildNumber:1") ;
312
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "AssemblyMetadataAttribute" , " BuildNumber:1") ) ;
311
313
312
314
var firstWriteTime = File . GetLastWriteTimeUtc ( assemblyPath ) ;
313
315
@@ -324,7 +326,7 @@ public void It_respects_custom_assembly_attribute_items_on_incremental_build()
324
326
File . GetLastWriteTimeUtc ( assemblyPath ) . Should ( ) . NotBe ( firstWriteTime ) ;
325
327
326
328
// and the custom assembly should be generated with the updated value.
327
- AssemblyInfo . Get ( assemblyPath ) [ "AssemblyMetadataAttribute" ] . Should ( ) . Be ( " BuildNumber:2") ;
329
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "AssemblyMetadataAttribute" , " BuildNumber:2") ) ;
328
330
329
331
BuildCommand BuildProject ( string buildNumber )
330
332
{
@@ -358,7 +360,7 @@ public void It_includes_internals_visible_to()
358
360
359
361
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
360
362
361
- AssemblyInfo . Get ( assemblyPath ) [ "InternalsVisibleToAttribute" ] . Should ( ) . Be ( " Tests") ;
363
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "InternalsVisibleToAttribute" , " Tests") ) ;
362
364
}
363
365
364
366
[ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
@@ -552,7 +554,7 @@ public void It_respects_out_out_of_internals_visible_to()
552
554
553
555
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
554
556
555
- Assert . False ( AssemblyInfo . Get ( assemblyPath ) . ContainsKey ( "InternalsVisibleToAttribute" ) ) ;
557
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . NotContain ( i => i . Key == "InternalsVisibleToAttribute" ) ;
556
558
}
557
559
558
560
[ Fact ]
@@ -578,7 +580,7 @@ public void It_includes_internals_visible_to_with_key()
578
580
579
581
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
580
582
581
- AssemblyInfo . Get ( assemblyPath ) [ "InternalsVisibleToAttribute" ] . Should ( ) . Be ( " Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2") ;
583
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "InternalsVisibleToAttribute" , " Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2") ) ;
582
584
}
583
585
584
586
[ Fact ]
@@ -605,7 +607,7 @@ public void It_includes_internals_visible_to_with_project_publickey()
605
607
606
608
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
607
609
608
- AssemblyInfo . Get ( assemblyPath ) [ "InternalsVisibleToAttribute" ] . Should ( ) . Be ( " Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2") ;
610
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "InternalsVisibleToAttribute" , " Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2") ) ;
609
611
}
610
612
611
613
[ Fact ]
@@ -631,11 +633,11 @@ public void It_includes_assembly_metadata()
631
633
632
634
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
633
635
634
- AssemblyInfo . Get ( assemblyPath ) [ "AssemblyMetadataAttribute" ] . Should ( ) . Be ( " MetadataKey:MetadataValue") ;
636
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "AssemblyMetadataAttribute" , " MetadataKey:MetadataValue") ) ;
635
637
}
636
638
637
639
[ Fact ]
638
- public void It_respects_out_out_of_assembly_metadata ( )
640
+ public void It_respects_opt_out_of_assembly_metadata ( )
639
641
{
640
642
var testAsset = _testAssetsManager
641
643
. CopyTestAsset ( "HelloWorld" )
@@ -659,7 +661,7 @@ public void It_respects_out_out_of_assembly_metadata()
659
661
660
662
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( "netstandard2.0" ) . FullName , "HelloWorld.dll" ) ;
661
663
662
- Assert . False ( AssemblyInfo . Get ( assemblyPath ) . ContainsKey ( "AssemblyMetadataAttribute" ) ) ;
664
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . NotContain ( i => i . Key == "AssemblyMetadataAttribute" ) ;
663
665
}
664
666
665
667
[ Theory ]
@@ -699,11 +701,11 @@ public void GenerateUserSecrets(bool referenceAspNetCore, bool referenceExtensio
699
701
700
702
if ( shouldHaveAttribute )
701
703
{
702
- AssemblyInfo . Get ( assemblyPath ) [ "UserSecretsIdAttribute" ] . Should ( ) . Be ( " SecretsIdValue") ;
704
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "UserSecretsIdAttribute" , " SecretsIdValue") ) ;
703
705
}
704
706
else
705
707
{
706
- AssemblyInfo . Get ( assemblyPath ) . Should ( ) . NotContainKey ( "SecretsIdValue" ) ;
708
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . NotContain ( i => i . Key == "SecretsIdValue" ) ;
707
709
}
708
710
}
709
711
@@ -743,7 +745,7 @@ public void GenerateUserSecretsForTestProject()
743
745
744
746
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( testTestProject . TargetFrameworks ) . FullName , testTestProject . Name + ".dll" ) ;
745
747
746
- AssemblyInfo . Get ( assemblyPath ) [ "UserSecretsIdAttribute" ] . Should ( ) . Be ( " SecretsIdValue") ;
748
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "UserSecretsIdAttribute" , " SecretsIdValue") ) ;
747
749
}
748
750
749
751
[ Theory ]
@@ -775,7 +777,7 @@ public void It_includes_repository_url(bool privateRepo)
775
777
776
778
var assemblyPath = Path . Combine ( buildCommand . GetOutputDirectory ( testProject . TargetFrameworks ) . FullName , testProject . Name + ".dll" ) ;
777
779
778
- AssemblyInfo . Get ( assemblyPath ) [ "AssemblyMetadataAttribute" ] . Should ( ) . Be ( " RepositoryUrl:" + fakeUrl ) ;
780
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "AssemblyMetadataAttribute" , " RepositoryUrl:" + fakeUrl ) ) ;
779
781
}
780
782
781
783
[ Theory ]
@@ -804,11 +806,11 @@ public void It_does_not_write_to_undefined_assembly_metadata_attribute(string ta
804
806
805
807
if ( containsAttribute )
806
808
{
807
- AssemblyInfo . Get ( assemblyPath ) [ "AssemblyMetadataAttribute" ] . Should ( ) . Be ( " RepositoryUrl:" + fakeUrl ) ;
809
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . Contain ( ( "AssemblyMetadataAttribute" , " RepositoryUrl:" + fakeUrl ) ) ;
808
810
}
809
811
else
810
812
{
811
- AssemblyInfo . Get ( assemblyPath ) . ContainsKey ( "AssemblyMetadataAttribute" ) . Should ( ) . Be ( false ) ;
813
+ AssemblyInfo . Get ( assemblyPath ) . Should ( ) . NotContain ( i => i . Key == "AssemblyMetadataAttribute" ) ;
812
814
}
813
815
}
814
816
0 commit comments