/// <summary> /// Helper function to build a simple project based on a particular change wave being set. /// Call SetChangeWave on your TestEnvironment before calling this function. /// </summary> /// <param name="testEnvironment">The TestEnvironment being used for this test.</param> /// <param name="versionToCheckAgainstCurrentChangeWave">The version to compare to the current set Change Wave.</param> /// <param name="currentChangeWaveShouldUltimatelyResolveTo">What the project property for the environment variable MSBuildDisableFeaturesFromVersion ultimately resolves to.</param> /// <param name="warningCodesLogShouldContain">An array of warning codes that should exist in the resulting log. Ex: "MSB4271".</param> private void buildSimpleProjectAndValidateChangeWave(TestEnvironment testEnvironment, Version versionToCheckAgainstCurrentChangeWave, Version currentChangeWaveShouldUltimatelyResolveTo, params string[] warningCodesLogShouldContain) { bool isThisWaveEnabled = versionToCheckAgainstCurrentChangeWave < currentChangeWaveShouldUltimatelyResolveTo || currentChangeWaveShouldUltimatelyResolveTo == ChangeWaves.EnableAllFeatures; ChangeWaves.AreFeaturesEnabled(versionToCheckAgainstCurrentChangeWave).ShouldBe(isThisWaveEnabled); string projectFile = $"" + $"<Project>" + $"<Target Name='HelloWorld' Condition=\"$([MSBuild]::AreFeaturesEnabled('{versionToCheckAgainstCurrentChangeWave}')) and '$(MSBUILDDISABLEFEATURESFROMVERSION)' == '{currentChangeWaveShouldUltimatelyResolveTo}'\">" + $"<Message Text='Hello World!'/>" + $"</Target>" + $"</Project>"; TransientTestFile file = testEnvironment.CreateFile("proj.csproj", projectFile); ProjectCollection collection = new ProjectCollection(); MockLogger log = new MockLogger(_output); collection.RegisterLogger(log); Project p = collection.LoadProject(file.Path); p.Build().ShouldBeTrue(); log.FullLog.Contains("Hello World!").ShouldBe(isThisWaveEnabled); if (warningCodesLogShouldContain != null) { log.WarningCount.ShouldBe(warningCodesLogShouldContain.Length); log.AssertLogContains(warningCodesLogShouldContain); } ChangeWaves.ResetStateForTests(); }
public void NoChangeWaveSetMeansAllChangeWavesAreEnabled(string featureWave) { using (TestEnvironment env = TestEnvironment.Create()) { ChangeWaves.ResetStateForTests(); ChangeWaves.AreFeaturesEnabled(featureWave).ShouldBe(true); string projectFile = $"" + $"<Project>" + $"<Target Name='HelloWorld' Condition=\"'$(MSBUILDDISABLEFEATURESFROMVERSION)' == '{ChangeWaves.EnableAllFeatures}' and $([MSBuild]::AreFeaturesEnabled('{featureWave}'))\">" + $"<Message Text='Hello World!'/>" + $"</Target>" + $"</Project>"; TransientTestFile file = env.CreateFile("proj.csproj", projectFile); ProjectCollection collection = new ProjectCollection(); MockLogger log = new MockLogger(); collection.RegisterLogger(log); collection.LoadProject(file.Path).Build().ShouldBeTrue(); log.AssertLogContains("Hello World!"); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); } }
public void VersionSetToValidValueButInvalidVersionSetsNextVersion() { using (TestEnvironment env = TestEnvironment.Create()) { env.SetChangeWave($"{ChangeWaves.LowestWaveAsVersion.Major}.{ChangeWaves.LowestWaveAsVersion.Minor}.{ChangeWaves.LowestWaveAsVersion.Build+1}"); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); // All waves should be disabled string projectFile = $"" + $"<Project>" + $"<Target Name='HelloWorld' Condition=\"'$(MSBUILDDISABLEFEATURESFROMVERSION)' == '{ChangeWaves.AllWaves[1]}' and $([MSBuild]::AreFeaturesEnabled('{ChangeWaves.LowestWave}'))\">" + $"<Message Text='Hello World!'/>" + $"</Target>" + $"</Project>"; TransientTestFile file = env.CreateFile("proj.csproj", projectFile); ProjectCollection collection = new ProjectCollection(); MockLogger log = new MockLogger(); collection.RegisterLogger(log); Project p = collection.LoadProject(file.Path); p.Build().ShouldBeTrue(); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); log.AssertLogContains("Hello World!"); } }
public void CorrectlyDetermineDisabledFeatures() { using (TestEnvironment env = TestEnvironment.Create()) { env.SetChangeWave(ChangeWaves.LowestWave); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); foreach (string wave in ChangeWaves.AllWaves) { ChangeWaves.AreFeaturesEnabled(wave).ShouldBeFalse(); string projectFile = $"" + $"<Project>" + $"<Target Name='HelloWorld' Condition=\"$([MSBuild]::AreFeaturesEnabled('{wave}')) == false\">" + $"<Message Text='Hello World!'/>" + $"</Target>" + $"</Project>"; TransientTestFile file = env.CreateFile("proj.csproj", projectFile); ProjectCollection collection = new ProjectCollection(); MockLogger log = new MockLogger(); collection.RegisterLogger(log); Project p = collection.LoadProject(file.Path); p.Build().ShouldBeTrue(); log.AssertLogContains("Hello World!"); } BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); } }
public void VersionTooHighClampsToHighestVersionInRotation(string disableFromWave) { using (TestEnvironment env = TestEnvironment.Create()) { env.SetChangeWave(disableFromWave); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); // all waves but the highest should pass for (int i = 0; i < ChangeWaves.AllWaves.Length - 1; i++) { ChangeWaves.ResetStateForTests(); string projectFile = $"" + $"<Project>" + $"<Target Name='HelloWorld' Condition=\"'$(MSBUILDDISABLEFEATURESFROMVERSION)' == '{ChangeWaves.HighestWave}' and $([MSBuild]::AreFeaturesEnabled('{ChangeWaves.AllWaves[i]}'))\">" + $"<Message Text='Hello World!'/>" + $"</Target>" + $"</Project>"; TransientTestFile file = env.CreateFile("proj.csproj", projectFile); ProjectCollection collection = new ProjectCollection(); MockLogger log = new MockLogger(); collection.RegisterLogger(log); Project p = collection.LoadProject(file.Path); p.Build().ShouldBeTrue(); BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); log.WarningCount.ShouldBe(1); log.AssertLogContains("out of rotation"); log.AssertLogContains("Hello World!"); } } }