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
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@
using System.Text;
using System.Threading.Tasks;

using Microsoft.WindowsAzure.ServiceLayer.ServiceBus;

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

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

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

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

public static IServiceBusService ServiceBus
{
get
{
if (_serviceBus == null)
{
_serviceBus = ServiceBusService.Create(ServiceNamespace, UserName, Password);
}
return _serviceBus;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Compile Include="Configuration.cs" />
<Compile Include="ServiceBusManagementTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestSubscriptionAttribute.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="xunit, Version=1.9.0.1566, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
Expand Down

Large diffs are not rendered by default.

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

using Xunit;

namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests
{
/// <summary>
/// Creates a topic/subscription pair for a test marked with this attribute.
/// </summary>
public class TestSubscriptionAttribute: BeforeAfterTestAttribute
{
public TestSubscriptionAttribute()
{
TopicName = string.Format(CultureInfo.InvariantCulture, "Test.{0}", Guid.NewGuid());
SubscriptionName = string.Format(CultureInfo.InvariantCulture, "Subscription.{0}", Guid.NewGuid());
}

public TestSubscriptionAttribute(string topicName, string subscriptionName)
{
TopicName = topicName;
SubscriptionName = subscriptionName;
}

/// <summary>
/// Gets the topic name.
/// </summary>
public static string TopicName { get; private set; }

/// <summary>
/// Gets the subscription name.
/// </summary>
public static string SubscriptionName { get; private set; }

/// <summary>
/// Runs before the test.
/// </summary>
/// <param name="methodUnderTest">Test method.</param>
public override void Before(MethodInfo methodUnderTest)
{
try
{
Configuration.ServiceBus.CreateTopicAsync(TopicName).AsTask().Wait();
}
catch
{
// Do nothing.
}

try
{
Configuration.ServiceBus.CreateSubscriptionAsync(TopicName, SubscriptionName).AsTask().Wait();
}
catch
{
// Do nothing.
}
}

/// <summary>
/// Runs after the test.
/// </summary>
/// <param name="methodUnderTest">Test method.</param>
public override void After(MethodInfo methodUnderTest)
{
try
{
Configuration.ServiceBus.DeleteSubscriptionAsync(TopicName, SubscriptionName).AsTask().Wait();
}
catch
{
// Do nothing.
}

try
{
Configuration.ServiceBus.DeleteTopicAsync(TopicName).AsTask().Wait();
}
catch
{
// Do nothing.
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@ internal static class Constants
internal const string ServiceBusAuthenticationUri = "https://{0}-sb.accesscontrol.windows.net/wrapv0.9/";
internal const string ServiceBusScopeUri = "http://{0}.servicebus.windows.net/";

internal const string QueuesPath = "$Resources/Queues";
internal const string QueuePath = "{0}"; // <queue>

internal const string TopicsPath = "$Resources/Topics";
internal const string TopicPath = "{0}"; // <topic>

internal const string SubscriptionsPath = "{0}/subscriptions/"; // <topic>/subscriptions
internal const string SubscriptionPath = "{0}/subscriptions/{1}/"; // <topic>/subscriptions/<subscription>

internal const string RulesPath = "{0}/subscriptions/{1}/rules/"; // topics/<topic>/subscriptions/<subscription>/rules
internal const string RulePath = "{0}/subscriptions/{1}/rules/{2}"; // <topic>/subscriptions/<subscription>/rules/<rule>

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";

internal const int CompatibilityLevel = 20; // Compatibility level for rules
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,23 @@
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
</ItemGroup>
<ItemGroup>
<Compile Include="ServiceBus\CorrelationRuleFilter.cs" />
<Compile Include="ServiceBus\EmptyRuleAction.cs" />
<Compile Include="ServiceBus\FalseRuleFilter.cs" />
<Compile Include="ServiceBus\IRuleAction.cs" />
<Compile Include="ServiceBus\IRuleFilter.cs" />
<Compile Include="ServiceBus\ISqlRuleFilter.cs" />
<Compile Include="ServiceBus\RuleInfo.cs" />
<Compile Include="ServiceBus\SqlRuleFilter.cs" />
<Compile Include="ServiceBus\SqlRuleAction.cs" />
<Compile Include="ServiceBus\SubscriptionInfo.cs" />
<Compile Include="ServiceBus\RuleSettings.cs" />
<Compile Include="ServiceBus\TopicInfo.cs" />
<Compile Include="ServiceBus\TopicSettings.cs" />
<Compile Include="ServiceBus\SubscriptionSettings.cs" />
<Compile Include="ServiceBus\TrueRuleFilter.cs" />
<Compile Include="WindowsAzureServiceException.cs" />
<Compile Include="Constants.cs" />
<Compile Include="HttpErrorHandler.cs" />
<Compile Include="HttpQueryStringParser.cs" />
<Compile Include="ServiceBus\ServiceBusRestProxy.cs" />
<Compile Include="ServiceBus\WrapAuthenticationHandler.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ static internal class SerializationHelper
/// <typeparam name="T">Type of result items in the collection.</typeparam>
/// <param name="feed">Atom feed with serialized items.</param>
/// <param name="itemAction">Additional action to perform on each item.</param>
/// <param name="extraTypes">Extra types for deserialization.</param>
/// <returns>Collection of deserialized items.</returns>
static internal IEnumerable<T> DeserializeCollection<T>(SyndicationFeed feed, Action<SyndicationItem, T> itemAction)
internal static IEnumerable<T> DeserializeCollection<T>(SyndicationFeed feed, Action<SyndicationItem, T> itemAction, IEnumerable<Type> extraTypes)
{
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
return feed.Items.Select(item => DeserializeItem<T>(item, itemAction));
Debug.Assert(extraTypes != null);
DataContractSerializer serializer = new DataContractSerializer(typeof(T), extraTypes);
return feed.Items.Select(item => DeserializeItem<T>(serializer, item, itemAction));
}

/// <summary>
Expand All @@ -50,10 +52,12 @@ static internal IEnumerable<T> DeserializeCollection<T>(SyndicationFeed feed, Ac
/// <typeparam name="T">Target object type.</typeparam>
/// <param name="item">Atom item to deserialize.</param>
/// <param name="itemAction">Action to perform after deserialization.</param>
/// <param name="extraTypes">Extra types for deserialization.</param>
/// <returns>Deserialized object.</returns>
static internal T DeserializeItem<T>(SyndicationItem item, Action<SyndicationItem, T> itemAction)
internal static T DeserializeItem<T>(SyndicationItem item, Action<SyndicationItem, T> itemAction, IEnumerable<Type> extraTypes)
{
return DeserializeItem<T>(new DataContractSerializer(typeof(T)), item, itemAction);
Debug.Assert(extraTypes != null);
return DeserializeItem<T>(new DataContractSerializer(typeof(T), extraTypes), item, itemAction);
}

/// <summary>
Expand All @@ -64,7 +68,7 @@ static internal T DeserializeItem<T>(SyndicationItem item, Action<SyndicationIte
/// <param name="item">Atom item.</param>
/// <param name="itemAction">Action to perform after deserialization.</param>
/// <returns>Deserialized object.</returns>
static T DeserializeItem<T>(DataContractSerializer serializer, SyndicationItem item, Action<SyndicationItem, T> itemAction)
private static T DeserializeItem<T>(DataContractSerializer serializer, SyndicationItem item, Action<SyndicationItem, T> itemAction)
{
string serializedString = item.Content.Xml.GetXml();

Expand All @@ -82,15 +86,16 @@ static T DeserializeItem<T>(DataContractSerializer serializer, SyndicationItem i
/// Serializes given object.
/// </summary>
/// <param name="item">Object to serialize.</param>
/// <param name="knownTypes">List of supported types</param>
/// <returns>Serialized representation.</returns>
static internal string Serialize(object item)
internal static string Serialize(object item, params Type[] knownTypes)
{
// Serialize the content
string itemXml;

using (MemoryStream stream = new MemoryStream())
{
DataContractSerializer serializer = new DataContractSerializer(item.GetType());
DataContractSerializer serializer = new DataContractSerializer(item.GetType(), knownTypes);
serializer.WriteObject(stream, item);

stream.Flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// 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.Runtime.Serialization;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
/// <summary>
/// Correlation rule filter.
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", Name="CorrelationFilter")]
public sealed class CorrelationRuleFilter : IRuleFilter
{
/// <summary>
/// Correlation ID.
/// </summary>
[DataMember(Order = 0)]
public string CorrelationId { get; internal set; }

/// <summary>
/// Constructor.
/// </summary>
/// <param name="correlationId">Correlation ID.</param>
public CorrelationRuleFilter(string correlationId)
{
if (correlationId == null)
{
throw new ArgumentNullException("correlationId");
}
CorrelationId = correlationId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// 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.Runtime.Serialization;

namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
/// <summary>
/// Represents a no-op filter action.
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect")]
public sealed class EmptyRuleAction : IRuleAction
{
/// <summary>
/// Constructor.
/// </summary>
public EmptyRuleAction()
{
// Do nothing.
}
}
}
Loading