Skip to content

Commit

Permalink
Azure Managed Services RP .net SDK (#5424)
Browse files Browse the repository at this point in the history
* Add .Net SDK entities, build is still failing

* add missing metadata

* add tests

* bin place sessionrecords

* fixed tests

* Add session records'

* address pr feedback

* Fix up metadata

* version prefix

* 'update test csproj

* re-gen after swagger merge
  • Loading branch information
rajivnandivada authored and dsgouda committed Mar 18, 2019
1 parent 66897f1 commit ac97291
Show file tree
Hide file tree
Showing 41 changed files with 6,275 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/SDKs/ManagedServices/AzSdk.RP.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--This file and it's contents are updated at build time moving or editing might result in build failure. Take due deligence while editing this file-->
<PropertyGroup>
<AzureApiTag></AzureApiTag>
<AzureApiTag>ManagedServices_2018-06-01-preview;</AzureApiTag>
<PackageTags>$(PackageTags);$(CommonTags);$(AzureApiTag);</PackageTags>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions src/SDKs/ManagedServices/ManagedServices.Test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Microsoft Azure Managed Services Test Library.")]
[assembly: AssemblyDescription("Provides the capability to test Azure managed services.")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace ManagedServices.Tests.Helpers
{
using System;
using Microsoft.Azure.Management.ManagedServices;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

public class ManagedServicesTestBase : TestBase, IDisposable
{
public ManagedServicesClient ManagedServicesClient { get; private set; }

public ManagedServicesTestBase(MockContext context)
{
this.ManagedServicesClient = context.GetServiceClient<ManagedServicesClient>();
}

public void Dispose()
{
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.


using ManagedServices.Tests.Helpers;
using Microsoft.Azure.Management.ManagedServices;
using Microsoft.Azure.Management.ManagedServices.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Net;
using System.Threading;
using Authorization = Microsoft.Azure.Management.ManagedServices.Models.Authorization;

namespace ManagedServices.Tests.Helpers
{
public static class ManagedServicesTestUtilities
{

public static string registratonDefinitionId = "0cb6fbd6-90df-4923-9d92-c266f6c27bba",
registrationAssignmentId = "46c2a6a8-3dda-49ae-bc99-ecc5d28dd98a",
subscriptionId = "45062c92-741a-4e9b-acc4-f0afbfce9c7a",
apiVersion = "2018-06-01-preview",
scope = string.Format("subscriptions/{0}", subscriptionId),
planName = "planName",
publisher = "publisher",
product = "product",
version = "1.0.0",
defintionDesctiption = "Registration Defintion Description",
principalId = "1445e20d-2d4f-4616-9c19-564f4a963499",
roleDefinitionId = "acdd72a7-3385-48ef-bd42-f606fba81ae7",
registrationDefinitionName = "registrationDefinitionName",
managedByTenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47";

public static RegistrationDefinition GetRegistrationDefintion()
{
return new RegistrationDefinition(
properties: ManagedServicesTestUtilities.GetRegistrationDefinitionProperties(),
plan: ManagedServicesTestUtilities.GetPlan());
}

public static RegistrationDefinitionProperties GetRegistrationDefinitionProperties()
{
return new RegistrationDefinitionProperties(
description: defintionDesctiption,
authorizations: ManagedServicesTestUtilities.GetAuthorizations(),
registrationDefinitionName: registrationDefinitionName,
managedByTenantId: managedByTenantId);
}

public static Plan GetPlan()
{
return new Plan(
name: planName,
publisher: publisher,
product: product,
version: version);
}

public static Authorization[] GetAuthorizations()
{
return new Authorization[]
{
new Authorization(
principalId: principalId,
roleDefinitionId: roleDefinitionId)
};
}

public static RegistrationAssignment GetRegistrationAssignment()
{
return new RegistrationAssignment()
{
Properties = ManagedServicesTestUtilities.GetRegistrationAssignmentProperties()
};
}

public static RegistrationAssignmentProperties GetRegistrationAssignmentProperties()
{
return new RegistrationAssignmentProperties()
{
RegistrationDefinitionId = string.Format("{0}/providers/Microsoft.ManagedServices/registrationdefinitions/{1}", ManagedServicesTestUtilities.scope, ManagedServicesTestUtilities.registratonDefinitionId)
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<!-- Please do not move/edit code below this line -->
<Import Condition=" Exists('$([MSBuild]::GetPathOfFileAbove(AzSdk.test.reference.props))') " Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
<!-- Please do not move/edit code below this line -->
<PropertyGroup>
<PackageId>ManagedServices.Test</PackageId>
<VersionPrefix>1.0.0</VersionPrefix>
<AssemblyName>ManagedServices.Test</AssemblyName>
<Description>ManagedServices.Test class library</Description>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Management.ManagedServices\Microsoft.Azure.Management.ManagedServices.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System">
<HintPath>System</HintPath>
</Reference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Linq;
using System.Collections;
using ManagedServices.Tests.Helpers;
using Microsoft.Azure.Management.ManagedServices;
using Microsoft.Azure.Management.ManagedServices.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;

namespace ManagedServices.Tests.ScenarioTests
{
public class RegistrationAssignmentTests : TestBase
{
[Fact]
public void RegistrationAssignmentTests_CRUD()
{
using (var context = MockContext.Start(GetType().FullName))
{
using (var testFixture = new ManagedServicesTestBase(context))
{
var registrationDefinition = ManagedServicesTestUtilities.GetRegistrationDefintion();
var registrationAssignment= ManagedServicesTestUtilities.GetRegistrationAssignment();

//1. Create registration assignment
var registrationDefinitionResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.CreateOrUpdate(
registratonDefinitionId: ManagedServicesTestUtilities.registratonDefinitionId,
apiVersion: ManagedServicesTestUtilities.apiVersion,
scope: ManagedServicesTestUtilities.scope,
requestBody: registrationDefinition);

Assert.NotNull(registrationDefinitionResponse);
Assert.Equal(ManagedServicesTestUtilities.registratonDefinitionId, registrationDefinitionResponse.Name);
Assert.Equal(ProvisioningState.Succeeded, registrationDefinitionResponse.Properties.ProvisioningState);

var registrationAssignemntResponse = testFixture.ManagedServicesClient.RegistrationAssignments
.CreateOrUpdate(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion,
registratonAssignmentId: ManagedServicesTestUtilities.registrationAssignmentId,
requestBody: registrationAssignment);

Assert.NotNull(registrationAssignemntResponse);
Assert.Equal(ManagedServicesTestUtilities.registrationAssignmentId, registrationAssignemntResponse.Name);
Assert.Equal(ProvisioningState.Succeeded, registrationAssignemntResponse.Properties.ProvisioningState);

//2. Get registration assignment
registrationAssignemntResponse = testFixture.ManagedServicesClient.RegistrationAssignments
.Get(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion,
registratonAssignmentId: ManagedServicesTestUtilities.registrationAssignmentId);

Assert.NotNull(registrationAssignemntResponse);
Assert.Equal(ManagedServicesTestUtilities.registrationAssignmentId, registrationAssignemntResponse.Name);

//3. Get registration assignment collections
var registrationAssignemntResponses = testFixture.ManagedServicesClient.RegistrationAssignments
.List(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion,
expandRegistrationDefinition: true);

Assert.NotNull(registrationAssignemntResponses);
Assert.Single(registrationAssignemntResponses);

foreach (var assignment in registrationAssignemntResponses)
{
Assert.NotNull(assignment.Properties.RegistrationDefinition.Plan);
}

//4. Get registration assignment collections expanded
registrationAssignemntResponses = testFixture.ManagedServicesClient.RegistrationAssignments
.List(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion,
expandRegistrationDefinition: true);

Assert.NotNull(registrationAssignemntResponses);
Assert.Single(registrationAssignemntResponses);

//5. Delete registration assignment
registrationAssignemntResponse = testFixture.ManagedServicesClient.RegistrationAssignments
.Delete(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion,
registratonAssignmentId: ManagedServicesTestUtilities.registrationAssignmentId);

Assert.NotNull(registrationAssignemntResponse);
Assert.Equal(ManagedServicesTestUtilities.registrationAssignmentId, registrationAssignemntResponse.Name);

//6. Get registration assignment collections
registrationAssignemntResponses = testFixture.ManagedServicesClient.RegistrationAssignments
.List(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion);

Assert.NotNull(registrationAssignemntResponses);
Assert.Empty(registrationAssignemntResponses);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using ManagedServices.Tests.Helpers;
using Microsoft.Azure.Management.Resources;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;
using Microsoft.Azure.Management.ManagedServices;
using Microsoft.Azure.Management.ManagedServices.Models;

namespace ManagedServices.Tests.ScenarioTests
{
public class RegistrationDefintionTests : TestBase
{
[Fact]
public void RegistrationDefintionTests_CRUD()
{
using (var context = MockContext.Start(GetType().FullName))
{
using (var testFixture = new ManagedServicesTestBase(context))
{
var registrationDefinition = ManagedServicesTestUtilities.GetRegistrationDefintion();

//1. Create Registration Defintion
var registrationDefinitionResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.CreateOrUpdate(
registratonDefinitionId: ManagedServicesTestUtilities.registratonDefinitionId,
apiVersion: ManagedServicesTestUtilities.apiVersion,
scope: ManagedServicesTestUtilities.scope,
requestBody: registrationDefinition);

Assert.NotNull(registrationDefinitionResponse);
Assert.Equal(ProvisioningState.Succeeded, registrationDefinitionResponse.Properties.ProvisioningState);

//2. Get Registration Defintion
registrationDefinitionResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.Get(
scope: ManagedServicesTestUtilities.scope,
registratonDefinitionId: ManagedServicesTestUtilities.registratonDefinitionId,
apiVersion: ManagedServicesTestUtilities.apiVersion);

Assert.NotNull(registrationDefinitionResponse);
Assert.Equal(ManagedServicesTestUtilities.registrationDefinitionName, registrationDefinitionResponse.Properties.RegistrationDefinitionName);

//3. Get Registration Defintion collection
var registrationDefinitionsResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.List(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion);

Assert.NotNull(registrationDefinitionsResponse);
Assert.Single(registrationDefinitionsResponse);

//4. Delete Registration Defintion
registrationDefinitionResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.Delete(
scope: ManagedServicesTestUtilities.scope,
registratonDefinitionId: ManagedServicesTestUtilities.registratonDefinitionId,
apiVersion: ManagedServicesTestUtilities.apiVersion);

Assert.NotNull(registrationDefinitionResponse);

//5. Get Registration Defintion collection
registrationDefinitionsResponse = testFixture.ManagedServicesClient.RegistrationDefinitions
.List(
scope: ManagedServicesTestUtilities.scope,
apiVersion: ManagedServicesTestUtilities.apiVersion);

Assert.Empty(registrationDefinitionsResponse);
}
}
}
}
}
Loading

0 comments on commit ac97291

Please sign in to comment.