Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Azure
* Added the [Get-PartnerAzureBillingAccount](https://docs.microsoft.com/powershell/module/partnercenter/get-partnerazurebillingaccount) command to get billing accounts where the authenticated user has access
* Added the [Get-PartnerAzureBillingProfile](https://docs.microsoft.com/powershell/module/partnercenter/get-partnerazurebillingprofile) to get billing profiles for specified billing account
* Added the [New-PartnerAzureSubscription](https://docs.microsoft.com/powershell/module/partnercenter/new-partnerazuresubscription) to create a new Azure subscription for Microsoft Partner Agreement billing account.
* Added the [New-PartnerAzureSubscription](https://docs.microsoft.com/powershell/module/partnercenter/new-partnerazuresubscription) to create a new Azure subscription for Microsoft Partner Agreement billing account
* Security
* Updated the [Get-PartnerUser](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerProductUpgrade) command to ensure all user accounts are returned
* Updated the [Get-PartnerUserSignActivity](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerUserSignActivity) command to ensure all user sign-in activities are returned
Expand Down
2 changes: 1 addition & 1 deletion src/PowerShell/Commands/ConnectPartnerCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected override void ProcessRecord()
account.SetProperty(PartnerAccountPropertyType.RefreshToken, RefreshToken);
}

account.SetProperty(PartnerAccountPropertyType.ApplicationId, PowerShellApplicationId);
account.SetProperty(PartnerAccountPropertyType.ApplicationId, string.IsNullOrEmpty(ApplicationId) ? PowerShellApplicationId : ApplicationId);

if (ParameterSetName.Equals(AccessTokenParameterSet, StringComparison.InvariantCultureIgnoreCase))
{
Expand Down
4 changes: 2 additions & 2 deletions src/PowerShell/Commands/GetPartnerUserSignInActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ private async Task<List<SignIn>> GetSignInActivitiesAsync(string filter)
client.AuthenticationProvider = new GraphAuthenticationProvider();

IAuditLogRootSignInsCollectionPage data = await client
.AuditLogs.SignIns.Request(queryOptions).GetAsync().ConfigureAwait(false);
.AuditLogs.SignIns.Request(queryOptions).GetAsync(CancellationToken).ConfigureAwait(false);

activities = new List<SignIn>(data.CurrentPage);

while (data.NextPageRequest != null)
{
data = await data.NextPageRequest.GetAsync().ConfigureAwait(false);
data = await data.NextPageRequest.GetAsync(CancellationToken).ConfigureAwait(false);
activities.AddRange(data.CurrentPage);
}

Expand Down
13 changes: 11 additions & 2 deletions src/PowerShell/Factories/SharedTokenCacheClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public static IPublicClientApplication CreatePublicClient(
LogLevel.Info,
enablePiiLogging: false,
enableDefaultPlatformLogging: true).Build();
MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);

MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);
cacheHelper.RegisterCache(client.UserTokenCache);

return client;
Expand All @@ -123,7 +123,16 @@ public static ITokenCache GetTokenCache(string clientId)
{
if (tokenCache == null)
{
IPublicClientApplication client = CreatePublicClient(null, clientId);
PublicClientApplicationBuilder builder = PublicClientApplicationBuilder.Create(clientId);

IPublicClientApplication client = builder.WithLogging(
DebugLoggingMethod,
LogLevel.Info,
enablePiiLogging: false,
enableDefaultPlatformLogging: true).Build();

MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);
cacheHelper.RegisterCache(client.UserTokenCache);

tokenCache = client.UserTokenCache;
}
Expand Down
23 changes: 23 additions & 0 deletions test/PowerShell.UnitTests/Commands/GetPartnerOfferCategoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Commands
{
using VisualStudio.TestTools.UnitTesting;

/// <summary>
/// Unit tests for the Get-PartnerOfferCategory cmdlet.
/// </summary>
[TestClass]
public class GetPartnerOfferCategoryTests : TestBase
{
/// <summary>
/// Unit test for the Get-PartnerOfferCategory cmdlet.
/// </summary>
[TestMethod]
public void GetPartnerOfferCategory()
{
RunPowerShellTest("Test-GetPartnerOfferCategory");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Commands
using VisualStudio.TestTools.UnitTesting;

/// <summary>
/// Unit tests for the commands related to offers.
/// Unit tests for the Get-PartnerOffer cmdlet.
/// </summary>
[TestClass]
public class OfferTests : TestBase
public class GetPartnerOfferTests : TestBase
{
/// <summary>
/// Unit test for the Get-PartnerOffer cmdlet.
Expand Down
42 changes: 34 additions & 8 deletions test/PowerShell.UnitTests/Factories/MockClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Factories
{
using Microsoft.Graph;
using Microsoft.Rest;
using System;
using Graph;
using Network;
using PowerShell.Factories;
using PowerShell.Network;
using Rest;

/// <summary>
/// Factory that provides initialized clients used to mock interactions with online services.
Expand All @@ -23,6 +25,11 @@ public class MockClientFactory : IClientFactory
/// </summary>
private readonly IPartnerCredentials credentials;

/// <summary>
/// Provides the ability to interact with Microsoft Graph.
/// </summary>
private static IGraphServiceClient graphServiceClient;

/// <summary>
/// Provides the ability to interact with the partner service.
/// </summary>
Expand All @@ -39,6 +46,23 @@ public MockClientFactory(HttpMockHandler httpMockHandler, IPartnerCredentials cr
this.httpMockHandler = httpMockHandler;
}

/// <summary>
/// Creates a new instance of the Microsoft Graph service client.
/// </summary>
/// <returns>An instance of the <see cref="Graph.GraphServiceClient"/> class.</returns>
public IGraphServiceClient CreateGraphServiceClient()
{
if (graphServiceClient == null)
{
graphServiceClient = new GraphServiceClient(null, new HttpProvider(new CancelRetryHandler(3, TimeSpan.FromSeconds(10))
{
InnerHandler = httpMockHandler
}, false, null));
}

return graphServiceClient;
}

/// <summary>
/// Creates a new instance of the object used to interface with Partner Center.
/// </summary>
Expand All @@ -55,14 +79,16 @@ public IPartner CreatePartnerOperations()
return partnerOperations;
}

public IGraphServiceClient CreateGraphServiceClient()
{
throw new System.NotImplementedException();
}

/// <summary>
/// Creates a new service client used interact with a specific service.
/// </summary>
/// <typeparam name="TClient">Type of service client being created.</typeparam>
/// <param name="scopes">Scopes requested to access a protected service.</param>
/// <param name="tenantId">The identifier for the tenant.</param>
/// <returns>An instance of a service client that is connected to a specific service.</returns>
public TClient CreateServiceClient<TClient>(string[] scopes, string tenantId = null) where TClient : ServiceClient<TClient>
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
}
}
3 changes: 3 additions & 0 deletions test/PowerShell.UnitTests/PowerShell.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<Reference Include="Microsoft.Graph.Beta">
<HintPath>..\..\src\lib\Microsoft.Graph.Beta.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Graph.Core">
<HintPath>..\..\src\lib\Microsoft.Graph.Core.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<#
.SYNOPSIS
Tests to be performed using the Get-PartnerOfferCategory cmdlet.
#>
function Test-GetPartnerOfferCategory
{
$categories = Get-PartnerOfferCategory -CountryCode 'US'

Assert-NotNull $categories
}
3 changes: 2 additions & 1 deletion test/PowerShell.UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests
using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation;
using System.Net.Http;
using System.Reflection;
using Factories;
using Network;
Expand All @@ -20,7 +21,7 @@ public abstract class TestBase
/// <summary>
/// Delegating handler used to intercept partner service client operations.
/// </summary>
private static readonly HttpMockHandler httpMockHandler = new HttpMockHandler(HttpMockHandlerMode.Playback);
private static readonly HttpMockHandler httpMockHandler = new HttpMockHandler(HttpMockHandlerMode.Playback) { InnerHandler = new HttpClientHandler() };

/// <summary>
/// Initializes a new instance of the <see cref="TestBase" /> class.
Expand Down