From f9493545dced3860f60a7901509adc70d3f3aada Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Mon, 31 Oct 2016 20:50:52 -0700 Subject: [PATCH] Address PR comments to improve test readability and reliability --- .../MigratePackageDependenciesAndToolsRule.cs | 18 +++++++++----- ...enThatIWantToMigratePackageDependencies.cs | 24 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index 139e3634b..ab203101d 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -104,30 +104,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules break; case ProjectType.Test: _transformApplicator.Execute( - PackageDependencyInfoTransform.Transform( + PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { Name = PackageConstants.TestSdkPackageName, Version = PackageConstants.TestSdkPackageVersion - }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); + }), + noFrameworkPackageReferenceItemGroup, + mergeExisting: false); if (project.TestRunner.Equals("xunit", StringComparison.OrdinalIgnoreCase)) { _transformApplicator.Execute( - PackageDependencyInfoTransform.Transform( + PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { Name = PackageConstants.XUnitPackageName, Version = PackageConstants.XUnitPackageVersion - }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); + }), + noFrameworkPackageReferenceItemGroup, + mergeExisting: false); _transformApplicator.Execute( - PackageDependencyInfoTransform.Transform( + PackageDependencyInfoTransform().Transform( new PackageDependencyInfo { Name = PackageConstants.XUnitRunnerPackageName, Version = PackageConstants.XUnitRunnerPackageVersion - }), noFrameworkPackageReferenceItemGroup, mergeExisting: false); + }), + noFrameworkPackageReferenceItemGroup, + mergeExisting: false); } break; default: diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 03e0784a0..50066736f 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -272,12 +272,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests ""testRunner"": ""mstest"" }"); - var items = mockProj.Items - .Where(i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference") || - (i.Include == "xunit" && i.ItemType == "PackageReference") || - (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference")); + mockProj.Items.Should().ContainSingle( + i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference")); - items.Should().HaveCount(1); + mockProj.Items.Should().NotContain( + i => (i.Include == "xunit" && i.ItemType == "PackageReference")); + + mockProj.Items.Should().NotContain( + i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference")); } [Fact] @@ -294,12 +296,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests ""testRunner"": ""xunit"" }"); - var items = mockProj.Items - .Where(i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference") || - (i.Include == "xunit" && i.ItemType == "PackageReference") || - (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference")); + mockProj.Items.Should().ContainSingle( + i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference")); - items.Should().HaveCount(3); + mockProj.Items.Should().ContainSingle( + i => (i.Include == "xunit" && i.ItemType == "PackageReference")); + + mockProj.Items.Should().ContainSingle( + i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference")); } private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple[] packageSpecs)