Beispiel #1
0
        public async Task GetCompilationResultAsync_WithPositivePredicate_ExecutesServiceCompilation()
        {
            var settingsManager             = new ScriptSettingsManager();
            var innerCompilationServiceMock = new Mock <ICompilationService <IJavaScriptCompilation> >();

            innerCompilationServiceMock.Setup(m => m.GetFunctionCompilationAsync(It.IsAny <FunctionMetadata>()))
            .ReturnsAsync(new TestJavaScriptCompilation("test", ImmutableArray <Diagnostic> .Empty));

            var compilationService = new ConditionalJavaScriptCompilationService(settingsManager, innerCompilationServiceMock.Object, () => true);
            var functionMetadata   = new FunctionMetadata
            {
                Name       = "testfunction",
                ScriptFile = "test.ts"
            };

            IJavaScriptCompilation compilation = await compilationService.GetFunctionCompilationAsync(functionMetadata);

            Assert.NotNull(compilation);

            string result = await compilation.EmitAsync(CancellationToken.None);

            Assert.Equal("test", result);

            innerCompilationServiceMock.Verify();
        }
Beispiel #2
0
        public (Mock <ICompilationService <IJavaScriptCompilation> > CompilationServiceMock, ConditionalJavaScriptCompilationService Service) CreateTestData(Func <bool> predicate)
        {
            var settingsManager             = new ScriptSettingsManager();
            var innerCompilationServiceMock = new Mock <ICompilationService <IJavaScriptCompilation> >();
            var compilationService          = new ConditionalJavaScriptCompilationService(settingsManager, innerCompilationServiceMock.Object, predicate);

            return(innerCompilationServiceMock, compilationService);
        }