Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Feb 8, 2024
1 parent 84c2911 commit 8b13954
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -172,5 +172,45 @@ public void CanGetAppTheme ()

Assert.AreEqual ("@android:style/Theme.Material.Light", manifest.ApplicationTheme);
}

[Test]
public void CanAddAndRemoveUsesSdk ()
{
XNamespace aNS = "http://schemas.android.com/apk/res/android";
var versions = new AndroidVersions (new AndroidVersion [0]);
var doc = XDocument.Parse (@"
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"" package=""com.xamarin.Foo"">
<uses-sdk android:minSdkVersion=""8"" android:targetSdkVersion=""12"" />
<application android:label=""Foo"" android:icon=""@drawable/ic_icon"" android:theme=""@android:style/Theme.Material.Light"">
</application>
</manifest>");
var manifest = AndroidAppManifest.Load (doc, versions);

manifest.MinSdkVersion = null;
manifest.TargetSdkVersion = null;

var sb = new StringBuilder ();
using (var writer = XmlWriter.Create (sb)) {
manifest.Write (writer);
}

var newDoc = XDocument.Parse (sb.ToString ());
var usesSdk = newDoc.Element ("manifest").Element ("uses-sdk");
Assert.IsNull (usesSdk, "uses-sdk should not exist");

manifest.MinSdkVersion = 8;
manifest.TargetSdkVersion = 12;

sb = new StringBuilder ();
using (var writer = XmlWriter.Create (sb)) {
manifest.Write (writer);
}

newDoc = XDocument.Parse (sb.ToString ());
usesSdk = newDoc.Element ("manifest").Element ("uses-sdk");
Assert.IsNotNull (usesSdk, "uses-sdk should exist");
Assert.AreEqual ("8", usesSdk.Attribute (aNS + "minSdkVersion").Value);
Assert.AreEqual ("12", usesSdk.Attribute (aNS + "targetSdkVersion").Value);
}
}
}

0 comments on commit 8b13954

Please sign in to comment.