public async Task WhenPropertyIsAnIEvaluatedProperty_GetUnevaluatedValueAsyncIsCalled() { var properties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus( includeEvaluatedValue: false, includeUnevaluatedValue: true); var mockEvaluatedProperty = new Mock <IEvaluatedProperty>(); mockEvaluatedProperty.Setup(m => m.GetUnevaluatedValueAsync()).ReturnsAsync("unevaluated value"); var property = mockEvaluatedProperty.Object; var entityRuntime = IEntityRuntimeModelFactory.Create(); var id = new EntityIdentity(key: "A", value: "B"); var configuration = ProjectConfigurationFactory.Create(configuration: "Alpha|Beta|Gamma"); var result = (UIPropertyValueValue)await UIPropertyValueDataProducer.CreateUIPropertyValueValueAsync( entityRuntime, id, configuration, property, properties); Assert.Equal(expected: "unevaluated value", actual: result.UnevaluatedValue); mockEvaluatedProperty.Verify(m => m.GetUnevaluatedValueAsync()); }
public async Task WhenThePropertyIsConfigurationIndependent_ThenOnlyOneValueIsReturned() { var parent = IEntityWithIdFactory.Create(key: "ParentName", value: "Aardvark"); var defaultConfiguration = ProjectConfigurationFactory.Create("Alpha|Beta"); var otherConfiguration = ProjectConfigurationFactory.Create("Delta|Gamma"); var cache = IPropertyPageQueryCacheFactory.Create( projectConfigurations: ImmutableHashSet <ProjectConfiguration> .Empty.Add(defaultConfiguration).Add(otherConfiguration), defaultConfiguration: defaultConfiguration, bindToRule: (config, schemaName) => IRuleFactory.Create( name: "ParentName", properties: new[] { IPropertyFactory.Create("MyProperty") })); var schema = new Rule { Properties = { new TestProperty { Name = "MyProperty", DataSource = new(){ HasConfigurationCondition = false } } } }; var propertyName = "MyProperty"; var requestedProperties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus(); var results = await UIPropertyValueDataProducer.CreateUIPropertyValueValuesAsync( parent, cache, schema, propertyName, requestedProperties); Assert.Single(results); }
/// <summary> /// Returns a set of <see cref="ProjectConfiguration"/>s for testing purposes. /// </summary> private static ImmutableHashSet <ProjectConfiguration> GetConfigurations() { return(ImmutableHashSet <ProjectConfiguration> .Empty .Add(ProjectConfigurationFactory.Create("Debug|x86")) .Add(ProjectConfigurationFactory.Create("Debug|x64")) .Add(ProjectConfigurationFactory.Create("Release|x86")) .Add(ProjectConfigurationFactory.Create("Release|x64"))); }
public static IReadOnlyCollection <PackageRestoreConfiguredInput>?Create(ProjectRestoreInfo restoreInfo) { ProjectConfiguration projectConfiguration = ProjectConfigurationFactory.Create("Debug|x64"); IComparable projectVersion = 0; return(new PackageRestoreConfiguredInput[1] { new PackageRestoreConfiguredInput(projectConfiguration, restoreInfo, projectVersion) }); }
public async Task AllowProjectLoadAsync_WhenUnrecognizedExtension_ReturnsTrue(string fullPath) { var project = UnconfiguredProjectFactory.ImplementFullPath(fullPath); var capabilitiesService = IProjectCapabilitiesServiceFactory.ImplementsContains(c => throw new Exception("Should not be hit")); var veto = CreateInstance(project, capabilitiesService); var result = await veto.AllowProjectLoadAsync(true, ProjectConfigurationFactory.Create("Debug|AnyCPU"), CancellationToken.None); Assert.True(result); }
public void Handle_WhenMSBuildProjectFullPathPropertyChangedAndMultitargeting_IncludeDimensionValuesInDisplayName(string dimensionNames, string dimensionValues, string implicitDimensionNames, string expected) { var context = IWorkspaceProjectContextMockFactory.Create(); var implicitlyActiveDimensionProvider = IImplicitlyActiveDimensionProviderFactory.ImplementGetImplicitlyActiveDimensions(n => implicitDimensionNames.SplitReturningEmptyIfEmpty('|')); var configuration = ProjectConfigurationFactory.Create(dimensionNames, dimensionValues); var handler = CreateInstance(configuration, implicitlyActiveDimensionProvider, context); var projectChange = SetupProjectChanges(true, "C:\\Project\\Project.csproj", true); Handle(handler, projectChange); Assert.Equal(expected, context.DisplayName); }
public void WhenThePropertyIsConfigurationIndependent_ThenNoDimensionsAreProduced() { var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true); var parentEntity = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue"); var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C"); var property = IPropertyFactory.Create( dataSource: IDataSourceFactory.Create(hasConfigurationCondition: false)); var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties); Assert.Empty(results); }
public void WhenCreatingEntitiesFromAProjectConfiguration_OneEntityIsCreatedPerDimension() { var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true); var entityRuntimeModel = IEntityRuntimeModelFactory.Create(); var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C"); var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(entityRuntimeModel, configuration, properties); // We can't guarantee an order for the dimensions, so just check that all the expected values are present. Assert.Contains(results, entity => entity is ConfigurationDimensionValue dimension && dimension.Name == "Alpha" && dimension.Value == "A"); Assert.Contains(results, entity => entity is ConfigurationDimensionValue dimension && dimension.Name == "Beta" && dimension.Value == "B"); Assert.Contains(results, entity => entity is ConfigurationDimensionValue dimension && dimension.Name == "Gamma" && dimension.Value == "C"); }
public async Task AllowProjectLoadAsync_WhenMissingCapability_ReturnsFail(string fullPath) { var project = UnconfiguredProjectFactory.ImplementFullPath(fullPath); var capabilitiesService = IProjectCapabilitiesServiceFactory.ImplementsContains(c => false); var veto = CreateInstance(project, capabilitiesService); var result = await Assert.ThrowsAnyAsync <Exception>(() => { return(veto.AllowProjectLoadAsync(true, ProjectConfigurationFactory.Create("Debug|AnyCPU"), CancellationToken.None)); }); Assert.Equal(VSConstants.E_FAIL, result.HResult); }
public void WhenThePropertyIsConfigurationDependent_OneEntityIsCreatedPerDimension() { var properties = PropertiesAvailableStatusFactory.CreateConfigurationDimensionAvailableStatus(includeAllProperties: true); var parentEntity = IEntityWithIdFactory.Create("ParentKey", "ParentKeyValue"); var configuration = ProjectConfigurationFactory.Create("Alpha|Beta|Gamma", "A|B|C"); var property = IPropertyFactory.Create( dataSource: IDataSourceFactory.Create(hasConfigurationCondition: true)); var results = ConfigurationDimensionDataProducer.CreateProjectConfigurationDimensions(parentEntity, configuration, property, properties); // We can't guarantee an order for the dimensions, so just check that all the expected values are present. Assert.Contains(results, entity => entity is ConfigurationDimensionValue { Name: "Alpha", Value: "A" });
public void Update_InitialItemDataDoesNotUpdateLastItemsChangedAtUtc() { // This test covers a false negative described in https://github.com/dotnet/project-system/issues/5386 // where the initial snapshot of items sets LastItemsChangedAtUtc, so if a project is up to date when // it is loaded, then the items are considered changed *after* the last build, but MSBuild's up-to-date // check will determine the project doesn't require a rebuild and so the output timestamps won't update. // This previously left the project in a state where it would be considered out of date endlessly. var projectSnapshot = new Dictionary <string, IProjectRuleSnapshotModel>() { [UpToDateCheckBuilt.SchemaName] = SimpleItems("BuiltOutputPath1") }; var sourceSnapshot1 = new Dictionary <string, IProjectRuleSnapshotModel>() { [Compile.SchemaName] = SimpleItems("ItemPath1") }; var sourceSnapshot2 = new Dictionary <string, IProjectRuleSnapshotModel>() { [Compile.SchemaName] = SimpleItems("ItemPath1", "ItemPath2") }; var state = UpToDateCheckImplicitConfiguredInput.CreateEmpty(ProjectConfigurationFactory.Create("testConfiguration")); Assert.Equal(DateTime.MinValue, state.LastItemsChangedAtUtc); // Initial change does NOT set LastItemsChangedAtUtc state = UpdateState( state, projectSnapshot, sourceSnapshot1); Assert.Equal(DateTime.MinValue, state.LastItemsChangedAtUtc); // Broadcasting an update with no change to items does NOT set LastItemsChangedAtUtc state = UpdateState(state); Assert.Equal(DateTime.MinValue, state.LastItemsChangedAtUtc); // Broadcasting changed items DOES set LastItemsChangedAtUtc state = UpdateState( state, projectSnapshot, sourceSnapshot2); Assert.NotEqual(DateTime.MinValue, state.LastItemsChangedAtUtc); }
public async Task WhenThePropertyIsAnIIntProperty_ThenTheEvaluatedValueIsAnInt() { var properties = PropertiesAvailableStatusFactory.CreateUIPropertyValuePropertiesAvailableStatus(includeEvaluatedValue: true); var mockIntProperty = new Mock <IIntProperty>(); mockIntProperty.Setup(m => m.GetValueAsIntAsync()).ReturnsAsync(42); var property = mockIntProperty.Object; var entityRuntime = IEntityRuntimeModelFactory.Create(); var id = new EntityIdentity(key: "A", value: "B"); var configuration = ProjectConfigurationFactory.Create(configuration: "Alpha|Beta|Gamma"); var result = (UIPropertyValueValue)await UIPropertyValueDataProducer.CreateUIPropertyValueValueAsync( entityRuntime, id, configuration, property, properties); Assert.Equal(expected: 42, actual: result.EvaluatedValue); }
public void Handle_WhenMSBuildProjectFullPathPropertyChangedAndMultitargeting_IncludeDimensionValuesInDisplayName(string dimensionNames, string dimensionValues, string implicitDimensionNames, string expected) { var context = IWorkspaceProjectContextMockFactory.Create(); var implicitlyActiveDimensionProvider = IImplicitlyActiveDimensionProviderFactory.ImplementGetImplicitlyActiveDimensions(n => implicitDimensionNames.SplitReturningEmptyIfEmpty('|')); var configuration = ProjectConfigurationFactory.Create(dimensionNames, dimensionValues); var handler = CreateInstance(configuration, implicitlyActiveDimensionProvider, context); var projectChange = IProjectChangeDescriptionFactory.FromJson( @"{ ""Difference"": { ""AnyChanges"": true, ""ChangedProperties"": [ ""MSBuildProjectFullPath"" ] }, ""After"": { ""Properties"": { ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"" } } }"); Handle(handler, projectChange); Assert.Equal(expected, context.DisplayName); }
public static IConfigurationGroup <ProjectConfiguration> CreateFromConfigurationNames(params string[] configurationNames) { IEnumerable <ProjectConfiguration> configurations = configurationNames.Select(name => ProjectConfigurationFactory.Create(name)); return(Create(configurations)); }
public static ConfiguredProject ImplementProjectConfiguration(string configuration) { return(ImplementProjectConfiguration(ProjectConfigurationFactory.Create(configuration))); }
private static ProjectFilePathAndDisplayNameEvaluationHandler CreateInstance(ProjectConfiguration?configuration = null, IImplicitlyActiveDimensionProvider?implicitlyActiveDimensionProvider = null, IWorkspaceProjectContext?context = null) { var project = ConfiguredProjectFactory.ImplementProjectConfiguration(configuration ?? ProjectConfigurationFactory.Create("Debug|AnyCPU")); implicitlyActiveDimensionProvider ??= IImplicitlyActiveDimensionProviderFactory.Create(); var handler = new ProjectFilePathAndDisplayNameEvaluationHandler(project, implicitlyActiveDimensionProvider); if (context != null) { handler.Initialize(context); } return(handler); }
public void GetDisplayString(string pattern) { Assert.Equal(pattern, ProjectConfigurationFactory.Create(pattern).GetDisplayString()); }