Ejemplo n.º 1
0
        public async Task ApplyProjectEvaluationAsync_IgnoresCommandLineHandlers()
        {
            int callCount = 0;
            var handler   = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, state, logger) => { callCount++; });

            var applyChangesToWorkspace = CreateInitializedInstance(handlers: new[] { handler });

            var update = IProjectVersionedValueFactory.FromJson(
                @"{
   ""ProjectChanges"": {
        ""CompilerCommandLineArgs"": {
            ""Difference"": { 
                ""AnyChanges"": true
            },
        },
        ""RuleName"": {
            ""Difference"": { 
                ""AnyChanges"": true
            },
        }
    }
}");
            await applyChangesToWorkspace.ApplyProjectEvaluationAsync(update, new ContextState(isActiveEditorContext : true, isActiveConfiguration : false), CancellationToken.None);

            Assert.Equal(0, callCount);
        }
Ejemplo n.º 2
0
        public async Task ApplyProjectBuildAsync_WhenCancellationTokenCancelled_StopsProcessingHandlersAndThrowOperationCanceled()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var handler1 = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, state, logger) =>
            {
                cancellationTokenSource.Cancel();
            });

            int callCount = 0;
            var handler2  = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, state, logger) =>
            {
                callCount++;
            });

            var applyChangesToWorkspace = CreateInitializedInstance(handlers: new[] { handler1, handler2 });

            var update = IProjectVersionedValueFactory.FromJson(
                @"{
   ""ProjectChanges"": {
        ""CompilerCommandLineArgs"": {
            ""Difference"": { 
                ""AnyChanges"": true
            },
        }
    }
}");
            await Assert.ThrowsAsync <OperationCanceledException>(() =>
            {
                return(applyChangesToWorkspace.ApplyProjectBuildAsync(update, new ContextState(isActiveEditorContext: true, isActiveConfiguration: false), cancellationTokenSource.Token));
            });

            Assert.True(cancellationTokenSource.IsCancellationRequested);
            Assert.Equal(0, callCount);
        }
        public void ApplyDesignTime_WhenCancellationTokenCancelled_StopsProcessingHandlers()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var handler1 = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, isActiveContext, logger) =>
            {
                cancellationTokenSource.Cancel();
            });

            int callCount = 0;
            var handler2  = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, isActiveContext, logger) =>
            {
                callCount++;
            });

            var applyChangesToWorkspace = CreateInitializedInstance(handlers: new[] { handler1, handler2 });

            var update = IProjectVersionedValueFactory.FromJson(
                @"{
   ""ProjectChanges"": {
        ""CompilerCommandLineArgs"": {
            ""Difference"": { 
                ""AnyChanges"": true
            },
        }
    }
}");

            applyChangesToWorkspace.ApplyDesignTime(update, isActiveContext: true, cancellationTokenSource.Token);

            Assert.True(cancellationTokenSource.IsCancellationRequested);
            Assert.Equal(0, callCount);
        }
Ejemplo n.º 4
0
        public async Task ApplyProjectBuildAsync_WhenNoCompilerCommandLineArgsRuleChanges_DoesNotCallHandler()
        {
            int callCount = 0;
            var handler   = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, state, logger) => { callCount++; });

            var applyChangesToWorkspace = CreateInitializedInstance(handlers: new[] { handler });

            var update = IProjectVersionedValueFactory.FromJson(
                @"{
   ""ProjectChanges"": {
        ""CompilerCommandLineArgs"": {
            ""Difference"": { 
                ""AnyChanges"": false
            },
        }
    }
}");

            await applyChangesToWorkspace.ApplyProjectBuildAsync(update, new ContextState(), CancellationToken.None);

            Assert.Equal(0, callCount);
        }