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 @@ -115,7 +115,11 @@
<Compile Include="Configuration.cs" />
<Compile Include="ServiceBusManagementTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceBusTests\MessagePropertiesTests.cs" />
<Compile Include="ServiceBusTests\MessageSettingsTests.cs" />
<Compile Include="ServiceBusTests\QueueMessagingTests.cs" />
<Compile Include="ServiceBusTests\SubscriptionMessagingTests.cs" />
<Compile Include="ServiceBusTests\UniqueSubscriptionFixture.cs" />
<Compile Include="ServiceBusTests\UsesUniqueQueueAttribute.cs" />
<Compile Include="ServiceBusTests\UsesUniqueSubscriptionAttribute.cs" />
<Compile Include="ServiceBusTests\UsesUniqueTopicAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,22 @@ public void CreateQueueWithNonDefaultParams()
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.MaximumDeliveryCount, settings.MaximumDeliveryCount.Value);
Assert.Equal(queueInfo.MaximumSizeInMegabytes, settings.MaximumSizeInMegabytes.Value);
Assert.Equal(queueInfo.RequiresDuplicateDetection, settings.RequiresDuplicateDetection.Value);
Assert.Equal(queueInfo.RequiresSession, settings.RequiresSession.Value);
try
{
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.MaximumDeliveryCount, settings.MaximumDeliveryCount.Value);
Assert.Equal(queueInfo.MaximumSizeInMegabytes, settings.MaximumSizeInMegabytes.Value);
Assert.Equal(queueInfo.RequiresDuplicateDetection, settings.RequiresDuplicateDetection.Value);
Assert.Equal(queueInfo.RequiresSession, settings.RequiresSession.Value);
}
finally
{
Service.DeleteQueueAsync(queueName).AsTask().Wait();
}
}

/// <summary>
Expand Down Expand Up @@ -361,11 +368,18 @@ public void CreateTopicWithNonDefaultParams()
settings.RequiresDuplicateDetection = true;

TopicInfo topic = Service.CreateTopicAsync(topicName, settings).AsTask<TopicInfo>().Result;
Assert.Equal(settings.DefaultMessageTimeToLive.Value, topic.DefaultMessageTimeToLive);
Assert.Equal(settings.DuplicateDetectionHistoryTimeWindow.Value, topic.DuplicateDetectionHistoryTimeWindow);
Assert.Equal(settings.EnableBatchedOperations.Value, topic.EnableBatchedOperations);
Assert.Equal(settings.MaximumSizeInMegabytes.Value, topic.MaximumSizeInMegabytes);
Assert.Equal(settings.RequiresDuplicateDetection.Value, topic.RequiresDuplicateDetection);
try
{
Assert.Equal(settings.DefaultMessageTimeToLive.Value, topic.DefaultMessageTimeToLive);
Assert.Equal(settings.DuplicateDetectionHistoryTimeWindow.Value, topic.DuplicateDetectionHistoryTimeWindow);
Assert.Equal(settings.EnableBatchedOperations.Value, topic.EnableBatchedOperations);
Assert.Equal(settings.MaximumSizeInMegabytes.Value, topic.MaximumSizeInMegabytes);
Assert.Equal(settings.RequiresDuplicateDetection.Value, topic.RequiresDuplicateDetection);
}
finally
{
Service.DeleteTopicAsync(topicName).AsTask().Wait();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// 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;
using Microsoft.WindowsAzure.ServiceLayer.ServiceBus;
using Xunit;

namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests.ServiceBusTests
{
/// <summary>
/// Tests for message properties.
/// </summary>
public sealed class MessagePropertiesTests
{
/// <summary>
/// Tests setting and reading message properties.
/// </summary>
[Fact]
[UsesUniqueQueue]
public void MessageProperties()
{
string queueName = UsesUniqueQueueAttribute.QueueName;
BrokeredMessageSettings messageSettings = BrokeredMessageSettings.CreateFromText("text/plain", "This is a test.");

messageSettings.Properties.Add("StringProperty", "Test");
messageSettings.Properties.Add("BoolPropertyTrue", true);
messageSettings.Properties.Add("BoolPropertyFalse", false);
messageSettings.Properties.Add("NullProperty", null);
messageSettings.Properties.Add("NumberProperty", 123);

Configuration.ServiceBus.SendMessageAsync(queueName, messageSettings).AsTask().Wait();
BrokeredMessageInfo message = Configuration.ServiceBus.GetQueueMessageAsync(queueName, TimeSpan.FromSeconds(10)).AsTask().Result;

Assert.NotEqual(message.Properties, null);
Assert.True(message.Properties.ContainsKey("StringProperty"));
Assert.True(message.Properties.ContainsKey("BoolPropertyTrue"));
Assert.True(message.Properties.ContainsKey("BoolPropertyFalse"));
Assert.True(message.Properties.ContainsKey("NumberProperty"));
// The server does not store/return null properties.
Assert.False(message.Properties.ContainsKey("NullProperty"));

Assert.Equal((string)message.Properties["StringProperty"], "Test", StringComparer.Ordinal);
Assert.Equal((bool)message.Properties["BoolPropertyTrue"], true);
Assert.Equal((bool)message.Properties["BoolPropertyFalse"], false);
Assert.Equal(Convert.ToInt32(message.Properties["NumberProperty"]), 123);
}

/// <summary>
/// Tests that properties of unsupported types are rejected.
/// </summary>
[Fact]
[UsesUniqueQueue]
public void InvalidPropertyType()
{
string queueName = UsesUniqueQueueAttribute.QueueName;
BrokeredMessageSettings messageSettings = BrokeredMessageSettings.CreateFromText("text/plain", "This is a test.");

messageSettings.Properties.Add("TestProperty", new int[] { 1, 2, 3});
Assert.Throws<InvalidCastException>(() => Configuration.ServiceBus.SendMessageAsync(queueName, messageSettings));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.ServiceLayer.ServiceBus;
using Windows.Storage.Streams;
using Xunit;

namespace Microsoft.WindowsAzure.ServiceLayer.UnitTests.ServiceBusTests
{
/// <summary>
/// Unit tests for the BrokeredMessageSettings class.
/// </summary>
public sealed class MessageSettingsTests
{
/// <summary>
/// Tests specifying null arguments in constructors.
/// </summary>
[Fact]
public void NullArgumentsInConstructors()
{
Assert.Throws<ArgumentNullException>(() => BrokeredMessageSettings.CreateFromBytes((byte[])null));
Assert.Throws<ArgumentNullException>(() => BrokeredMessageSettings.CreateFromText(null, "This is a test."));
Assert.Throws<ArgumentNullException>(() => BrokeredMessageSettings.CreateFromText("text/plain", (string)null));
Assert.Throws<ArgumentNullException>(() => BrokeredMessageSettings.CreateFromStream((IInputStream)null));
}

/// <summary>
/// Tests specifying null arguments in methods of a brokered message.
/// </summary>
[Fact]
public void NullArgumentsInMethods()
{
BrokeredMessageSettings message = BrokeredMessageSettings.CreateFromText("text/plain", "This is a test.");
Assert.Throws<ArgumentNullException>(() => message.CopyContentToAsync(null));
}

/// <summary>
/// Tests reading a message as a string.
/// </summary>
[Fact]
public void ReadAsString()
{
string originalBody = "This is only a test!";
BrokeredMessageSettings message = BrokeredMessageSettings.CreateFromText("text/plain", originalBody);

// Do it twice to make sure the position in the stream is restored after each read.
for (int i = 0; i < 2; i++)
{
string newBody = message.ReadContentAsStringAsync().AsTask().Result;
Assert.Equal(originalBody, newBody, StringComparer.Ordinal);
}
}

/// <summary>
/// Tests reading content of the message into a stream.
/// </summary>
[Fact]
public void ReadIntoStream()
{
Byte[] bytes = new byte[] { 1, 2, 3 };
BrokeredMessageSettings message = BrokeredMessageSettings.CreateFromBytes(bytes);

// Do it twice to make sure the position in the stream is restored after each read.
for (int i = 0; i < 2; i++)
{
using (MemoryStream stream = new MemoryStream())
{
message.CopyContentToAsync(stream.AsOutputStream()).AsTask().Wait();
stream.Flush();
stream.Position = 0;

BinaryReader reader = new BinaryReader(stream);
byte[] readBytes = reader.ReadBytes(bytes.Length + 1);
Assert.Equal(bytes, readBytes);
}
}
}
}
}
Loading