-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update CRUD samples #12693
Update CRUD samples #12693
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using Azure.Messaging.ServiceBus.Management; | ||
using Moq; | ||
|
@@ -17,40 +16,47 @@ public async Task CreateQueue() | |
{ | ||
string queueName = Guid.NewGuid().ToString("D").Substring(0, 8); | ||
string connectionString = TestEnvironment.ServiceBusConnectionString; | ||
var client = new ServiceBusManagementClient(connectionString); | ||
#region Snippet:CreateQueue | ||
//@@ string connectionString = "<connection_string>"; | ||
//@@ string queueName = "<queue_name>"; | ||
//@@ var client = new ServiceBusClient(connectionString); | ||
var queueDescription = new QueueDescription(queueName) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Consider renaming the class/file to (see also: Capitalization Conventions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PascalCasing is appropriate here, but yeah the acronym should not be all caps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ROFL. Yeah, way to comment with the exact opposite of what I actually mean. I'll go sit in the corner now. |
||
try | ||
{ | ||
AutoDeleteOnIdle = TimeSpan.FromDays(7), | ||
DefaultMessageTimeToLive = TimeSpan.FromDays(2), | ||
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1), | ||
EnableBatchedOperations = true, | ||
DeadLetteringOnMessageExpiration = true, | ||
EnablePartitioning = false, | ||
ForwardDeadLetteredMessagesTo = null, | ||
ForwardTo = null, | ||
LockDuration = TimeSpan.FromSeconds(45), | ||
MaxDeliveryCount = 8, | ||
MaxSizeInMegabytes = 2048, | ||
RequiresDuplicateDetection = true, | ||
RequiresSession = true, | ||
UserMetadata = "some metadata" | ||
}; | ||
|
||
queueDescription.AuthorizationRules.Add(new SharedAccessAuthorizationRule( | ||
"allClaims", | ||
new[] { AccessRights.Manage, AccessRights.Send, AccessRights.Listen })); | ||
|
||
// The CreateQueueAsync method will return the created queue | ||
// which would include values for all of the | ||
// QueueDescription properties (the service will supply | ||
// default values for properties not included in the creation). | ||
QueueDescription createdQueue = await client.CreateQueueAsync(queueDescription); | ||
#endregion | ||
Assert.AreEqual(queueDescription, createdQueue); | ||
#region Snippet:CreateQueue | ||
//@@ string connectionString = "<connection_string>"; | ||
//@@ string queueName = "<queue_name>"; | ||
var client = new ServiceBusManagementClient(connectionString); | ||
var queueDescription = new QueueDescription(queueName) | ||
{ | ||
AutoDeleteOnIdle = TimeSpan.FromDays(7), | ||
DefaultMessageTimeToLive = TimeSpan.FromDays(2), | ||
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1), | ||
EnableBatchedOperations = true, | ||
DeadLetteringOnMessageExpiration = true, | ||
EnablePartitioning = false, | ||
ForwardDeadLetteredMessagesTo = null, | ||
ForwardTo = null, | ||
LockDuration = TimeSpan.FromSeconds(45), | ||
MaxDeliveryCount = 8, | ||
MaxSizeInMegabytes = 2048, | ||
RequiresDuplicateDetection = true, | ||
RequiresSession = true, | ||
UserMetadata = "some metadata" | ||
}; | ||
|
||
queueDescription.AuthorizationRules.Add(new SharedAccessAuthorizationRule( | ||
"allClaims", | ||
new[] { AccessRights.Manage, AccessRights.Send, AccessRights.Listen })); | ||
|
||
// The CreateQueueAsync method will return the created queue | ||
// which would include values for all of the | ||
// QueueDescription properties (the service will supply | ||
// default values for properties not included in the creation). | ||
QueueDescription createdQueue = await client.CreateQueueAsync(queueDescription); | ||
#endregion | ||
Assert.AreEqual(queueDescription, createdQueue); | ||
} | ||
finally | ||
{ | ||
await new ServiceBusManagementClient(connectionString).DeleteQueueAsync(queueName); | ||
} | ||
} | ||
|
||
[Test] | ||
|
@@ -60,8 +66,8 @@ public async Task GetUpdateDeleteQueue() | |
string connectionString = TestEnvironment.ServiceBusConnectionString; | ||
var client = new ServiceBusManagementClient(connectionString); | ||
var qd = new QueueDescription(queueName); | ||
|
||
await client.CreateQueueAsync(qd); | ||
|
||
#region Snippet:GetQueue | ||
QueueDescription queueDescription = await client.GetQueueAsync(queueName); | ||
#endregion | ||
|
@@ -78,5 +84,105 @@ public async Task GetUpdateDeleteQueue() | |
await client.GetQueueAsync(queueName), | ||
Throws.InstanceOf<ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task CreateTopicAndSubscription() | ||
{ | ||
string topicName = Guid.NewGuid().ToString("D").Substring(0, 8); | ||
string subscriptionName = Guid.NewGuid().ToString("D").Substring(0, 8); | ||
string connectionString = TestEnvironment.ServiceBusConnectionString; | ||
var client = new ServiceBusManagementClient(connectionString); | ||
|
||
try | ||
{ | ||
#region Snippet:CreateTopicAndSubscription | ||
//@@ string connectionString = "<connection_string>"; | ||
//@@ string topicName = "<topic_name>"; | ||
//@@ var client = new ServiceBusManagementClient(connectionString); | ||
var topicDescription = new TopicDescription(topicName) | ||
{ | ||
AutoDeleteOnIdle = TimeSpan.FromDays(7), | ||
DefaultMessageTimeToLive = TimeSpan.FromDays(2), | ||
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1), | ||
EnableBatchedOperations = true, | ||
EnablePartitioning = false, | ||
MaxSizeInMegabytes = 2048, | ||
RequiresDuplicateDetection = true, | ||
UserMetadata = "some metadata" | ||
}; | ||
|
||
topicDescription.AuthorizationRules.Add(new SharedAccessAuthorizationRule( | ||
"allClaims", | ||
new[] { AccessRights.Manage, AccessRights.Send, AccessRights.Listen })); | ||
|
||
TopicDescription createdTopic = await client.CreateTopicAsync(topicDescription); | ||
|
||
//@@ string subscriptionName = "<subscription_name>"; | ||
var subscriptionDescription = new SubscriptionDescription(topicName, subscriptionName) | ||
{ | ||
AutoDeleteOnIdle = TimeSpan.FromDays(7), | ||
DefaultMessageTimeToLive = TimeSpan.FromDays(2), | ||
EnableBatchedOperations = true, | ||
UserMetadata = "some metadata" | ||
}; | ||
SubscriptionDescription createdSubscription = await client.CreateSubscriptionAsync(subscriptionDescription); | ||
#endregion | ||
Assert.AreEqual(topicDescription, createdTopic); | ||
Assert.AreEqual(subscriptionDescription, createdSubscription); | ||
} | ||
finally | ||
{ | ||
await client.DeleteTopicAsync(topicName); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task GetUpdateDeleteTopicAndSubscription() | ||
{ | ||
string topicName = Guid.NewGuid().ToString("D").Substring(0, 8); | ||
string subscriptionName = Guid.NewGuid().ToString("D").Substring(0, 8); | ||
string connectionString = TestEnvironment.ServiceBusConnectionString; | ||
var client = new ServiceBusManagementClient(connectionString); | ||
var td = new TopicDescription(topicName); | ||
var sd = new SubscriptionDescription(topicName, subscriptionName); | ||
await client.CreateTopicAsync(td); | ||
await client.CreateSubscriptionAsync(sd); | ||
#region Snippet:GetTopic | ||
TopicDescription topicDescription = await client.GetTopicAsync(topicName); | ||
#endregion | ||
#region Snippet:GetSubscription | ||
SubscriptionDescription subscriptionDescription = await client.GetSubscriptionAsync(topicName, subscriptionName); | ||
#endregion | ||
#region Snippet:UpdateTopic | ||
topicDescription.UserMetadata = "some metadata"; | ||
TopicDescription updatedTopic = await client.UpdateTopicAsync(topicDescription); | ||
#endregion | ||
Assert.AreEqual("some metadata", updatedTopic.UserMetadata); | ||
|
||
#region Snippet:UpdateSubscription | ||
subscriptionDescription.UserMetadata = "some metadata"; | ||
SubscriptionDescription updatedSubscription = await client.UpdateSubscriptionAsync(subscriptionDescription); | ||
#endregion | ||
Assert.AreEqual("some metadata", updatedSubscription.UserMetadata); | ||
|
||
// need to delete the subscription before the topic, as deleting | ||
// the topic would automatically delete the subscription | ||
#region Snippet:DeleteSubscription | ||
await client.DeleteSubscriptionAsync(topicName, subscriptionName); | ||
#endregion | ||
Assert.That( | ||
async () => | ||
await client.GetSubscriptionAsync(topicName, subscriptionName), | ||
Throws.InstanceOf<ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); | ||
|
||
#region Snippet:DeleteTopic | ||
await client.DeleteTopicAsync(topicName); | ||
#endregion | ||
Assert.That( | ||
async () => | ||
await client.GetTopicAsync(topicName), | ||
Throws.InstanceOf<ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusException.FailureReason.MessagingEntityNotFound)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... "using the name of the topic", maybe? It reads a bit awkward to me as written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha woops