Skip to content

Commit

Permalink
Even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svrooij committed Aug 14, 2023
1 parent 73181cb commit 2306aae
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: 📝 Code Coverage report
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.1.23
reportgenerator -reports:${{github.workspace}}/coverage.cobertura.xml -targetdir:${{github.workspace}}/report -reporttypes:MarkdownSummaryGithub -filefilters:-*.g.cs -verbosity:Warning
reportgenerator -reports:${{github.workspace}}/coverage.cobertura.xml -targetdir:${{github.workspace}}/report -reporttypes:MarkdownSummaryGithub -filefilters:-*.g.cs -classfilters:-WixSharp.*;-WingetIntune.Os.* -verbosity:Warning
sed -i 's/# Summary/## 📝 Code Coverage/g' ${{github.workspace}}/report/SummaryGithub.md
sed -i 's/## Coverage/### 📝 Code Coverage details/g' ${{github.workspace}}/report/SummaryGithub.md
cat ${{github.workspace}}/report/*.md >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion src/WingetIntune/Implementations/DefaultFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;

namespace WingetIntune;
namespace WingetIntune.Os;

public partial class DefaultFileManager : IFileManager
{
Expand Down
2 changes: 1 addition & 1 deletion src/WingetIntune/Implementations/ProcessManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging;
using System.Text;

namespace WingetIntune;
namespace WingetIntune.Os;

public partial class ProcessManager : IProcessManager
{
Expand Down
4 changes: 2 additions & 2 deletions src/WingetIntune/WingetServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public static class WingetServiceCollectionExtension
{
public static IServiceCollection AddWingetServices(this IServiceCollection services)
{
services.AddHttpClient<IFileManager, DefaultFileManager>();
services.AddTransient<IProcessManager, ProcessManager>();
services.AddHttpClient<IFileManager, Os.DefaultFileManager>();
services.AddTransient<IProcessManager, Os.ProcessManager>();
services.AddTransient<IWingetRepository, WingetManager>();
services.AddHttpClient<IntuneManager>();
services.AddTransient<IAzureFileUploader, AzCopyAzureUploader>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Net;
using WingetIntune.GraphExtensions;

namespace WingetIntune.Tests;
namespace WingetIntune.Tests.GraphExtensions;

public class GraphServiceExtensionsTests
{
Expand Down
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""
}";
}
10 changes: 9 additions & 1 deletion tests/WingetIntune.Tests/WingetIntune.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -10,6 +10,14 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;CS8625</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;CS8625</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
Expand Down

0 comments on commit 2306aae

Please sign in to comment.