Skip to content
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

Gfeitosa/increase coverage include int #39392

Merged
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
/sdk/communication/Azure.Communication.ShortCodes/ @guilhermeluizsp @danielav7

# PRLabel: %Communication - SMS
/sdk/communication/Azure.Communication.Sms/ @RoyHerrod @arifibrahim4
/sdk/communication/Azure.Communication.Sms/ @DimaKolomiiets @ozgurcivi-msft @gfeitosa-msft @phermanov-msft @ilyapaliakou-msft

# PRLabel: %Communication - Resource Manager
/sdk/communication/Azure.ResourceManager.Communication/ @archerzz @ArcturusZhang @ArthurMa1978
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
using System.Runtime.CompilerServices;

[assembly: Azure.Core.AzureResourceProviderNamespace("Communication")]
[assembly: InternalsVisibleTo("Azure.Communication.Sms.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")]
7 changes: 6 additions & 1 deletion sdk/communication/Azure.Communication.Sms/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ extends:
- $(sub-config-azure-cloud-test-resources)
- $(sub-config-communication-services-cloud-test-resources-common)
- $(sub-config-communication-services-cloud-test-resources-net)
Clouds: Public
- $(sub-config-communication-services-sms-cloud-test-resources)
Int:
SubscriptionConfigurations:
- $(sub-config-communication-int-test-resources-common)
- $(sub-config-communication-int-test-resources-net)
Clouds: Public,Int
TestResourceDirectories:
- communication/test-resources/
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\..\Azure.Communication.Common\src\Azure.Communication.Common.csproj" />
<ProjectReference Include="..\src\Azure.Communication.Sms.csproj" />
<Compile Include="..\..\Shared\tests\AuthMethod.cs" LinkBase="Shared\Communication.Tests" />
<Compile Include="..\..\Shared\tests\CommunicationTestEnvironment.cs" LinkBase="Shared\Communication.Tests" />
</ItemGroup>
<!-- Shared source from Azure.Core -->
<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)ConnectionString.cs" Link="Shared\\ConnectionString.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\tests.yml" Link="\tests.yml" />
<None Include="..\samples\README.md" Link="samples\README.md" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public SmsClient CreateSmsClient()
return InstrumentClient(client);
}

public SmsClient CreateSmsClientWithNullOptions()
{
var connectionString = TestEnvironment.LiveTestStaticConnectionString;
SmsClient client = new SmsClient(connectionString, null);

return InstrumentClient(client);
}

public SmsClient CreateSmsClientWithoutOptions()
{
var connectionString = TestEnvironment.LiveTestStaticConnectionString;
SmsClient client = new SmsClient(connectionString);

return InstrumentClient(client);
}

public SmsClient CreateSmsClientWithToken()
{
Uri endpoint = TestEnvironment.LiveTestStaticEndpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task SendingSmsMessageUsingTokenCredential()
[TestCase("+15550000000", Description = "Fake number")]
public async Task SendingSmsMessageFromUnauthorizedNumber(string from)
{
SmsClient client = CreateSmsClient();
SmsClient client = CreateSmsClientWithNullOptions();
try
{
SmsSendResult result = await client.SendAsync(
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task SendingTwoSmsMessages()
[Test]
public async Task SendingSmsFromNullNumberShouldThrow()
{
SmsClient client = CreateSmsClient();
SmsClient client = CreateSmsClientWithoutOptions();
try
{
SmsSendResult result = await client.SendAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,65 @@
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Azure.Communication.Sms.Models;
using Azure.Core;
using Azure.Core.TestFramework;
using Moq;
using NUnit.Framework;

namespace Azure.Communication.Sms.Tests
{
public class SmsClientTest
{
[Test]
public void SmsClient_ThrowsWithNullKeyCredential()
{
AzureKeyCredential? nullCredential = null;
Uri uri = new Uri("http://localhost");

Assert.Throws<ArgumentNullException>(() => new SmsClient(uri, nullCredential));
}

[Test]
public void SmsClient_ThrowsWithNullUri()
{
AzureKeyCredential mockCredential = new AzureKeyCredential("mockKey");

Assert.Throws<ArgumentNullException>(() => new SmsClient(null, mockCredential));
}

[Test]
public void SmsClient_KeyCredential_ValidParameters()
{
AzureKeyCredential mockCredential = new AzureKeyCredential("mockKey");
Uri uri = new Uri("http://localhost");

Assert.DoesNotThrow(() => new SmsClient(uri, mockCredential));
}

[Test]
public void SmsClient_TokenCredential_NullOptions()
{
TokenCredential mockCredential = new MockCredential();
Uri endpoint = new Uri("http://localhost");

Assert.DoesNotThrow(() => new SmsClient(endpoint, mockCredential, null));
}

[Test]
public void SmsClient_ThrowsWithNullOrEmptyConnectionString()
{
Assert.Throws<ArgumentException>(() => new SmsClient(string.Empty));
Assert.Throws<ArgumentNullException>(() => new SmsClient(null));
}

[Test]
public void SmsClientOptions_ThrowsWithInvalidVersion()
{
var invalidServiceVersion = (SmsClientOptions.ServiceVersion)2;

Assert.Throws<ArgumentOutOfRangeException>(() => new SmsClientOptions(invalidServiceVersion));
}

[TestCaseSource(nameof(TestDataForSingleSms))]
public async Task SendSmsAsyncOverload_PassesToGeneratedOne(string expectedFrom, string expectedTo, string expectedMessage, SmsSendOptions expectedOptions)
{
Expand Down
178 changes: 178 additions & 0 deletions sdk/communication/Azure.Communication.Sms/tests/SmsRestClientTest.cs
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);
}
}
}