Exemple #1
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsProjectFilePath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ""MSBuildProjectFullPath"" ]
    },
    ""After"": { 
        ""Properties"": {
            ""MSBuildProjectFullPath"": ""NewProjectFilePath""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal(@"NewProjectFilePath", context.ProjectFilePath);
        }
Exemple #2
0
        public void Handle_WhenTargetPathIsNotChanged_DoesNotSetBinOutputPath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.BinOutputPath = @"BinOutputPath";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                @"{
    ""Difference"": { 
        ""AnyChanges"": true,
        ""ChangedProperties"": [ ]
    },
    ""After"": { 
        ""Properties"": {
            ""TargetPath"": ""NewBinOutputPath""
        }
    }
}");

            Handle(handler, projectChange);

            Assert.Equal("BinOutputPath", context.BinOutputPath);
        }
Exemple #3
0
        public void Constructor_NullAsProject_ThrowsArgumentNull()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <ArgumentNullException>("project", () =>
            {
                new MetadataReferenceItemHandler((UnconfiguredProject)null);
            });
        }
Exemple #4
0
        private static ApplyChangesToWorkspaceContext CreateInitializedInstance(out IWorkspaceProjectContext context, ConfiguredProject?project = null, ICommandLineParserService?commandLineParser = null, IProjectLogger?logger = null, params IWorkspaceContextHandler[] handlers)
        {
            var applyChangesToWorkspace = CreateInstance(project, commandLineParser, logger, handlers);

            context = IWorkspaceProjectContextMockFactory.Create();

            applyChangesToWorkspace.Initialize(context);

            return(applyChangesToWorkspace);
        }
Exemple #5
0
        public async Task DisposeAsync_WhenInitializedWithNoHandlers_DoesNotThrow()
        {
            var applyChangesToWorkspace = CreateInstance();
            var context = IWorkspaceProjectContextMockFactory.Create();

            applyChangesToWorkspace.Initialize(context);

            await applyChangesToWorkspace.DisposeAsync();

            Assert.True(applyChangesToWorkspace.IsDisposed);
        }
Exemple #6
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsDisplayNameToFileNameWithoutExtension()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            var handler       = CreateInstance(context: context);
            var projectChange = SetupProjectChanges(true, "C:\\Project\\Project.csproj", true);

            Handle(handler, projectChange);

            Assert.Equal(@"Project", context.DisplayName);
        }
Exemple #7
0
        public void IsActiveEditorContext_UnregisteredContextAsContext_ThrowsInvalidOperation()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <InvalidOperationException>(() =>
            {
                instance.IsActiveEditorContext(context);
            });
        }
Exemple #8
0
        public void RegisterContext_EmptyAsContextId_ThrowsArgument()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <ArgumentException>("contextId", () =>
            {
                instance.RegisterContext(context, string.Empty);
            });
        }
Exemple #9
0
        public void RegisterContext_NullAsContextId_ThrowsArgumentNull()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <ArgumentNullException>("contextId", () =>
            {
                instance.RegisterContext(context, (string)null);
            });
        }
Exemple #10
0
        public void Initialize_InitializesHandlers()
        {
            IWorkspaceProjectContext?result = null;
            var handler = IWorkspaceContextHandlerFactory.ImplementInitialize((c) => { result = c; });

            var applyChangesToWorkspace = CreateInstance(handlers: handler);
            var context = IWorkspaceProjectContextMockFactory.Create();

            applyChangesToWorkspace.Initialize(context);

            Assert.Same(context, result);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        public void Initialize_WhenAlreadyInitialized_ThrowsInvalidOperation()
        {
            var applyChangesToWorkspace = CreateInstance();
            var context = IWorkspaceProjectContextMockFactory.Create();

            applyChangesToWorkspace.Initialize(context);

            Assert.Throws <InvalidOperationException>(() =>
            {
                applyChangesToWorkspace.Initialize(context);
            });
        }
        public async Task ReleaseProjectContextAsync_UnregistersContextWithTracker()
        {
            IWorkspaceProjectContext result          = null;
            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementReleaseContext(c => { result = c; });

            var provider = CreateInstance(activeWorkspaceProjectContextTracker: activeWorkspaceProjectContextTracker);

            var projectContext = IWorkspaceProjectContextMockFactory.Create();

            await provider.ReleaseProjectContextAsync(projectContext);

            Assert.Same(projectContext, result);
        }
Exemple #14
0
        [InlineData("contextId")]           // Case-sensitive
        public void IsActiveEditorContext_WhenActiveIntellisenseProjectContextNotSet_UsesActiveHostContextId(string contextId)
        {
            var activeWorkspaceProjectContextHost = IActiveWorkspaceProjectContextHostFactory.ImplementContextId(contextId);
            var instance = CreateInstance(activeWorkspaceProjectContextHost);

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, contextId);

            var result = instance.IsActiveEditorContext(context);

            Assert.True(result);
        }
Exemple #15
0
        public void Initialize_WhenAlreadyInitialized_ThrowsInvalidOperation()
        {
            var handler = CreateInstance();

            var workspaceContext = IWorkspaceProjectContextMockFactory.Create();

            handler.Initialize(workspaceContext);

            Assert.Throws <InvalidOperationException>(() =>
            {
                handler.Initialize(workspaceContext);
            });
        }
        public async Task GetDesignTimeRules_WhenDisposed_ThrowsObjectDisposed()
        {
            var applyChangesToWorkspace = CreateInstance();

            await applyChangesToWorkspace.DisposeAsync();

            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <ObjectDisposedException>(() =>
            {
                applyChangesToWorkspace.GetProjectBuildRules();
            });
        }
Exemple #17
0
        public void UnregisterContext_RegisteredContextAsContext_CanUnregister()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, "ContextId");

            instance.UnregisterContext(context);

            // Should be unregistered
            Assert.Throws <InvalidOperationException>(() => instance.IsActiveEditorContext(context));
        }
Exemple #18
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsProjectFilePath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";

            var handler       = CreateInstance(context: context);
            var projectChange = SetupProjectChanges(true, "NewProjectFilePath", true);

            Handle(handler, projectChange);

            Assert.Equal(@"NewProjectFilePath", context.ProjectFilePath);
        }
        public async Task CreateProjectContextAsync_ReturnsContextWithLastDesignTimeBuildSucceededSetToFalse()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => context);
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            var result = await provider.CreateProjectContextAsync(project);

            Assert.NotNull(context);
            Assert.False(context.LastDesignTimeBuildSucceeded);
        }
Exemple #20
0
        public void GetProjectName_WhenActiveIntellisenseProjectContextNotSet_ReturnsActiveHostContextId(string contextId)
        {
            var activeWorkspaceProjectContextHost = IActiveWorkspaceProjectContextHostFactory.ImplementContextId(contextId);
            var instance = CreateInstance(activeWorkspaceProjectContextHost);

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, contextId);

            instance.GetProjectName(HierarchyId.Root, out string result);

            Assert.Equal(contextId, result);
        }
Exemple #21
0
        public void RegisteredContext_AlreadyRegisteredContextAsContext_ThrowsInvalidOperation()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, "ContextId");

            Assert.Throws <InvalidOperationException>(() =>
            {
                instance.RegisterContext(context, "ContextId");
            });
        }
Exemple #22
0
        public async Task Initialize_WhenDisposed_ThrowsObjectDisposed()
        {
            var applyChangesToWorkspace = CreateInstance();

            await applyChangesToWorkspace.DisposeAsync();

            var context = IWorkspaceProjectContextMockFactory.Create();

            Assert.Throws <ObjectDisposedException>(() =>
            {
                applyChangesToWorkspace.Initialize(context);
            });
        }
Exemple #23
0
        [InlineData("contextId")]           // Case-sensitive
        public void IsActiveEditorContext_WhenActiveIntellisenseProjectContextDoesNotMatch_ReturnsFalse(string activeIntellisenseProjectContext)
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, "ContextId");

            instance.ActiveIntellisenseProjectContext = activeIntellisenseProjectContext;

            var result = instance.IsActiveEditorContext(context);

            Assert.False(result);
        }
Exemple #24
0
        public void IsActiveEditorContext_WhenActiveIntellisenseProjectContextMatches_ReturnsTrue()
        {
            var instance = CreateInstance();

            var context = IWorkspaceProjectContextMockFactory.Create();

            instance.RegisterContext(context, "ContextId");

            instance.ActiveIntellisenseProjectContext = "ContextId";

            var result = instance.IsActiveEditorContext(context);

            Assert.True(result);
        }
Exemple #25
0
        public void Handle_WhenMSBuildProjectFullPathPropertyChanged_SetsProjectFilePath()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";

            var handler = CreateInstance(context: context);

            var projectChange = IProjectChangeDescriptionFactory.FromJson(
                "" "
                {
                    " Difference ": { 
                        " AnyChanges ": true,
                        " ChangedProperties ": [ " MSBuildProjectFullPath " ]
Exemple #26
0
        public async Task DisposeAsync_DisposesHandlers()
        {
            int callCount = 0;
            var handler   = IWorkspaceContextHandlerFactory.ImplementDispose(() => { callCount++; });

            var applyChangesToWorkspace = CreateInstance(handlers: handler);
            var context = IWorkspaceProjectContextMockFactory.Create();

            applyChangesToWorkspace.Initialize(context);

            await applyChangesToWorkspace.DisposeAsync();

            Assert.Equal(1, callCount);
        }
Exemple #27
0
        public async Task InitializedAsync_WhenInitializedWithContext_RegistersContextWithTracker()
        {
            string contextIdResult = null;
            var    activeWorkspaceProjectContextTracker = IActiveEditorContextTrackerFactory.ImplementRegisterContext(id => { contextIdResult = id; });

            var context  = IWorkspaceProjectContextMockFactory.Create();
            var accessor = IWorkspaceProjectContextAccessorFactory.ImplementContext(context, "ContextId");
            var provider = new WorkspaceProjectContextProviderMock();

            provider.ImplementCreateProjectContextAsync(project => accessor);

            var instance = await CreateInitializedInstanceAsync(workspaceProjectContextProvider : provider.Object, activeWorkspaceProjectContextTracker : activeWorkspaceProjectContextTracker);

            Assert.Equal("ContextId", contextIdResult);
        }
Exemple #28
0
        public void Handle_WhenMSBuildProjectFullPathPropertyNotChanged_DoesNothing(string diffContains, string afterContains)
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            context.ProjectFilePath = @"ProjectFilePath";
            context.DisplayName     = "DisplayName";

            var handler       = CreateInstance(context: context);
            var projectChange = SetupProjectChanges(bool.Parse(diffContains), "C:\\Project\\Project.csproj", bool.Parse(afterContains));

            Handle(handler, projectChange);

            Assert.Equal(@"ProjectFilePath", context.ProjectFilePath);
            Assert.Equal(@"DisplayName", context.DisplayName);
        }
        public async Task CreateProjectContextAsync_RegistersContextWithTracker()
        {
            IWorkspaceProjectContext result          = null;
            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementRegisterContext((c, id) => { result = c; });

            var context = IWorkspaceProjectContextMockFactory.Create();
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => context);
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, activeWorkspaceProjectContextTracker: activeWorkspaceProjectContextTracker);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            await provider.CreateProjectContextAsync(project);

            Assert.NotNull(result);
        }
Exemple #30
0
        public async Task Dispose_WhenInitializedWithContext_ReleasesContext()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();

            IWorkspaceProjectContext result = null;
            var provider = new WorkspaceProjectContextProviderMock();

            provider.ImplementCreateProjectContextAsync(project => context);
            provider.ImplementReleaseProjectContextAsync(c => { result = c; });

            var instance = await CreateInitializedInstanceAsync(workspaceProjectContextProvider : provider.Object);

            await instance.DisposeAsync();

            Assert.Same(context, result);
        }