-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
Adds a new unit test for `GraphStoreAppUploader` in `GraphStoreAppUploaderTests.cs` to verify the functionality of creating a Microsoft Store app in Intune using a specific package ID. - Implements a test method `CreateStoreAppAsync_WithValidPackageId_CreatesAppSuccessfully` that mocks dependencies such as `GraphServiceClient`, `IFileManager`, and `Internal.MsStore.MicrosoftStoreClient` to simulate the app creation process. - Verifies that the `CreateStoreAppAsync` method correctly interacts with mocked services to create an app with expected properties based on a given package ID. - Ensures that the method handles the app creation process, including downloading the app icon and logging the appropriate information. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/svrooij/WingetIntune/pull/59?shareId=6768da5b-994f-483e-b903-95394dd61bf2).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Graph.Beta; | ||
using NSubstitute; | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using WingetIntune.Graph; | ||
using WingetIntune.Models; | ||
using Xunit; | ||
|
||
namespace WingetIntune.Tests.Graph; | ||
|
||
public class GraphStoreAppUploaderTests | ||
{ | ||
private readonly ILogger<GraphStoreAppUploader> _logger; | ||
private readonly IFileManager _fileManager; | ||
private readonly Internal.MsStore.MicrosoftStoreClient _microsoftStoreClient; | ||
private readonly GraphServiceClient _graphServiceClient; | ||
private readonly GraphStoreAppUploader _graphStoreAppUploader; | ||
|
||
public GraphStoreAppUploaderTests() | ||
{ | ||
_logger = Substitute.For<ILogger<GraphStoreAppUploader>>(); | ||
_fileManager = Substitute.For<IFileManager>(); | ||
_microsoftStoreClient = Substitute.For<Internal.MsStore.MicrosoftStoreClient>(Substitute.For<HttpClient>(), _logger); | ||
_graphServiceClient = Substitute.For<GraphServiceClient>(Substitute.For<HttpClient>(), Substitute.For<IAuthenticationProvider>()); | ||
Check failure on line 27 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
Check failure on line 27 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
_graphStoreAppUploader = new GraphStoreAppUploader(_logger, _fileManager, _microsoftStoreClient); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateStoreAppAsync_WithValidPackageId_CreatesAppSuccessfully() | ||
{ | ||
// Arrange | ||
var packageId = "9NZVDKPMR9RD"; | ||
var cancellationToken = CancellationToken.None; | ||
var expectedApp = new WinGetApp | ||
Check failure on line 37 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
Check failure on line 37 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
{ | ||
DisplayName = "Test App", | ||
Publisher = "Test Publisher", | ||
Description = "Test Description", | ||
PackageIdentifier = packageId, | ||
Id = Guid.NewGuid().ToString() | ||
}; | ||
|
||
_microsoftStoreClient.GetDisplayCatalogAsync(packageId, cancellationToken).Returns(Task.FromResult(new DisplayCatalogResponse | ||
Check failure on line 46 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
Check failure on line 46 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
{ | ||
Products = new[] | ||
{ | ||
new Product | ||
Check failure on line 50 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
{ | ||
ProductId = packageId, | ||
LocalizedProperties = new[] | ||
{ | ||
new LocalizedProperty | ||
Check failure on line 55 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
{ | ||
PublisherName = "Test Publisher", | ||
DeveloperName = "Test Developer", | ||
ProductTitle = "Test App", | ||
ShortDescription = "Test Description", | ||
Images = new[] | ||
{ | ||
new Image | ||
Check failure on line 63 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
{ | ||
Uri = "/test/image.png", | ||
Height = 300, | ||
Width = 300 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
})); | ||
|
||
_graphServiceClient.DeviceAppManagement.MobileApps.PostAsync(Arg.Any<WinGetApp>(), cancellationToken).Returns(Task.FromResult(expectedApp)); | ||
Check failure on line 76 in tests/WingetIntune.Tests/Graph/GraphStoreAppUploaderTests.cs GitHub Actions / 🛠️ Build and Test
|
||
|
||
// Act | ||
var result = await _graphStoreAppUploader.CreateStoreAppAsync(_graphServiceClient, packageId, cancellationToken); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Equal(expectedApp.DisplayName, result.DisplayName); | ||
Assert.Equal(expectedApp.Publisher, result.Publisher); | ||
Assert.Equal(expectedApp.Description, result.Description); | ||
Assert.Equal(expectedApp.PackageIdentifier, result.PackageIdentifier); | ||
Assert.Equal(expectedApp.Id, result.Id); | ||
} | ||
} |