-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid NRE and disposed exceptions when closing client twice (#3312)
- Loading branch information
Showing
2 changed files
with
55 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.Azure.Devices.E2ETests.Helpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.Azure.Devices.E2ETests | ||
{ | ||
[TestClass] | ||
[TestCategory("E2E")] | ||
[TestCategory("IoTHub")] | ||
public class DeviceClientE2eTests | ||
{ | ||
[TestMethod] | ||
public async Task DeviceClient_CloseAsync_CanBeCalledTwice() | ||
{ | ||
// arrange | ||
|
||
using TestDevice testDevice = await TestDevice.GetTestDeviceAsync(nameof(DeviceClient_CloseAsync_CanBeCalledTwice)); | ||
|
||
try | ||
{ | ||
using Client.DeviceClient client = testDevice.CreateDeviceClient(Client.TransportType.Amqp_Tcp_Only); | ||
await client.OpenAsync().ConfigureAwait(false); | ||
await client.CloseAsync().ConfigureAwait(false); | ||
|
||
// act | ||
Func<Task> act = () => client.CloseAsync(); | ||
|
||
// assert | ||
await act.Should().NotThrowAsync().ConfigureAwait(false); | ||
} | ||
finally | ||
{ | ||
await testDevice.RemoveDeviceAsync().ConfigureAwait(false); | ||
testDevice.Dispose(); | ||
} | ||
|
||
} | ||
} | ||
} |
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