Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 2de4e1e

Browse files
author
Isaiah Williams
authored
Updating the structure of the unit test project (#206)
1 parent e43d862 commit 2de4e1e

12 files changed

Lines changed: 90 additions & 17 deletions

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Azure
3737
* Added the [Get-PartnerAzureBillingAccount](https://docs.microsoft.com/powershell/module/partnercenter/get-partnerazurebillingaccount) command to get billing accounts where the authenticated user has access
3838
* Added the [Get-PartnerAzureBillingProfile](https://docs.microsoft.com/powershell/module/partnercenter/get-partnerazurebillingprofile) to get billing profiles for specified billing account
39-
* 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.
39+
* 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
4040
* Security
4141
* Updated the [Get-PartnerUser](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerProductUpgrade) command to ensure all user accounts are returned
4242
* Updated the [Get-PartnerUserSignActivity](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerUserSignActivity) command to ensure all user sign-in activities are returned

src/PowerShell/Commands/ConnectPartnerCenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected override void ProcessRecord()
187187
account.SetProperty(PartnerAccountPropertyType.RefreshToken, RefreshToken);
188188
}
189189

190-
account.SetProperty(PartnerAccountPropertyType.ApplicationId, PowerShellApplicationId);
190+
account.SetProperty(PartnerAccountPropertyType.ApplicationId, string.IsNullOrEmpty(ApplicationId) ? PowerShellApplicationId : ApplicationId);
191191

192192
if (ParameterSetName.Equals(AccessTokenParameterSet, StringComparison.InvariantCultureIgnoreCase))
193193
{

src/PowerShell/Commands/GetPartnerUserSignInActivity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ private async Task<List<SignIn>> GetSignInActivitiesAsync(string filter)
7979
client.AuthenticationProvider = new GraphAuthenticationProvider();
8080

8181
IAuditLogRootSignInsCollectionPage data = await client
82-
.AuditLogs.SignIns.Request(queryOptions).GetAsync().ConfigureAwait(false);
82+
.AuditLogs.SignIns.Request(queryOptions).GetAsync(CancellationToken).ConfigureAwait(false);
8383

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

8686
while (data.NextPageRequest != null)
8787
{
88-
data = await data.NextPageRequest.GetAsync().ConfigureAwait(false);
88+
data = await data.NextPageRequest.GetAsync(CancellationToken).ConfigureAwait(false);
8989
activities.AddRange(data.CurrentPage);
9090
}
9191

src/PowerShell/Factories/SharedTokenCacheClientFactory.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public static IPublicClientApplication CreatePublicClient(
112112
LogLevel.Info,
113113
enablePiiLogging: false,
114114
enableDefaultPlatformLogging: true).Build();
115-
MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);
116115

116+
MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);
117117
cacheHelper.RegisterCache(client.UserTokenCache);
118118

119119
return client;
@@ -123,7 +123,16 @@ public static ITokenCache GetTokenCache(string clientId)
123123
{
124124
if (tokenCache == null)
125125
{
126-
IPublicClientApplication client = CreatePublicClient(null, clientId);
126+
PublicClientApplicationBuilder builder = PublicClientApplicationBuilder.Create(clientId);
127+
128+
IPublicClientApplication client = builder.WithLogging(
129+
DebugLoggingMethod,
130+
LogLevel.Info,
131+
enablePiiLogging: false,
132+
enableDefaultPlatformLogging: true).Build();
133+
134+
MsalCacheHelper cacheHelper = InitializeCacheHelper(clientId);
135+
cacheHelper.RegisterCache(client.UserTokenCache);
127136

128137
tokenCache = client.UserTokenCache;
129138
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Commands
5+
{
6+
using VisualStudio.TestTools.UnitTesting;
7+
8+
/// <summary>
9+
/// Unit tests for the Get-PartnerOfferCategory cmdlet.
10+
/// </summary>
11+
[TestClass]
12+
public class GetPartnerOfferCategoryTests : TestBase
13+
{
14+
/// <summary>
15+
/// Unit test for the Get-PartnerOfferCategory cmdlet.
16+
/// </summary>
17+
[TestMethod]
18+
public void GetPartnerOfferCategory()
19+
{
20+
RunPowerShellTest("Test-GetPartnerOfferCategory");
21+
}
22+
}
23+
}

test/PowerShell.UnitTests/Commands/OfferTests.cs renamed to test/PowerShell.UnitTests/Commands/GetPartnerOfferTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Commands
66
using VisualStudio.TestTools.UnitTesting;
77

88
/// <summary>
9-
/// Unit tests for the commands related to offers.
9+
/// Unit tests for the Get-PartnerOffer cmdlet.
1010
/// </summary>
1111
[TestClass]
12-
public class OfferTests : TestBase
12+
public class GetPartnerOfferTests : TestBase
1313
{
1414
/// <summary>
1515
/// Unit test for the Get-PartnerOffer cmdlet.

test/PowerShell.UnitTests/Factories/MockClientFactory.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
namespace Microsoft.Store.PartnerCenter.PowerShell.UnitTests.Factories
55
{
6-
using Microsoft.Graph;
7-
using Microsoft.Rest;
6+
using System;
7+
using Graph;
88
using Network;
99
using PowerShell.Factories;
10+
using PowerShell.Network;
11+
using Rest;
1012

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

28+
/// <summary>
29+
/// Provides the ability to interact with Microsoft Graph.
30+
/// </summary>
31+
private static IGraphServiceClient graphServiceClient;
32+
2633
/// <summary>
2734
/// Provides the ability to interact with the partner service.
2835
/// </summary>
@@ -39,6 +46,23 @@ public MockClientFactory(HttpMockHandler httpMockHandler, IPartnerCredentials cr
3946
this.httpMockHandler = httpMockHandler;
4047
}
4148

49+
/// <summary>
50+
/// Creates a new instance of the Microsoft Graph service client.
51+
/// </summary>
52+
/// <returns>An instance of the <see cref="Graph.GraphServiceClient"/> class.</returns>
53+
public IGraphServiceClient CreateGraphServiceClient()
54+
{
55+
if (graphServiceClient == null)
56+
{
57+
graphServiceClient = new GraphServiceClient(null, new HttpProvider(new CancelRetryHandler(3, TimeSpan.FromSeconds(10))
58+
{
59+
InnerHandler = httpMockHandler
60+
}, false, null));
61+
}
62+
63+
return graphServiceClient;
64+
}
65+
4266
/// <summary>
4367
/// Creates a new instance of the object used to interface with Partner Center.
4468
/// </summary>
@@ -55,14 +79,16 @@ public IPartner CreatePartnerOperations()
5579
return partnerOperations;
5680
}
5781

58-
public IGraphServiceClient CreateGraphServiceClient()
59-
{
60-
throw new System.NotImplementedException();
61-
}
62-
82+
/// <summary>
83+
/// Creates a new service client used interact with a specific service.
84+
/// </summary>
85+
/// <typeparam name="TClient">Type of service client being created.</typeparam>
86+
/// <param name="scopes">Scopes requested to access a protected service.</param>
87+
/// <param name="tenantId">The identifier for the tenant.</param>
88+
/// <returns>An instance of a service client that is connected to a specific service.</returns>
6389
public TClient CreateServiceClient<TClient>(string[] scopes, string tenantId = null) where TClient : ServiceClient<TClient>
6490
{
65-
throw new System.NotImplementedException();
91+
throw new NotImplementedException();
6692
}
6793
}
6894
}

test/PowerShell.UnitTests/PowerShell.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<Reference Include="Microsoft.Graph.Beta">
3535
<HintPath>..\..\src\lib\Microsoft.Graph.Beta.dll</HintPath>
3636
</Reference>
37+
<Reference Include="Microsoft.Graph.Core">
38+
<HintPath>..\..\src\lib\Microsoft.Graph.Core.dll</HintPath>
39+
</Reference>
3740
</ItemGroup>
3841

3942
<ItemGroup>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<#
2+
.SYNOPSIS
3+
Tests to be performed using the Get-PartnerOfferCategory cmdlet.
4+
#>
5+
function Test-GetPartnerOfferCategory
6+
{
7+
$categories = Get-PartnerOfferCategory -CountryCode 'US'
8+
9+
Assert-NotNull $categories
10+
}

0 commit comments

Comments
 (0)