|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Azure.Core.TestFramework; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace Azure.Communication.Sms.Tests.samples |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Samples that are used in the README.md file. |
| 13 | + /// </summary> |
| 14 | + public partial class Sample2_OptOutsApi : SmsClientLiveTestBase |
| 15 | + { |
| 16 | + public Sample2_OptOutsApi(bool isAsync) : base(isAsync) |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + [Test] |
| 21 | + [AsyncOnly] |
| 22 | + public async Task CheckOptOutAsync() |
| 23 | + { |
| 24 | + SmsClient smsClient = CreateSmsClient(); |
| 25 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_CheckAsync |
| 26 | + var optOutCheckResults = await smsClient.OptOuts.CheckAsync( |
| 27 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 28 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 29 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 30 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 31 | + foreach (var result in optOutCheckResults.Value) |
| 32 | + { |
| 33 | + Console.WriteLine($"{result.To}: {result.IsOptedOut}"); |
| 34 | + } |
| 35 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_CheckAsync |
| 36 | + } |
| 37 | + |
| 38 | + [Test] |
| 39 | + [AsyncOnly] |
| 40 | + public async Task AddOptOutAsync() |
| 41 | + { |
| 42 | + SmsClient smsClient = CreateSmsClient(); |
| 43 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_AddAsync |
| 44 | + var optOutAddResults = await smsClient.OptOuts.AddAsync( |
| 45 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 46 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 47 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 48 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 49 | + foreach (var result in optOutAddResults.Value) |
| 50 | + { |
| 51 | + Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); |
| 52 | + } |
| 53 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_AddAsync |
| 54 | + } |
| 55 | + |
| 56 | + [Test] |
| 57 | + [AsyncOnly] |
| 58 | + public async Task RemoveOptOutAsync() |
| 59 | + { |
| 60 | + SmsClient smsClient = CreateSmsClient(); |
| 61 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_RemoveAsync |
| 62 | + var optOutRemoveResults = await smsClient.OptOuts.RemoveAsync( |
| 63 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 64 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 65 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 66 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 67 | + |
| 68 | + foreach (var result in optOutRemoveResults.Value) |
| 69 | + { |
| 70 | + Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); |
| 71 | + } |
| 72 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_RemoveAsync |
| 73 | + } |
| 74 | + |
| 75 | + [Test] |
| 76 | + [SyncOnly] |
| 77 | + public void CheckOptOut() |
| 78 | + { |
| 79 | + SmsClient smsClient = CreateSmsClient(); |
| 80 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Check |
| 81 | + var optOutCheckResults = smsClient.OptOuts.Check( |
| 82 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 83 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 84 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 85 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 86 | + foreach (var result in optOutCheckResults.Value) |
| 87 | + { |
| 88 | + Console.WriteLine($"{result.To}: {result.IsOptedOut}"); |
| 89 | + } |
| 90 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Check |
| 91 | + } |
| 92 | + |
| 93 | + [Test] |
| 94 | + [SyncOnly] |
| 95 | + public void AddOptOut() |
| 96 | + { |
| 97 | + SmsClient smsClient = CreateSmsClient(); |
| 98 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Add |
| 99 | + var optOutAddResults = smsClient.OptOuts.Add( |
| 100 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 101 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 102 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 103 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 104 | + foreach (var result in optOutAddResults.Value) |
| 105 | + { |
| 106 | + Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); |
| 107 | + } |
| 108 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Add |
| 109 | + } |
| 110 | + |
| 111 | + [Test] |
| 112 | + [SyncOnly] |
| 113 | + public void RemoveOptOut() |
| 114 | + { |
| 115 | + SmsClient smsClient = CreateSmsClient(); |
| 116 | + #region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Remove |
| 117 | + var optOutRemoveResults = smsClient.OptOuts.Remove( |
| 118 | + //@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS |
| 119 | + //@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers |
| 120 | + /*@@*/ from: TestEnvironment.FromPhoneNumber, |
| 121 | + /*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); |
| 122 | + |
| 123 | + foreach (var result in optOutRemoveResults.Value) |
| 124 | + { |
| 125 | + Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); |
| 126 | + } |
| 127 | + #endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Remove |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments