-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gfeitosa/increase coverage include int (#39392)
* Remove common package from coverage report * Added SMS speciffic phone number to test pipeline * Fix typo in yml file * Extra tests implemented * Add a few extra tests for coverage * Add a few extra tests for coverage * Remove unecessary usings * Fix assert exception * Remove shared core ConnectionString from tests * Make internal classes visible to test package * Implement SmsRestClient tests for coverage * Remove duplicate snippets * Update code owners for SMS sdk to include only SMS team * Remove missing user from codeowners file
- Loading branch information
1 parent
9e033be
commit 8e52e83
Showing
8 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
sdk/communication/Azure.Communication.Sms/tests/SmsRestClientTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Azure.Communication.Sms.Models; | ||
using Azure.Core.Pipeline; | ||
using Azure.Core.TestFramework; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Communication.Sms.Tests | ||
{ | ||
public class SmsRestClientTest | ||
{ | ||
[Test] | ||
public void SmsRestClient_NullClientDiagnostics_ShouldThrow() | ||
{ | ||
var httpPipeline = HttpPipelineBuilder.Build(new SmsClientOptions()); | ||
var uri = "http://localhost"; | ||
|
||
Assert.Throws<ArgumentNullException>(() => new SmsRestClient(null, httpPipeline, uri)); | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_NullHttpPipeline_ShouldThrow() | ||
{ | ||
var clientDiagnostics = new ClientDiagnostics(new SmsClientOptions()); | ||
var endpoint = "http://localhost"; | ||
|
||
Assert.Throws<ArgumentNullException>(() => new SmsRestClient(clientDiagnostics, null, endpoint)); | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_NullEndpoint_ShouldThrow() | ||
{ | ||
var clientDiagnostics = new ClientDiagnostics(new SmsClientOptions()); | ||
var httpPipeline = HttpPipelineBuilder.Build(new SmsClientOptions()); | ||
|
||
Assert.Throws<ArgumentNullException>(() => new SmsRestClient(clientDiagnostics, httpPipeline, null)); | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_NullVersion_ShouldThrow() | ||
{ | ||
var clientOptions = new SmsClientOptions(); | ||
var clientDiagnostics = new ClientDiagnostics(clientOptions); | ||
var httpPipeline = HttpPipelineBuilder.Build(clientOptions); | ||
var uri = "http://localhost"; | ||
|
||
Assert.Throws<ArgumentNullException>(() => new SmsRestClient(clientDiagnostics, httpPipeline, uri, null)); | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_SendWithNullSender_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var recipients = Enumerable.Empty<SmsRecipient>(); | ||
var message = "Message"; | ||
|
||
try | ||
{ | ||
client.Send(null, recipients, message); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("from", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_SendWithNullRecipients_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var from = "+123456789"; | ||
var message = "Message"; | ||
|
||
try | ||
{ | ||
client.Send(from, null, message); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("smsRecipients", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
[Test] | ||
public void SmsRestClient_SendWithNullMessage_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var from = "+123456789"; | ||
var recipients = Enumerable.Empty<SmsRecipient>(); | ||
|
||
try | ||
{ | ||
client.Send(from, recipients, null); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("message", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task SmsRestClient_SendAsyncWithNullSender_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var recipients = Enumerable.Empty<SmsRecipient>(); | ||
var message = "Message"; | ||
|
||
try | ||
{ | ||
await client.SendAsync(null, recipients, message); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("from", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task SmsRestClient_SendAsyncWithNullRecipients_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var from = "+123456789"; | ||
var message = "Message"; | ||
|
||
try | ||
{ | ||
await client.SendAsync(from, null, message); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("smsRecipients", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task SmsRestClient_SendAsyncWithNullMessage_ShouldThrow() | ||
{ | ||
var client = CreateSmsRestClient(); | ||
|
||
var from = "+123456789"; | ||
var recipients = Enumerable.Empty<SmsRecipient>(); | ||
|
||
try | ||
{ | ||
await client.SendAsync(from, recipients, null); | ||
} | ||
catch (ArgumentNullException ex) | ||
{ | ||
Assert.AreEqual("message", ex.ParamName); | ||
return; | ||
} | ||
} | ||
|
||
private SmsRestClient CreateSmsRestClient() | ||
{ | ||
var clientOptions = new SmsClientOptions(); | ||
var clientDiagnostics = new ClientDiagnostics(clientOptions); | ||
var httpPipeline = HttpPipelineBuilder.Build(clientOptions); | ||
var endpoint = "http://localhost"; | ||
|
||
return new SmsRestClient(clientDiagnostics, httpPipeline, endpoint); | ||
} | ||
} | ||
} |