import * as path from 'path' ; import * as vscode from 'vscode' ; import { FuncVersion , funcVersionSetting , ProjectLanguage , projectLanguageSetting , TemplateSource } from '../../extension.bundle' ; import { allTemplateSources , shouldSkipVersion } from '../global.test' ; import { getDotnetScriptValidateOptions , validateProject } from '../project/validateProject' ; import { runWithFuncSetting } from '../runWithSetting' ; import { FunctionTesterBase } from './FunctionTesterBase' ; class CSharpScriptFunctionTester extends FunctionTesterBase { public language : ProjectLanguage = ProjectLanguage . CSharpScript ; public constructor ( source ) { super ( FuncVersion . v1 , source ) ; } public getExpectedPaths ( functionName ) { return [ path . join ( functionName , 'function.json' ) , path . join ( functionName , 'run.csx' ) ] ; } } for ( const source of allTemplateSources ) { const tester = new CSharpScriptFunctionTester ( source ) ; suite ( tester . suiteName , function ( this ) : void { suiteSetup ( async function ( this ) : Promise < void > { if ( shouldSkipVersion ( tester . version ) ) { this . skip ( ) ; } await tester . initAsync ( ) ; } ) ; suiteTeardown ( async ( ) => { if ( ! shouldSkipVersion ( tester . version ) ) { await tester . dispose ( ) ; } } ) ; const iotTemplateId = 'IoTHubTrigger-CSharp' ; const iotFunctionName = 'createFunctionApi' ; const iotConnection = 'test_EVENTHUB' ; const iotPath = 'test-workitems' ; const iotConsumerGroup = 'testconsumergroup' ; const iotTriggerSettings = { connection : iotConnection , path : iotPath , consumerGroup : iotConsumerGroup } ; const iotExpectedContents = [ iotConnection , iotPath , iotConsumerGroup ] ; test ( 'createFunction API (deprecated)' , async ( ) => { await runWithFuncSetting ( projectLanguageSetting , ProjectLanguage . CSharpScript , async ( ) => { await runWithFuncSetting ( funcVersionSetting , FuncVersion . v1 , async ( ) => { await vscode . commands . executeCommand ( 'azureFunctions.createFunction' , tester . projectPath , iotTemplateId , iotFunctionName , iotTriggerSettings ) ; } ) ; } ) ; await tester . validateFunction ( tester . projectPath , iotFunctionName , iotExpectedContents ) ; } ) ; test ( 'createNewProjectAndFunction API (deprecated)' , async ( ) => { const projectPath = path . join ( tester . projectPath , 'createNewProjectAndFunction' ) ; await vscode . commands . executeCommand ( 'azureFunctions.createNewProject' , projectPath , 'C#Script' , '~1' , false , iotTemplateId , iotFunctionName , iotTriggerSettings ) ; await tester . validateFunction ( projectPath , iotFunctionName , iotExpectedContents ) ; await validateProject ( projectPath , getDotnetScriptValidateOptions ( ProjectLanguage . CSharpScript , FuncVersion . v1 ) ) ; } ) ; } ) ; }