/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/ProjectSystem/Debug/ActiveDebugFrameworkServicesTests.cs

https://github.com/dotnet/project-system · C# · 107 lines · 84 code · 20 blank · 3 comment · 1 complexity · a3fb48af1237747b201f8094485fca71 MD5 · raw file

  1. // 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.
  2. using System.Collections.Immutable;
  3. using System.Threading.Tasks;
  4. using Microsoft.VisualStudio.ProjectSystem.Debug;
  5. using Moq;
  6. using Xunit;
  7. namespace Microsoft.VisualStudio.ProjectSystem.Input.Commands
  8. {
  9. public class ActiveDebugFrameworkServicesTests
  10. {
  11. [Theory]
  12. [InlineData("netcoreapp1.0;net462", new string[] { "netcoreapp1.0", "net462" })]
  13. [InlineData("net461;netcoreapp1.0;net45;net462", new string[] { "net461", "netcoreapp1.0", "net45", "net462" })]
  14. public async Task GetProjectFrameworksAsync_ReturnsFrameworksInCorrectOrder(string frameworks, string[] expectedOrder)
  15. {
  16. var project = UnconfiguredProjectFactory.Create();
  17. var data = new PropertyPageData(ConfigurationGeneral.SchemaName, ConfigurationGeneral.TargetFrameworksProperty, frameworks);
  18. var projectProperties = ProjectPropertiesFactory.Create(project, data);
  19. var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(projectProperties: projectProperties);
  20. var debugFrameworkSvcs = new ActiveDebugFrameworkServices(null!, commonServices);
  21. var result = await debugFrameworkSvcs.GetProjectFrameworksAsync();
  22. Assert.NotNull(result);
  23. Assert.Equal(expectedOrder.Length, result!.Count);
  24. for (int i = 0; i < result.Count; i++)
  25. {
  26. Assert.Equal(expectedOrder[i], result[i]);
  27. }
  28. }
  29. [Theory]
  30. [InlineData("netcoreapp1.0")]
  31. [InlineData("net461")]
  32. public async Task GetActiveDebuggingFrameworkPropertyAsync_ReturnsFrameworkValue(string framework)
  33. {
  34. var project = UnconfiguredProjectFactory.Create();
  35. var data = new PropertyPageData(ProjectDebugger.SchemaName, ProjectDebugger.ActiveDebugFrameworkProperty, framework);
  36. var projectProperties = ProjectPropertiesFactory.Create(project, data);
  37. var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(projectProperties: projectProperties);
  38. var debugFrameworkSvcs = new ActiveDebugFrameworkServices(null!, commonServices);
  39. var result = await debugFrameworkSvcs.GetActiveDebuggingFrameworkPropertyAsync();
  40. Assert.Equal(framework, result);
  41. }
  42. [Fact]
  43. public async Task SetActiveDebuggingFrameworkPropertyAsync_SetsValue()
  44. {
  45. var project = UnconfiguredProjectFactory.Create();
  46. var data = new PropertyPageData(ProjectDebugger.SchemaName, ProjectDebugger.ActiveDebugFrameworkProperty, "FrameworkOne");
  47. var projectProperties = ProjectPropertiesFactory.Create(project, data);
  48. var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(projectProperties: projectProperties);
  49. var debugFrameworkSvcs = new ActiveDebugFrameworkServices(null!, commonServices);
  50. await debugFrameworkSvcs.SetActiveDebuggingFrameworkPropertyAsync("netcoreapp1.0");
  51. // Just verifies it doesn't throw. In other words, the function is trying to set the correct property. The way the property mocks
  52. // are set up there is no easy way to capture the value being set without rewriting how they work.
  53. }
  54. [Theory]
  55. [InlineData("netcoreapp1.0", "netcoreapp1.0")]
  56. [InlineData("net461", "net461")]
  57. [InlineData("", "net462")]
  58. [InlineData("someframework", "net462")]
  59. public async Task GetConfiguredProjectForActiveFrameworkAsync_ReturnsCorrectProject(string framework, string selectedConfigFramework)
  60. {
  61. var project = UnconfiguredProjectFactory.Create();
  62. var data = new PropertyPageData(ProjectDebugger.SchemaName, ProjectDebugger.ActiveDebugFrameworkProperty, framework);
  63. var data2 = new PropertyPageData(ConfigurationGeneral.SchemaName, ConfigurationGeneral.TargetFrameworksProperty, "net462;net461;netcoreapp1.0");
  64. var projects = ImmutableStringDictionary<ConfiguredProject>.EmptyOrdinal
  65. .Add("net461", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net461", Empty.PropertiesMap
  66. .Add("Configuration", "Debug")
  67. .Add("Platform", "AnyCPU")
  68. .Add("TargetFramework", "net461"))))
  69. .Add("netcoreapp1.0", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|netcoreapp1.0", Empty.PropertiesMap
  70. .Add("Configuration", "Debug")
  71. .Add("Platform", "AnyCPU")
  72. .Add("TargetFramework", "netcoreapp1.0"))))
  73. .Add("net462", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net462", Empty.PropertiesMap
  74. .Add("Configuration", "Debug")
  75. .Add("Platform", "AnyCPU")
  76. .Add("TargetFramework", "net462"))));
  77. var projectProperties = ProjectPropertiesFactory.Create(project, data, data2);
  78. var projectConfigProvider = new IActiveConfiguredProjectsProviderFactory(MockBehavior.Strict)
  79. .ImplementGetActiveConfiguredProjectsMapAsync(projects);
  80. var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(projectProperties: projectProperties);
  81. var debugFrameworkSvcs = new ActiveDebugFrameworkServices(projectConfigProvider.Object, commonServices);
  82. var activeConfiguredProject = await debugFrameworkSvcs.GetConfiguredProjectForActiveFrameworkAsync();
  83. Assert.NotNull(activeConfiguredProject);
  84. Assert.Equal(selectedConfigFramework, activeConfiguredProject!.ProjectConfiguration.Dimensions.GetValueOrDefault("TargetFramework"));
  85. }
  86. }
  87. }