-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7714 from ocallesp/fix1420437
[Dev17.0] Fix1420437
- Loading branch information
Showing
3 changed files
with
129 additions
and
21 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...crosoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/OutputTypeChecker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.ProjectSystem.Properties; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.Debug | ||
{ | ||
internal class OutputTypeChecker | ||
{ | ||
private readonly ProjectProperties _properties; | ||
|
||
public OutputTypeChecker(ProjectProperties properties) | ||
{ | ||
_properties = properties; | ||
} | ||
|
||
public Task<bool> IsLibraryAsync() => IsOutputTypeAsync(ConfigurationGeneral.OutputTypeValues.Library); | ||
|
||
public Task<bool> IsConsoleAsync() => IsOutputTypeAsync(ConfigurationGeneral.OutputTypeValues.Exe); | ||
|
||
public async Task<bool> IsOutputTypeAsync(string outputType) | ||
{ | ||
IEnumValue? actualOutputType = await GetEvaluatedOutputTypeAsync(); | ||
|
||
return actualOutputType is not null && StringComparers.PropertyLiteralValues.Equals(actualOutputType.Name, outputType); | ||
} | ||
|
||
public virtual async Task<IEnumValue?> GetEvaluatedOutputTypeAsync() | ||
{ | ||
// Used by default Windows debugger to figure out whether to add an extra | ||
// pause to end of window when CTRL+F5'ing a console application | ||
ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync(); | ||
|
||
var actualOutputType = (IEnumValue?)await configuration.OutputType.GetValueAsync(); | ||
|
||
return actualOutputType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...Studio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Debug/OutputTypeCheckerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.Build.Framework.XamlTypes; | ||
using Microsoft.VisualStudio.ProjectSystem.Properties; | ||
using Xunit; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.Debug | ||
{ | ||
public class OutputTypeCheckerTest | ||
{ | ||
private readonly string _ProjectFile = @"c:\test\project\project.csproj"; | ||
|
||
[Fact] | ||
public async Task OutputTypeChecker_False_IsLibraryAsyncWhenEvaluationFails() | ||
{ | ||
OutputTypeChecker outputTypeChecker = CreateFailedOutputTypeChecker(); | ||
|
||
Assert.False(await outputTypeChecker.IsLibraryAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task OutputTypeChecker_True_IsLibraryAsync() | ||
{ | ||
OutputTypeChecker outputTypeChecker = CreateOutputTypeChecker(ConfigurationGeneral.OutputTypeValues.Library); | ||
|
||
Assert.True(await outputTypeChecker.IsLibraryAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task OutputTypeChecker_False_IsLibraryAsync() | ||
{ | ||
OutputTypeChecker outputTypeChecker = CreateOutputTypeChecker(ConfigurationGeneral.OutputTypeValues.Exe); | ||
|
||
Assert.False(await outputTypeChecker.IsLibraryAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task OutputTypeChecker_True_IsConsoleAsync() | ||
{ | ||
OutputTypeChecker outputTypeChecker = CreateOutputTypeChecker(ConfigurationGeneral.OutputTypeValues.Exe); | ||
|
||
Assert.True(await outputTypeChecker.IsConsoleAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task OutputTypeChecker_False_IsConsoleAsync() | ||
{ | ||
OutputTypeChecker outputTypeChecker = CreateOutputTypeChecker(ConfigurationGeneral.OutputTypeValues.Library); | ||
|
||
Assert.False(await outputTypeChecker.IsConsoleAsync()); | ||
} | ||
|
||
private OutputTypeChecker CreateFailedOutputTypeChecker() | ||
{ | ||
var projectProperties = ProjectPropertiesFactory.CreateEmpty(); | ||
|
||
return new OutputTypeChecker2(projectProperties); | ||
} | ||
|
||
private OutputTypeChecker CreateOutputTypeChecker(string outputType) | ||
{ | ||
var project = UnconfiguredProjectFactory.Create(fullPath: _ProjectFile); | ||
|
||
var outputTypeEnum = new PageEnumValue(new EnumValue { Name = outputType }); | ||
var data = new PropertyPageData(ConfigurationGeneral.SchemaName, ConfigurationGeneral.OutputTypeProperty, outputTypeEnum); | ||
var projectProperties = ProjectPropertiesFactory.Create(project, data); | ||
|
||
return new OutputTypeChecker(projectProperties); | ||
} | ||
|
||
internal class OutputTypeChecker2 : OutputTypeChecker | ||
{ | ||
public OutputTypeChecker2(ProjectProperties properties) : base(properties) | ||
{ | ||
} | ||
|
||
public override Task<IEnumValue?> GetEvaluatedOutputTypeAsync() | ||
{ | ||
// Evaluation fails | ||
return Task.FromResult<IEnumValue?>(null); | ||
} | ||
} | ||
} | ||
} |