Skip to content

Commit 93b3d00

Browse files
[tests] add test for Microsoft.Intune (#7926)
Context: https://www.nuget.org/packages/Microsoft.Intune.Maui.Essentials.android/9.5.2-beta The `Microsoft.Intune.Maui.Essentials.android` makes use of specific MSBuild targets and "remapping" features. We should add a test verifying that it stays working over time. Assert `MainActivity.onMAMCreate` exists in `classes.dex`, to verify this package actually "does something". Otherwise, the test would just pass if we removed the Intune package.
1 parent 9ace5da commit 93b3d00

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ public static class KnownPackages
592592
Id = "SkiaSharp.Views",
593593
Version = "2.88.3",
594594
};
595+
public static Package Microsoft_Intune_Maui_Essentials_android = new Package {
596+
Id = "Microsoft.Intune.Maui.Essentials.android",
597+
Version = "10.0.0-beta",
598+
};
595599
}
596600
}
597601

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,5 +1170,39 @@ public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease
11701170
Assert.IsTrue (didLaunch, "Activity should have started.");
11711171
}
11721172
}
1173+
1174+
[Test]
1175+
public void MicrosoftIntune ([Values (false, true)] bool isRelease)
1176+
{
1177+
proj = new XamarinAndroidApplicationProject {
1178+
IsRelease = isRelease,
1179+
PackageReferences = {
1180+
KnownPackages.AndroidXAppCompat,
1181+
KnownPackages.Microsoft_Intune_Maui_Essentials_android,
1182+
},
1183+
};
1184+
proj.MainActivity = proj.DefaultMainActivity
1185+
.Replace ("Icon = \"@drawable/icon\")]", "Icon = \"@drawable/icon\", Theme = \"@style/Theme.AppCompat.Light.DarkActionBar\")]")
1186+
.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity");
1187+
var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" };
1188+
proj.SetAndroidSupportedAbis (abis);
1189+
builder = CreateApkBuilder ();
1190+
builder.BuildLogFile = "install.log";
1191+
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
1192+
1193+
var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
1194+
var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex");
1195+
FileAssert.Exists (dexFile);
1196+
var className = "Lcom/xamarin/microsoftintune/MainActivity;";
1197+
var methodName = "onMAMCreate";
1198+
Assert.IsTrue (DexUtils.ContainsClassWithMethod (className, methodName, "(Landroid/os/Bundle;)V", dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}` and `{methodName}!");
1199+
1200+
RunProjectAndAssert (proj, builder);
1201+
1202+
WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log"));
1203+
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
1204+
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
1205+
Assert.IsTrue (didLaunch, "Activity should have started.");
1206+
}
11731207
}
11741208
}

0 commit comments

Comments
 (0)