import fs = require ( 'fs' ) ; import iconv = require ( 'iconv-lite' ) ; import xml2js = require ( 'xml2js' ) ; export class TestUtils { static getLine ( stdout , start ) { const startIndex = stdout . indexOf ( start ) ; const endIndex = stdout . indexOf ( '\n' , startIndex ) ; return stdout . substring ( startIndex , endIndex ) ; } static getAssemblyInfoValue ( filePath , propName ) { let _value = '' ; const fileContent = iconv . decode ( fs . readFileSync ( filePath ) , 'utf-8' ) ; const parser = new xml2js . Parser ( ) ; parser . parseString ( fileContent , ( err , result ) => { let group = this . getPropertyGroup ( result . Project . PropertyGroup , propName ) ; const propValue = Reflect . get ( group , propName ) as string [ ] ; if ( propValue && propValue . length > 0 ) { _value = propValue [ 0 ] ; } } ) ; return _value ; } static elementExists ( filePath , propName ) { let _value = false ; const fileContent = iconv . decode ( fs . readFileSync ( filePath ) , 'utf-8' ) ; const parser = new xml2js . Parser ( ) ; parser . parseString ( fileContent , ( err , result ) => { let group = this . getPropertyGroup ( result . Project . PropertyGroup , propName ) ; const propValue = Reflect . get ( group , propName ) as string [ ] ; if ( propValue && propValue . length > 0 ) { _value = true ; } } ) ; return _value ; } private static getPropertyGroup ( propertyGroups , name ) { for ( const group of propertyGroups ) { let keys = Object . keys ( group ) ; for ( const key of keys ) { if ( key . toLowerCase ( ) === name . toLowerCase ( ) ) { return group ; } } } return propertyGroups [ 0 ] ; } }