Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial checkin for WinMD WindowsAzure API #3

Closed
wants to merge 12 commits into from
Closed
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
3 changes: 3 additions & 0 deletions microsoft-azure-servicelayer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.suo
TestApp/
microsoft-azure-servicelayer-pr.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.suo
bin/
obj/

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests
{
static class Configuration
{
public static string ServiceNamespace { get { throw new NotImplementedException(); } }

public static string UserName { get { throw new NotImplementedException(); } }

public static string Password { get { throw new NotImplementedException(); } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{DA6C7F9A-B35C-4D34-AD83-7131ACE8F72C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.WindowsAzure.ServiceLayer.UnitTests</RootNamespace>
<AssemblyName>Microsoft.WindowsAzure.ServiceLayer.UnitTests</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<ProjectReference Include="..\Microsoft.WindowsAzure.ServiceLayer\Microsoft.WindowsAzure.ServiceLayer.csproj">
<Project>{53c097e2-7384-446b-836b-a7910993091e}</Project>
<Name>Microsoft.WindowsAzure.ServiceLayer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="ServiceBusManagementTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="xunit">
<HintPath>..\..\..\..\Tools\XUnit 1.9\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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("Microsoft.WindowsAzure.ServiceLayer.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Microsoft.WindowsAzure.ServiceLayer.UnitTests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 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")]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.WindowsAzure.ServiceLayer.ServiceBus;

using Xunit;

namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests
{
/// <summary>
/// Tests for the service bus management.
/// </summary>
public class ServiceBusManagementTests
{
class InternalQueueInfoComparer : IEqualityComparer<QueueInfo>
{
bool IEqualityComparer<QueueInfo>.Equals(QueueInfo x, QueueInfo y)
{
return x.DefaultMessageTimeToLive == y.DefaultMessageTimeToLive
&& x.DuplicateDetectionHistoryTimeWindow == y.DuplicateDetectionHistoryTimeWindow
&& x.EnableBatchedOperations == y.EnableBatchedOperations
&& x.EnableDeadLetteringOnMessageExpiration == y.EnableDeadLetteringOnMessageExpiration
&& x.LockDuration == y.LockDuration
&& x.MaxDeliveryCount == y.MaxDeliveryCount
&& x.MaxSizeInMegabytes == y.MaxSizeInMegabytes
&& x.MessageCount == y.MessageCount
&& string.Equals(x.Name, y.Name, StringComparison.OrdinalIgnoreCase)
&& x.RequiresDuplicateDetection == y.RequiresDuplicateDetection
&& x.RequiresSession == y.RequiresSession
&& x.SizeInBytes == y.SizeInBytes
&& string.Equals(x.Uri.ToString(), y.Uri.ToString(), StringComparison.OrdinalIgnoreCase);
}

int IEqualityComparer<QueueInfo>.GetHashCode(QueueInfo obj)
{
return obj.GetHashCode();
}
}

IServiceBusService Service { get; set; }
IEqualityComparer<QueueInfo> QueueInfoComparer { get; set; }

public ServiceBusManagementTests()
{
Service = ServiceBusService.Create(Configuration.ServiceNamespace, Configuration.UserName, Configuration.Password);
QueueInfoComparer = new InternalQueueInfoComparer();
}


string GetUniqueEntityName()
{
return string.Format("UnitTests.{0}", Guid.NewGuid().ToString());
}

Dictionary<string, QueueInfo> GetQueues()
{
Dictionary<string, QueueInfo> queues = new Dictionary<string, QueueInfo>(StringComparer.OrdinalIgnoreCase);
foreach (QueueInfo queue in Service.ListQueuesAsync().AsTask<IEnumerable<QueueInfo>>().Result)
{
queues.Add(queue.Name, queue);
}
return queues;
}

[Fact]
public void NullArgsInQueues()
{
Assert.Throws<ArgumentNullException>(() => Service.CreateQueueAsync(null));
Assert.Throws<ArgumentNullException>(() => Service.CreateQueueAsync(null, new QueueSettings()));
Assert.Throws<ArgumentNullException>(() => Service.CreateQueueAsync("foo", null));
Assert.Throws<ArgumentNullException>(() => Service.GetQueueAsync(null));
Assert.Throws<ArgumentNullException>(() => Service.DeleteQueueAsync(null));
}

/// <summary>
/// Tests full lifecycle of a queue.
/// </summary>
[Fact]
public void QueueLifecycle()
{
// Create a queue.
string queueName = GetUniqueEntityName();
QueueInfo newQueue = Service.CreateQueueAsync(queueName).AsTask<QueueInfo>().Result;

// Confirm that the queue can be obtained from the server
QueueInfo storedQueue = Service.GetQueueAsync(queueName).AsTask<QueueInfo>().Result;
Assert.Equal<QueueInfo>(storedQueue, newQueue, QueueInfoComparer);

// Confirm that the queue can be obtained in the list
Dictionary<string, QueueInfo> queues = GetQueues();

Assert.True(queues.ContainsKey(queueName));
Assert.Equal<QueueInfo>(newQueue, queues[queueName], QueueInfoComparer);

// Delete the queue
Service.DeleteQueueAsync(queueName).AsTask().Wait();
queues = GetQueues();
Assert.False(queues.ContainsKey(queueName));
}

/// <summary>
/// Verifies that using an existing name for a new queue result in an exception.
/// </summary>
[Fact]
public void CreateQueueDuplicateName()
{
// Create a queue
string queueName = GetUniqueEntityName();
QueueInfo newQueue = Service.CreateQueueAsync(queueName).AsTask<QueueInfo>().Result;

Task t = Service.CreateQueueAsync(queueName).AsTask();
Assert.Throws<AggregateException>(() => t.Wait());
}

/// <summary>
/// Verifies creation of the queue with all non-default parameters
/// </summary>
[Fact]
public void CreateQueueWithNonDefaultParams()
{
string queueName = GetUniqueEntityName();
QueueSettings settings = new QueueSettings();

settings.DefaultMessageTimeToLive = TimeSpan.FromHours(24);
settings.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromDays(2);
settings.EnableBatchedOperations = false;
settings.EnableDeadLetteringOnMessageExpiration = true;
settings.LockDuration = TimeSpan.FromMinutes(3);
settings.MaxDeliveryCount = 5;
settings.MaxSizeInMegabytes = 2048;
settings.RequiresDuplicateDetection = true;
settings.RequiresSession = true;

QueueInfo queueInfo = Service.CreateQueueAsync(queueName, settings).AsTask<QueueInfo>().Result;
Assert.Equal(queueInfo.DefaultMessageTimeToLive, settings.DefaultMessageTimeToLive.Value);
Assert.Equal(queueInfo.DuplicateDetectionHistoryTimeWindow, settings.DuplicateDetectionHistoryTimeWindow.Value);
Assert.Equal(queueInfo.EnableBatchedOperations, settings.EnableBatchedOperations.Value);
Assert.Equal(queueInfo.EnableDeadLetteringOnMessageExpiration, settings.EnableDeadLetteringOnMessageExpiration.Value);
Assert.Equal(queueInfo.LockDuration, settings.LockDuration.Value);
Assert.Equal(queueInfo.MaxDeliveryCount, settings.MaxDeliveryCount.Value);
Assert.Equal(queueInfo.MaxSizeInMegabytes, settings.MaxSizeInMegabytes.Value);
Assert.Equal(queueInfo.RequiresDuplicateDetection, settings.RequiresDuplicateDetection.Value);
Assert.Equal(queueInfo.RequiresSession, settings.RequiresSession.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.suo
bin/
obj/

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2012 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.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.ServiceLayer
{
/// <summary>
/// Shared constants.
/// </summary>
internal static class Constants
{
internal const string ServiceBusServiceUri = "https://{0}.servicebus.windows.net/";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be constants or resources? If they're resources, folks can change the service URI without recompiling the app. If the other libraries all have them as constants then I'm fine with that too as Azure won't likely be ever changing that URI.

internal const string ServiceBusAuthenticationUri = "https://{0}-sb.accesscontrol.windows.net/wrapv0.9/";
internal const string ServiceBusScopeUri = "http://{0}.servicebus.windows.net/";

internal const string WrapTokenAuthenticationString = "WRAP access_token=\"{0}\"";

internal const string SerializationContentType = "application/xml";
internal const string BodyContentType = "application/atom+xml";
internal const string WrapAuthenticationContentType = "application/x-www-form-urlencoded";
}
}
Loading