Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
babd009
Notificationhub Net SDK tests
smithaborkar Jul 20, 2015
d4ad389
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Jul 20, 2015
a928e29
NotificationHub Tests
smithaborkar Jul 21, 2015
524b5bd
NotificationHub : Nuget version change to preview
smithaborkar Jul 22, 2015
8459f77
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Jul 22, 2015
06abbf6
test proj fix
smithaborkar Jul 22, 2015
e82c8cc
NotificationHub response/nuget fixes
smithaborkar Jul 22, 2015
df80652
nh conflict fix
smithaborkar Jul 22, 2015
9c69ed0
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Jul 22, 2015
6667bac
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Jul 31, 2015
f4d9ebd
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Jul 31, 2015
2c9ed8a
NotificationHubs .SDK test fixes and ScenarioTest files
smithaborkar Aug 13, 2015
255d75b
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Aug 13, 2015
902e5d0
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-net
smithaborkar Aug 20, 2015
e340b06
NotificationHub fixs
smithaborkar Aug 20, 2015
f9a8d95
SessionRecord included
smithaborkar Aug 20, 2015
6432850
moved sessionrecords to the right place
amarzavery Aug 21, 2015
2a8dc16
Added random key values to recording files
amarzavery Aug 21, 2015
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{0ED772D0-2E8C-4E55-B1EE-5B75FA80A896}</ProjectGuid>
<RootNamespace>NotificationHubs.Tests</RootNamespace>
<AssemblyName>NotificationHubs.Tests</AssemblyName>
<NuGetPackageImportStamp>da945abd</NuGetPackageImportStamp>
</PropertyGroup>
<Import Project="..\..\..\..\tools\Library.Settings.targets" />
<Import Project="$(LibraryToolsFolder)\Test.Dependencies.target" />
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\TestDependencies\TestDependencies.csproj">
<Project>{40f35645-00ee-4df2-b66e-7624546b66df}</Project>
<Name>TestDependencies</Name>
</ProjectReference>
<ProjectReference Include="..\NotificationHubsManagement\NotificationHubsManagement.csproj">
<Project>{D56E4444-B9DF-4B02-9329-FFE12B39832D}</Project>
<Name>NotificationHubsManagement</Name>
<Properties>SkipValidatePackageReferences=true</Properties>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestHelper\RecordedDelegatingHandler.cs" />
<Compile Include="Tests\ScenarioTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestHelper\NotificationHubsManagementHelper.cs" />
<Compile Include="Tests\ScenarioTests.NamespaceTests.CRUD.cs" />
<Compile Include="Tests\ScenarioTests.NamespaceTests.CRUDAuthorizationRules.cs" />
<Compile Include="Tests\ScenarioTests.NotificationHubTests.CheckAvailability.cs" />
<Compile Include="Tests\ScenarioTests.NotificationHubTests.CRUD.cs" />
<Compile Include="Tests\ScenarioTests.NotificationHubTests.CRUDAuthorizationRules.cs" />
<Compile Include="Tests\ScenarioTests.NamespaceTests.CheckAvailability.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="SessionRecords\ScenarioTests\CheckNamespaceNameAvailability.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\ScenarioTests\CheckNotificationHubNameAvailability.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\ScenarioTests\NamespaceCreateGetUpdateDelete.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\ScenarioTests\NamespaceCreateGetUpdateDeleteAuthorizationRules.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\ScenarioTests\NotificationHubCreateGetUpdateDelete.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\ScenarioTests\NotificationHubCreateGetUpdateDeleteAuthorizationRules.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<!--<ItemGroup>
<Reference Include="Microsoft.Azure.Test.Framework, Version=1.0.5568.26003, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Azure.Test.Framework.2.0.5658.29898-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.2.0.5658.29898-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
</Reference>
</ItemGroup>-->
<!--
<Import Project="..\..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// 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.
//

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NotificationHubs.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NotificationHubs.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("663aa481-92aa-41e6-9ac7-11d232beaf54")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// 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 NotificationHubs.Tests.TestHelper
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.Azure;
using Microsoft.Azure.Management.NotificationHubs;
using Microsoft.Azure.Management.NotificationHubs.Models;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.WindowsAzure.Management;
using System.Security.Cryptography;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;

public static class NotificationHubsManagementHelper
{
internal const string DefaultLocation = "South Central US";
internal const string ResourceGroupPrefix = "NotificationHub-RG";
internal const string NamespacePrefix = "HydraNH-Namespace";
internal const string NotificationHubPrefix = "HydraNH-NotificationHub";
internal const string AuthorizationRulesPrefix = "HydraNH-Authrules";
internal const string DefaultNamespaceAuthorizationRule = "RootManageSharedAccessKey";

public static NotificationHubsManagementClient GetNotificationHubsManagementClient(RecordedDelegatingHandler handler)
{
return TestBase.GetServiceClient<NotificationHubsManagementClient>(new CSMTestEnvironmentFactory());//.WithHandler(handler);
}

public static ResourceManagementClient GetResourceManagementClient(RecordedDelegatingHandler handler)
{
return TestBase.GetServiceClient<ResourceManagementClient>(new CSMTestEnvironmentFactory()).WithHandler(handler);
}

public static ManagementClient GetManagementClient(RecordedDelegatingHandler handler)
{
return TestBase.GetServiceClient<ManagementClient>(new CSMTestEnvironmentFactory()).WithHandler(handler);
}

public static void RefreshAccessToken(this NotificationHubsManagementClient notificationHubsManagementClient)
{
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
{
// if it's playback then do nothing
return;
}

var testEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
var context = new AuthenticationContext(new Uri(testEnvironment.Endpoints.AADAuthUri, testEnvironment.Tenant).AbsoluteUri);

var result = context.AcquireToken("https://management.core.windows.net/", testEnvironment.ClientId, new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior.Auto);
var newToken = context.AcquireTokenByRefreshToken(result.RefreshToken, testEnvironment.ClientId, "https://management.core.windows.net/");

((TokenCloudCredentials)notificationHubsManagementClient.Credentials).Token = newToken.AccessToken;
}

private static void ThrowIfTrue(bool condition, string message)
{
if (condition)
{
throw new Exception(message);
}
}

public static void TryRegisterSubscriptionForResource(this ResourceManagementClient resourceManagementClient, string providerName = "Microsoft.NotificationHubs")
{
var reg = resourceManagementClient.Providers.Register(providerName);
ThrowIfTrue(reg == null, "_client.Providers.Register returned null.");
ThrowIfTrue(reg.StatusCode != HttpStatusCode.OK, string.Format("_client.Providers.Register returned with status code {0}", reg.StatusCode));

var resultAfterRegister = resourceManagementClient.Providers.Get(providerName);
ThrowIfTrue(resultAfterRegister == null, "_client.Providers.Get returned null.");
ThrowIfTrue(string.IsNullOrEmpty(resultAfterRegister.Provider.Id), "Provider.Id is null or empty.");
ThrowIfTrue(!providerName.Equals(resultAfterRegister.Provider.Namespace), string.Format("Provider name is not equal to {0}.", providerName));
ThrowIfTrue(ProviderRegistrationState.Registered != resultAfterRegister.Provider.RegistrationState &&
ProviderRegistrationState.Registering != resultAfterRegister.Provider.RegistrationState,
string.Format("Provider registration state was not 'Registered' or 'Registering', instead it was '{0}'", resultAfterRegister.Provider.RegistrationState));
ThrowIfTrue(resultAfterRegister.Provider.ResourceTypes == null || resultAfterRegister.Provider.ResourceTypes.Count == 0, "Provider.ResourceTypes is empty.");
ThrowIfTrue(resultAfterRegister.Provider.ResourceTypes[0].Locations == null || resultAfterRegister.Provider.ResourceTypes[0].Locations.Count == 0, "Provider.ResourceTypes[0].Locations is empty.");
}

public static string TryGetResourceGroup(this ResourceManagementClient resourceManagementClient, string location)
{
var resourceGroup =
resourceManagementClient.ResourceGroups
.List(new ResourceGroupListParameters()).ResourceGroups
.Where(group => string.IsNullOrWhiteSpace(location) || group.Location.Equals(location, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault(group => group.Name.Contains(ResourceGroupPrefix));

return resourceGroup != null

? resourceGroup.Name
: string.Empty;
}

public static IEnumerable<ResourceGroupExtended> GetResourceGroups(this ResourceManagementClient resourceManagementClient)
{
return resourceManagementClient.ResourceGroups.List(new ResourceGroupListParameters()).ResourceGroups;
}

public static void TryRegisterResourceGroup(this ResourceManagementClient resourceManagementClient, string location, string resourceGroupName)
{
resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup(location));
}

public static string TryGetLocation(this ManagementClient managementClient, string preferedLocationName = null)
{
var loc = managementClient.Locations;
var locList = loc.List();
var locc = locList.Locations;

var locations = managementClient.Locations.List().Locations;
if (!locations.Any())
{
return string.Empty;
}

var foundLocation = locations.First();
if (preferedLocationName == null)
{
return foundLocation.Name;
}

var preferedLocation = locations.FirstOrDefault(location => location.Name.Contains(preferedLocationName));
if (preferedLocation != null)
{
return preferedLocation.Name;
}

return foundLocation.Name;
}

public static IEnumerable<string> GetLocations(this ManagementClient managementClient)
{
return managementClient.Locations.List().Locations.Select(location => location.Name);
}

public static void TryCreateNamespace(
this NotificationHubsManagementClient client,
string resourceGroupName,
string namespaceName,
string location,
string scaleUnit = null)
{
var namespaceParameter = new NamespaceCreateOrUpdateParameters()
{
Location = location,
Properties = new NamespaceProperties
{
NamespaceType = NamespaceType.NotificationHub
}
};

if (!string.IsNullOrEmpty(scaleUnit))
{
namespaceParameter.Properties.ScaleUnit = scaleUnit;
}

client.Namespaces.CreateOrUpdate(
resourceGroupName,
namespaceName, namespaceParameter
);

var response = client.Namespaces.Get(resourceGroupName, namespaceName);
ThrowIfTrue(!response.Value.Name.Equals(namespaceName), string.Format("Namespace name is not equal to {0}", namespaceName));
}

public static string GenerateRandomKey()
{
byte[] key256 = new byte[32];
using (var rngCryptoServiceProvider = new RNGCryptoServiceProvider())
{
rngCryptoServiceProvider.GetBytes(key256);
}

return Convert.ToBase64String(key256);
}

public static string ConvertObjectToJSon<T>(T obj)
{
return ConvertObjectToJSonAsync(obj);
}

public static string ConvertObjectToJSonAsync(object obj)
{
if (obj != null)
{
return (Task.Factory.StartNew(() => JsonConvert.SerializeObject(obj, SerializeMediaTypeFormatterSettings))).Result;
}
return String.Empty;
}

private static readonly JsonSerializerSettings SerializeMediaTypeFormatterSettings = new JsonSerializerSettings
{
NullValueHandling = Newtonsoft.Json.NullValueHandling.Include,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter>
{
new StringEnumConverter { CamelCaseText = false },
},
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};

}
}
Loading