Exemple #1
0
        public async Task ApplyProjectBuildAsync_IgnoresEvaluationHandlers()
        {
            int callCount = 0;
            var handler   = IEvaluationHandlerFactory.ImplementHandle("RuleName", (version, description, state, logger) => { callCount++; });

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

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

            Assert.Equal(0, callCount);
        }
Exemple #2
0
        public async Task ApplyProjectEvaluationAsync_CallsHandler()
        {
            (IComparable version, IProjectChangeDescription description, ContextState state, IProjectLogger logger)result = default;

            var handler = IEvaluationHandlerFactory.ImplementHandle("RuleName", (version, description, state, logger) =>
            {
                result = (version, description, state, logger);
            });

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

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

            Assert.Equal(2, result.version);
            Assert.NotNull(result.description);
            Assert.True(result.state.IsActiveEditorContext);
            Assert.True(result.state.IsActiveConfiguration);
            Assert.NotNull(result.logger);
        }
        public void ApplyDesignTime_IgnoresEvaluationHandlers()
        {
            int callCount = 0;
            var handler   = IEvaluationHandlerFactory.ImplementHandle("RuleName", (version, description, isActiveContext, logger) => { callCount++; });

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

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

            applyChangesToWorkspace.ApplyDesignTime(update, isActiveContext: true, CancellationToken.None);

            Assert.Equal(0, callCount);
        }
        public void ApplyEvaluation_CallsHandler()
        {
            (IComparable version, IProjectChangeDescription description, bool isActiveContext, IProjectLogger logger)result = default;

            var handler = IEvaluationHandlerFactory.ImplementHandle("RuleName", (version, description, isActiveContext, logger) =>
            {
                result = (version, description, isActiveContext, logger);
            });

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

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

            applyChangesToWorkspace.ApplyEvaluation(update, isActiveContext: true, CancellationToken.None);

            Assert.Equal(2, result.version);
            Assert.NotNull(result.description);
            Assert.True(result.isActiveContext);
            Assert.NotNull(result.logger);
        }
Exemple #5
0
        public void GetProjectEvaluationRules_ReturnsAllProjectEvaluationRuleNames()
        {
            var handler1 = IEvaluationHandlerFactory.ImplementProjectEvaluationRule("Rule1");
            var handler2 = IEvaluationHandlerFactory.ImplementProjectEvaluationRule("Rule2");

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

            var result = applyChangesToWorkspace.GetProjectEvaluationRules();

            Assert.Equal(new[] { "Rule1", "Rule2" }, result.OrderBy(n => n));
        }
Exemple #6
0
        public async Task ApplyProjectEvaluationAsync_WhenCancellationTokenCancelled_StopsProcessingHandlersAndThrowOperationCanceled()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var handler1 = IEvaluationHandlerFactory.ImplementHandle("RuleName1", (version, description, state, logger) =>
            {
                cancellationTokenSource.Cancel();
            });

            int callCount = 0;
            var handler2  = IEvaluationHandlerFactory.ImplementHandle("RuleName2", (version, description, state, logger) =>
            {
                callCount++;
            });

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

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

            Assert.True(cancellationTokenSource.IsCancellationRequested);
            Assert.Equal(0, callCount);
        }
Exemple #7
0
        public async Task ApplyProjectEvaluationAsync_WhenNoRuleChanges_DoesNotCallHandler()
        {
            int callCount = 0;
            var handler   = IEvaluationHandlerFactory.ImplementHandle("RuleName", (version, description, state, logger) => { callCount++; });

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

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

            await applyChangesToWorkspace.ApplyProjectEvaluationAsync(update, new ContextState(true, false), CancellationToken.None);

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

            var handler1 = IEvaluationHandlerFactory.ImplementHandle("RuleName1", (version, description, isActiveContext, logger) =>
            {
                cancellationTokenSource.Cancel();
            });

            int callCount = 0;
            var handler2  = IEvaluationHandlerFactory.ImplementHandle("RuleName2", (version, description, isActiveContext, logger) =>
            {
                callCount++;
            });

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

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

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

            Assert.True(cancellationTokenSource.IsCancellationRequested);
            Assert.Equal(0, callCount);
        }