Skip to content

Commit

Permalink
[tests] add test for Microsoft.Intune (#7926)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanpeppers committed Nov 30, 2023
1 parent 9ace5da commit 93b3d00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ public static class KnownPackages
Id = "SkiaSharp.Views",
Version = "2.88.3",
};
public static Package Microsoft_Intune_Maui_Essentials_android = new Package {
Id = "Microsoft.Intune.Maui.Essentials.android",
Version = "10.0.0-beta",
};
}
}

34 changes: 34 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,5 +1170,39 @@ public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease
Assert.IsTrue (didLaunch, "Activity should have started.");
}
}

[Test]
public void MicrosoftIntune ([Values (false, true)] bool isRelease)
{
proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
PackageReferences = {
KnownPackages.AndroidXAppCompat,
KnownPackages.Microsoft_Intune_Maui_Essentials_android,
},
};
proj.MainActivity = proj.DefaultMainActivity
.Replace ("Icon = \"@drawable/icon\")]", "Icon = \"@drawable/icon\", Theme = \"@style/Theme.AppCompat.Light.DarkActionBar\")]")
.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity");
var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" };
proj.SetAndroidSupportedAbis (abis);
builder = CreateApkBuilder ();
builder.BuildLogFile = "install.log";
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");

var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath);
var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex");
FileAssert.Exists (dexFile);
var className = "Lcom/xamarin/microsoftintune/MainActivity;";
var methodName = "onMAMCreate";
Assert.IsTrue (DexUtils.ContainsClassWithMethod (className, methodName, "(Landroid/os/Bundle;)V", dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}` and `{methodName}!");

RunProjectAndAssert (proj, builder);

WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log"));
bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30);
Assert.IsTrue (didLaunch, "Activity should have started.");
}
}
}

0 comments on commit 93b3d00

Please sign in to comment.