-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve code coverage DevicesClient V2 (#3073)
* Add more unit tests * Address comments * Create new tests * Work in progress * Work in progress * Work in progress * Add more unit tests * Make methods virtual and write more unit test cases * Add more test * Add comment * Rename test case * remove extra line * remove extra line * Address comments * Add comments
- Loading branch information
Showing
12 changed files
with
1,082 additions
and
11 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
iothub/service/tests/Feedback/MessageFeedbackProcessorClientTests.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,73 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.Azure.Devices.Tests.Feedback | ||
{ | ||
[TestClass] | ||
[TestCategory("Unit")] | ||
public class MessageFeedbackProcessorClientTests | ||
{ | ||
private const string HostName = "contoso.azure-devices.net"; | ||
private static readonly string s_connectionString = $"HostName={HostName};SharedAccessKeyName=iothubowner;SharedAccessKey=dGVzdFN0cmluZzE="; | ||
|
||
private static IIotHubServiceRetryPolicy noRetryPolicy = new IotHubServiceNoRetry(); | ||
private static IotHubServiceClientOptions s_options = new() | ||
{ | ||
Protocol = IotHubTransportProtocol.Tcp, | ||
RetryPolicy = noRetryPolicy | ||
}; | ||
|
||
[TestMethod] | ||
public async Task MessageFeedbackProcessorClient_OpenAsync_NotSettingMessageFeedbackProcessorThrows() | ||
{ | ||
// arrange | ||
using var serviceClient = new IotHubServiceClient( | ||
s_connectionString, | ||
s_options); | ||
|
||
// act | ||
Func<Task> act = async () => await serviceClient.MessageFeedback.OpenAsync().ConfigureAwait(false); | ||
|
||
// assert | ||
await act.Should().ThrowAsync<InvalidOperationException>(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task MessageFeedbackProcessorClient_OpenAsync_Cancelled_ThrowsOperationCanceledException() | ||
{ | ||
// arrange | ||
using var serviceClient = new IotHubServiceClient( | ||
s_connectionString, | ||
s_options); | ||
|
||
// act | ||
var ct = new CancellationToken(true); | ||
Func<Task> act = async () => await serviceClient.MessageFeedback.OpenAsync(ct); | ||
|
||
// assert | ||
await act.Should().ThrowAsync<OperationCanceledException>(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task MessageFeedbackProcessorClient_CloseAsync_Cancelled_ThrowsOperationCanceledException() | ||
{ | ||
// arrange | ||
using var serviceClient = new IotHubServiceClient( | ||
s_connectionString, | ||
s_options); | ||
|
||
// act | ||
var ct = new CancellationToken(true); | ||
Func<Task> act = async () => await serviceClient.MessageFeedback.CloseAsync(ct); | ||
|
||
// assert | ||
await act.Should().ThrowAsync<OperationCanceledException>(); | ||
} | ||
} | ||
} |
Oops, something went wrong.