-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
tests/WingetIntune.Tests/GraphExtensions/MobileAppsRequestBuilderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using Microsoft.Graph.Beta; | ||
using Microsoft.Graph.Beta.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WingetIntune.GraphExtensions; | ||
|
||
namespace WingetIntune.Tests.GraphExtensions; | ||
public class MobileAppsRequestBuilderExtensionsTests | ||
{ | ||
[Fact] | ||
public async Task DeviceAppManagement_MobileApps_PostAsync_MakesCorrectRequest() | ||
{ | ||
var appId = Guid.NewGuid().ToString(); | ||
var token = Guid.NewGuid().ToString(); | ||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
|
||
var app = new Win32LobApp | ||
{ | ||
DisplayName = "Test App", | ||
Publisher = "Test Publisher", | ||
IsFeatured = true, | ||
}; | ||
|
||
var response = new HttpResponseMessage(HttpStatusCode.Created); | ||
response.Content = new StringContent(win32LobAppResult); | ||
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); | ||
|
||
handlerMock.AddMockResponse( | ||
$"https://graph.microsoft.com/beta/deviceAppManagement/mobileApps", | ||
HttpMethod.Post, | ||
@"{""@odata.type"":""#microsoft.graph.win32LobApp"",""displayName"":""Test App"",""isFeatured"":true,""publisher"":""Test Publisher""}", | ||
response); | ||
|
||
var httpClient = new HttpClient(handlerMock.Object); | ||
var graphServiceClient = new GraphServiceClient(httpClient, new Internal.Msal.StaticAuthenticationProvider(token)); | ||
|
||
var result = await graphServiceClient.DeviceAppManagement.MobileApps.PostAsync(app, cancellationToken: default); | ||
Assert.Equal("9607b530-b530-9607-30b5-079630b50796", result!.Id); | ||
} | ||
|
||
[Fact] | ||
public async Task DeviceAppManagement_MobileApps_PatchAsync_MakesCorrectRequest() | ||
{ | ||
var token = Guid.NewGuid().ToString(); | ||
|
||
var appId = "9607b530-b530-9607-30b5-079630b50796"; | ||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
|
||
|
||
|
||
var response = new HttpResponseMessage(HttpStatusCode.OK); | ||
response.Content = new StringContent(win32LobAppResult); | ||
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); | ||
|
||
handlerMock.AddMockResponse( | ||
$"https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{appId}", | ||
HttpMethod.Patch, | ||
@"{""@odata.type"":""#microsoft.graph.win32LobApp"",""committedContentVersion"":""1""}", | ||
response); | ||
|
||
var httpClient = new HttpClient(handlerMock.Object); | ||
var graphServiceClient = new GraphServiceClient(httpClient, new Internal.Msal.StaticAuthenticationProvider(token)); | ||
|
||
var result = await graphServiceClient.DeviceAppManagement.MobileApps[appId].PatchAsync(new Win32LobApp { CommittedContentVersion = "1" }, cancellationToken: default); | ||
Assert.Equal("9607b530-b530-9607-30b5-079630b50796", result!.Id); | ||
} | ||
|
||
private const string win32LobAppResult = @"{ | ||
""@odata.type"": ""#microsoft.graph.win32LobApp"", | ||
""id"": ""9607b530-b530-9607-30b5-079630b50796"", | ||
""displayName"": ""Display Name value"", | ||
""description"": ""Description value"", | ||
""publisher"": ""Publisher value"", | ||
""largeIcon"": { | ||
""@odata.type"": ""microsoft.graph.mimeContent"", | ||
""type"": ""Type value"", | ||
""value"": ""dmFsdWU="" | ||
}, | ||
""createdDateTime"": ""2017-01-01T00:02:43.5775965-08:00"", | ||
""lastModifiedDateTime"": ""2017-01-01T00:00:35.1329464-08:00"", | ||
""isFeatured"": true, | ||
""privacyInformationUrl"": ""https://example.com/privacyInformationUrl/"", | ||
""informationUrl"": ""https://example.com/informationUrl/"", | ||
""owner"": ""Owner value"", | ||
""developer"": ""Developer value"", | ||
""notes"": ""Notes value"", | ||
""publishingState"": ""processing"", | ||
""committedContentVersion"": ""Committed Content Version value"", | ||
""fileName"": ""File Name value"", | ||
""size"": 4, | ||
""installCommandLine"": ""Install Command Line value"", | ||
""uninstallCommandLine"": ""Uninstall Command Line value"", | ||
""applicableArchitectures"": ""x86"", | ||
""minimumFreeDiskSpaceInMB"": 8, | ||
""minimumMemoryInMB"": 1, | ||
""minimumNumberOfProcessors"": 9, | ||
""minimumCpuSpeedInMHz"": 4, | ||
""rules"": [ | ||
{ | ||
""@odata.type"": ""microsoft.graph.win32LobAppRegistryRule"", | ||
""ruleType"": ""requirement"", | ||
""check32BitOn64System"": true, | ||
""keyPath"": ""Key Path value"", | ||
""valueName"": ""Value Name value"", | ||
""operationType"": ""exists"", | ||
""operator"": ""equal"", | ||
""comparisonValue"": ""Comparison Value value"" | ||
} | ||
], | ||
""installExperience"": { | ||
""@odata.type"": ""microsoft.graph.win32LobAppInstallExperience"", | ||
""runAsAccount"": ""user"", | ||
""deviceRestartBehavior"": ""allow"" | ||
}, | ||
""returnCodes"": [ | ||
{ | ||
""@odata.type"": ""microsoft.graph.win32LobAppReturnCode"", | ||
""returnCode"": 10, | ||
""type"": ""success"" | ||
} | ||
], | ||
""msiInformation"": { | ||
""@odata.type"": ""microsoft.graph.win32LobAppMsiInformation"", | ||
""productCode"": ""Product Code value"", | ||
""productVersion"": ""Product Version value"", | ||
""upgradeCode"": ""Upgrade Code value"", | ||
""requiresReboot"": true, | ||
""packageType"": ""perUser"", | ||
""productName"": ""Product Name value"", | ||
""publisher"": ""Publisher value"" | ||
}, | ||
""setupFilePath"": ""Setup File Path value"", | ||
""minimumSupportedWindowsRelease"": ""Minimum Supported Windows Release value"" | ||
}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters