private InterceptedProjectPropertiesProviderBase CreateInstance(FrameworkName configuredTargetFramework)
        {
            var data = new PropertyPageData()
            {
                Category     = ConfigurationGeneral.SchemaName,
                PropertyName = ConfigurationGeneral.TargetFrameworkMonikerProperty,
                Value        = configuredTargetFramework.FullName
            };

            var project          = UnconfiguredProjectFactory.Create();
            var properties       = ProjectPropertiesFactory.Create(project, data);
            var instanceProvider = IProjectInstancePropertiesProviderFactory.Create();

            var delegatePropertiesMock = IProjectPropertiesFactory
                                         .MockWithProperty(TargetFrameworkPropertyName);

            var delegateProperties = delegatePropertiesMock.Object;
            var delegateProvider   = IProjectPropertiesProviderFactory.Create(delegateProperties);

            var targetFrameworkProvider = new TargetFrameworkValueProvider(properties);
            var providerMetadata        = IInterceptingPropertyValueProviderMetadataFactory.Create(TargetFrameworkPropertyName);
            var lazyArray = new[] { new Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata>(
                                        () => targetFrameworkProvider, providerMetadata) };

            return(new ProjectFileInterceptedProjectPropertiesProvider(delegateProvider, instanceProvider, project, lazyArray));
        }
Ejemplo n.º 2
0
        internal async void ProjectFileProperties_WithInterception_SetEvalutedPropertyAsync(string propertyName, string existingPropertyValue, string propertyValueToSet, string expectedValue, Type interceptingProviderType)
        {
            var interceptingProvider = interceptingProviderType != null ?
                                       new Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata>(
                valueFactory: () => (IInterceptingPropertyValueProvider)Activator.CreateInstance(interceptingProviderType),
                metadata: IInterceptingPropertyValueProviderMetadataFactory.Create(propertyName)) :
                                       null;

            string code            = "";
            var    provider        = CreateProviderForProjectFileValidation(code, propertyName, existingPropertyValue, out Workspace workspace, interceptingProvider);
            var    projectFilePath = workspace.CurrentSolution.Projects.First().FilePath;

            var properties = provider.GetProperties(projectFilePath, null, null);
            await properties.SetPropertyValueAsync(propertyName, propertyValueToSet);

            // Read the property value again and confirm the new value.
            properties = provider.GetProperties(projectFilePath, null, null);
            var propertyValue = await properties.GetEvaluatedPropertyValueAsync(propertyName);

            Assert.Equal(expectedValue, propertyValue);

            // Verify no code changes as property was written to project file.
            var newCode = (await workspace.CurrentSolution.Projects.First().Documents.First().GetTextAsync()).ToString();

            Assert.Equal(code, newCode);
        }
Ejemplo n.º 3
0
        internal async void SourceFileProperties_DefaultValues_GetEvalutedPropertyAsync(string code, string propertyName, string expectedValue, Type interceptingProviderType)
        {
            var interceptingProvider = interceptingProviderType != null ?
                                       new Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata>(
                valueFactory: () => (IInterceptingPropertyValueProvider)Activator.CreateInstance(interceptingProviderType),
                metadata: IInterceptingPropertyValueProviderMetadataFactory.Create(propertyName)) :
                                       null;
            var provider        = CreateProviderForSourceFileValidation(code, propertyName, out Workspace workspace, interceptingProvider);
            var projectFilePath = workspace.CurrentSolution.Projects.First().FilePath;

            var properties    = provider.GetProperties(projectFilePath, null, null);
            var propertyValue = await properties.GetEvaluatedPropertyValueAsync(propertyName);

            Assert.Equal(expectedValue, propertyValue);
        }
        public async Task VerifySetKeyFilePropertyAsync()
        {
            string projectFolder          = @"C:\project\root";
            string projectFullPath        = $@"{projectFolder}\project.testproj";
            string keyFileName            = "KeyFile.snk";
            string keyFileFullPath        = $@"{projectFolder}\{keyFileName}";
            var    delegatePropertiesMock = IProjectPropertiesFactory
                                            .MockWithPropertiesAndValues(new Dictionary <string, string>()
            {
                { AssemblyOriginatorKeyFilePropertyName, keyFileFullPath }
            });

            var delegateProperties = delegatePropertiesMock.Object;
            var delegateProvider   = IProjectPropertiesProviderFactory.Create(delegateProperties);

            // Verify get key file value without intercepted provider.
            var properties    = delegateProvider.GetProperties("path/to/project.testproj", null, null);
            var propertyValue = await properties.GetEvaluatedPropertyValueAsync(AssemblyOriginatorKeyFilePropertyName);

            Assert.Equal(keyFileFullPath, propertyValue);

            // Verify relative path key file value from intercepted key file provider.
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFullPath);
            var instanceProvider    = IProjectInstancePropertiesProviderFactory.Create();
            var keyFileProvider     = new AssemblyOriginatorKeyFileValueProvider(unconfiguredProject);
            var providerMetadata    = IInterceptingPropertyValueProviderMetadataFactory.Create(AssemblyOriginatorKeyFilePropertyName);
            var lazyArray           = new[] { new Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata>(
                                                  () => keyFileProvider, providerMetadata) };
            var interceptedProvider = new ProjectFileInterceptedProjectPropertiesProvider(delegateProvider, instanceProvider, unconfiguredProject, lazyArray);
            var propertyNames       = await properties.GetPropertyNamesAsync();

            Assert.Single(propertyNames);
            Assert.Equal(AssemblyOriginatorKeyFilePropertyName, propertyNames.First());
            properties = interceptedProvider.GetProperties("path/to/project.testproj", null, null);
            string newKeyFileName     = "KeyFile2.snk";
            string newKeyFileFullPath = $@"{projectFolder}\{newKeyFileName}";
            await properties.SetPropertyValueAsync(AssemblyOriginatorKeyFilePropertyName, newKeyFileFullPath);

            propertyValue = await properties.GetEvaluatedPropertyValueAsync(AssemblyOriginatorKeyFilePropertyName);

            Assert.Equal(newKeyFileName, propertyValue);
        }
Ejemplo n.º 5
0
 public TestProjectFileOrAssemblyInfoPropertiesProvider(
     Workspace workspace,
     UnconfiguredProject unconfiguredProject,
     Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata> interceptingProvider = null,
     IProjectThreadingService threadingService           = null,
     IProjectProperties defaultProperties                = null,
     IProjectInstancePropertiesProvider instanceProvider = null,
     Func <ProjectId> getActiveProjectId = null)
     : base(delegatedProvider : IProjectPropertiesProviderFactory.Create(defaultProperties ?? IProjectPropertiesFactory.MockWithProperty("").Object),
            instanceProvider : instanceProvider ?? IProjectInstancePropertiesProviderFactory.Create(),
            interceptingValueProviders : interceptingProvider == null ?
            new[] { new Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata>(
                        () => IInterceptingPropertyValueProviderFactory.Create(),
                        IInterceptingPropertyValueProviderMetadataFactory.Create("")) } :
            new[] { interceptingProvider },
            unconfiguredProject : unconfiguredProject,
            getActiveProjectId : getActiveProjectId ?? (() => workspace.CurrentSolution.ProjectIds.SingleOrDefault()),
            workspace : workspace,
            threadingService : threadingService ?? IProjectThreadingServiceFactory.Create())
 {
     Requires.NotNull(workspace, nameof(workspace));
     Requires.NotNull(unconfiguredProject, nameof(unconfiguredProject));
 }