Skip to content
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
18 changes: 18 additions & 0 deletions src/Marketplace/Marketplace.Test/Marketplace.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Marketplace</PsModuleName>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />


<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Marketplace" Version="1.0.1" />
</ItemGroup>

<PropertyGroup>
<RootNamespace>Microsoft.Azure.Commands.Marketplace.Test</RootNamespace>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions src/Marketplace/Marketplace.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Validates property count of a custom object
#>
function Assert-PropertiesCount
{
param([PSCustomObject] $obj, [int] $count)

$properties = $obj.PSObject.Properties
Assert-AreEqual $([System.Linq.Enumerable]::ToArray($properties).Count) $count
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Marketplace.Test.ScenarioTests
{
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

public class PrivateStoreTests
{
private readonly XunitTracingInterceptor _logger;

public PrivateStoreTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetPrivateStores()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAzMarketplacePrivateStore");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetPrivateStoreOffers()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAzMarketplacePrivateStoreOffers");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetPrivateStoreOffer()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAzMarketplacePrivateStoreOffer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRemovePrivateStoreOffer()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RemoveAzMarketplacePrivateStoreOffer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreatePrivateStoreOffer()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateAzMarketplacePrivateStoreOffer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdatePrivateStoreOffer()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateAzMarketplacePrivateStoreOffer");
}
}
}
145 changes: 145 additions & 0 deletions src/Marketplace/Marketplace.Test/ScenarioTests/PrivateStoreTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Gets private stores that were defined in tenant level
#>
function Test-GetAzMarketplacePrivateStore
{
$propertiesCount=6
$AvailabilityValue="enabled"
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"

$queryResult = Get-AzMarketplacePrivateStore

Assert-NotNull $queryResult
Assert-AreEqual $queryResult.Count 1

for ($i = 0; $i -lt $queryResult.Count; $i++)
{
Assert-PropertiesCount $queryResult[$i] $propertiesCount
Assert-AreEqual $queryResult[$i].Availability $AvailabilityValue
Assert-AreEqual $queryResult[$i].PrivateStoreId $PrivateStoreIdValue
}
}

<#
.SYNOPSIS
Gets private store offers that were defined in tenant level
#>
function Test-GetAzMarketplacePrivateStoreOffers
{
$propertiesCount=11
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"

$queryResult = Get-AzMarketplacePrivateStoreOffer -PrivateStoreId $PrivateStoreIdValue

Assert-NotNull $queryResult
Assert-AreEqual $queryResult.Count 3

for ($i = 0; $i -lt $queryResult.Count; $i++)
{
Assert-PropertiesCount $queryResult[$i] $propertiesCount
Assert-AreEqual $queryResult[$i].PrivateStoreId $PrivateStoreIdValue
}
}

<#
.SYNOPSIS
Gets private store offers that were defined in tenant level
#>
function Test-GetAzMarketplacePrivateStoreOffer
{
$propertiesCount=11
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"
$OfferIdValue="altamira-corporation.lumify"

$queryResult = Get-AzMarketplacePrivateStoreOffer -PrivateStoreId $PrivateStoreIdValue -OfferId $OfferIdValue

Assert-NotNull $queryResult
Assert-AreEqual $queryResult.Count 1

for ($i = 0; $i -lt $queryResult.Count; $i++)
{
Assert-PropertiesCount $queryResult[$i] $propertiesCount
Assert-AreEqual $queryResult[$i].PrivateStoreId $PrivateStoreIdValue
Assert-AreEqual $queryResult[$i].UniqueOfferId $OfferIdValue
}
}

<#
.SYNOPSIS
Deletes private store offer that was defined in tenant level
#>
function Test-RemoveAzMarketplacePrivateStoreOffer
{
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"
$OfferIdValue="altamira-corporation.lumify"

$queryResult = Remove-AzMarketplacePrivateStoreOffer -PrivateStoreId $PrivateStoreIdValue -OfferId $OfferIdValue -PassThru

Assert-AreEqual true $queryResult

}

<#
.SYNOPSIS
Creates private store offer that was defined in tenant level
#>
function Test-CreateAzMarketplacePrivateStoreOffer
{
$propertiesCount=11
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"
$OfferIdValue="altamira-corporation.lumify"
$SpecificPlanIdsLimitationValue= @("lumify","0001")

$queryResult = Set-AzMarketplacePrivateStoreOffer -PrivateStoreId $PrivateStoreIdValue -OfferId $OfferIdValue -SpecificPlanIdsLimitation $SpecificPlanIdsLimitationValue

Assert-NotNull $queryResult
Assert-AreEqual $queryResult.Count 1

for ($i = 0; $i -lt $queryResult.Count; $i++)
{
Assert-PropertiesCount $queryResult[$i] $propertiesCount
Assert-AreEqual $queryResult[$i].PrivateStoreId $PrivateStoreIdValue
Assert-AreEqual $queryResult[$i].UniqueOfferId $OfferIdValue
}
}

<#
.SYNOPSIS
Updates private store offer that was defined in tenant level
#>
function Test-UpdateAzMarketplacePrivateStoreOffer
{
$propertiesCount=11
$PrivateStoreIdValue="a70d384d-ec34-47dd-9d38-ec6df452cba1"
$OfferIdValue="altamira-corporation.lumify"
$SpecificPlanIdsLimitationValue= @("lumify")
$EtagValue ="020032e7-0000-0100-0000-5ee629440000"

$queryResult = Set-AzMarketplacePrivateStoreOffer -PrivateStoreId $PrivateStoreIdValue -OfferId $OfferIdValue -SpecificPlanIdsLimitation $SpecificPlanIdsLimitationValue -ETag $EtagValue

Assert-NotNull $queryResult
Assert-AreEqual $queryResult.Count 1

for ($i = 0; $i -lt $queryResult.Count; $i++)
{
Assert-PropertiesCount $queryResult[$i] $propertiesCount
Assert-AreEqual $queryResult[$i].PrivateStoreId $PrivateStoreIdValue
Assert-AreEqual $queryResult[$i].UniqueOfferId $OfferIdValue
Assert-AreEqual $queryResult[$i].SpecificPlanIdsLimitation.Count 1
}
}
90 changes: 90 additions & 0 deletions src/Marketplace/Marketplace.Test/ScenarioTests/TestController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Marketplace.Test.ScenarioTests
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Management.Marketplace;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;

public class TestController : RMTestBase
{
private readonly EnvironmentSetupHelper _helper;

public IMarketplaceManagementClient MarketplaceClient { get; private set; }

public static TestController NewInstance => new TestController();

protected TestController()
{
_helper = new EnvironmentSetupHelper();
}

public void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)
{

var sf = new StackTrace().GetFrame(1);
var callingClassType = sf.GetMethod().ReflectedType?.ToString();
var mockName = sf.GetMethod().Name;

_helper.TracingInterceptor = logger;
var providers = new Dictionary<string, string>
{
{ "Microsoft.Resources", null },
{ "Microsoft.Features", null },
{ "Microsoft.Authorization", null }
};
var providersToIgnore = new Dictionary<string, string>();
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

using (var context = MockContext.Start(callingClassType, mockName))
{
SetupManagementClients(context);

_helper.SetupEnvironment(AzureModule.AzureResourceManager);

var callingClassName = callingClassType?.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
_helper.SetupModules(
AzureModule.AzureResourceManager,
_helper.RMProfileModule,
_helper.GetRMModulePath(@"Az.Marketplace.psd1"),
"ScenarioTests\\Common.ps1",
"ScenarioTests\\" + callingClassName + ".ps1");

_helper.RunPowerShellTest(scripts);
}
}

protected void SetupManagementClients(MockContext context)
{
MarketplaceClient = GetResourceGraphClient(context);
_helper.SetupManagementClients(MarketplaceClient);
}

private static IMarketplaceManagementClient GetResourceGraphClient(MockContext context)
{
return context.GetServiceClient<MarketplaceManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
}
}
}
Loading