@@ -522,6 +522,44 @@ public void VersionCodeTests (bool seperateApk, string abis, string versionCode,
522522 }
523523 }
524524
525+ [ Test ]
526+ [ TestCase ( "1" , false , "manifest=1" ) ]
527+ [ TestCase ( "1" , true , "x86_64=500001;arm64-v8a=400001" ) ]
528+ [ TestCase ( "2" , false , "manifest=2" ) ]
529+ [ TestCase ( "2" , true , "x86_64=500002;arm64-v8a=400002" ) ]
530+ public void ApplicationVersionTests ( string applicationVersion , bool seperateApk , string expected )
531+ {
532+ var proj = new XamarinAndroidApplicationProject ( ) {
533+ IsRelease = true ,
534+ MinSdkVersion = null ,
535+ } ;
536+ proj . SetProperty ( proj . ReleaseProperties , "ApplicationVersion" , applicationVersion ) ;
537+ proj . SetProperty ( proj . ReleaseProperties , "ApplicationDisplayVersion" , applicationVersion ) ;
538+ proj . SetProperty ( proj . ReleaseProperties , KnownProperties . AndroidCreatePackagePerAbi , seperateApk ) ;
539+ proj . AndroidManifest = proj . AndroidManifest
540+ . Replace ( "android:versionCode=\" 1\" " , string . Empty )
541+ . Replace ( "android:versionName=\" 1.0\" " , string . Empty ) ;
542+ using ( var builder = CreateApkBuilder ( ) ) {
543+ Assert . True ( builder . Build ( proj ) , "Build should have succeeded." ) ;
544+ XNamespace aNS = "http://schemas.android.com/apk/res/android" ;
545+
546+ var expectedItems = expected . Split ( ';' ) ;
547+ foreach ( var item in expectedItems ) {
548+ var items = item . Split ( '=' ) ;
549+ var path = seperateApk ? Path . Combine ( "android" , items [ 0 ] , "AndroidManifest.xml" ) : Path . Combine ( "android" , "manifest" , "AndroidManifest.xml" ) ;
550+ var manifest = builder . Output . GetIntermediaryAsText ( Root , path ) ;
551+ var doc = XDocument . Parse ( manifest ) ;
552+ var m = doc . XPathSelectElement ( "/manifest" ) as XElement ;
553+ Assert . IsNotNull ( m , "no manifest element found" ) ;
554+ var vc = m . Attribute ( aNS + "versionCode" ) ;
555+ Assert . IsNotNull ( vc , "no versionCode attribute found" ) ;
556+ StringAssert . AreEqualIgnoringCase ( items [ 1 ] , vc . Value ,
557+ $ "Version Code is incorrect. Found { vc . Value } expect { items [ 1 ] } ") ;
558+ }
559+
560+ }
561+ }
562+
525563 [ Test ]
526564 public void ManifestPlaceholders ( [ Values ( "legacy" , "manifestmerger.jar" ) ] string manifestMerger )
527565 {
0 commit comments