From 97d157dc2eda865d25babfd48be50928af79e535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6thinger?= Date: Sat, 11 Nov 2023 17:59:15 +0100 Subject: [PATCH] Updated tests Updated dependencies --- .../AleRoe.HomematicIpApi.Tests.csproj | 4 +- .../HomematicClientCtorTests.cs | 45 ++++++-------- .../HomematicClientDisposeTests.cs | 62 +++++++++++++++++++ 3 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 src/AleRoe.HomematicIPApi.Tests/HomematicClientDisposeTests.cs diff --git a/src/AleRoe.HomematicIPApi.Tests/AleRoe.HomematicIpApi.Tests.csproj b/src/AleRoe.HomematicIPApi.Tests/AleRoe.HomematicIpApi.Tests.csproj index 5468ba3..577d7c4 100644 --- a/src/AleRoe.HomematicIPApi.Tests/AleRoe.HomematicIpApi.Tests.csproj +++ b/src/AleRoe.HomematicIPApi.Tests/AleRoe.HomematicIpApi.Tests.csproj @@ -17,7 +17,7 @@ - + @@ -25,7 +25,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/AleRoe.HomematicIPApi.Tests/HomematicClientCtorTests.cs b/src/AleRoe.HomematicIPApi.Tests/HomematicClientCtorTests.cs index 1ecc5fa..d1f3612 100644 --- a/src/AleRoe.HomematicIPApi.Tests/HomematicClientCtorTests.cs +++ b/src/AleRoe.HomematicIPApi.Tests/HomematicClientCtorTests.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using Microsoft.Extensions.Logging.Abstractions; +using NUnit.Framework; using System; using System.Net.Http; using System.Threading; @@ -45,36 +46,30 @@ public async Task CtorWithHttpClientTest() } [Test()] - public async Task DisposeTest() + public async Task CtorWithLoggerTest() { - var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; - var client = new HomematicIpClient(config); - await client.InitializeAsync(CancellationToken.None); - var events = client.PushEventReceived.Subscribe(msg => { }); - Assert.DoesNotThrow(client.Dispose); - await Task.CompletedTask; - } - - [Test()] - public async Task DisposeWithoutInitializeTest() - { - var config = new HomematicIpConfiguration() {AccessPointId = AccessPoint, AuthToken = AuthToken }; - var client = new HomematicIpClient(config); - Assert.DoesNotThrow(client.Dispose); + Assert.DoesNotThrow(() => + { + using var loggerFactory = new NullLoggerFactory(); + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + using var client = new HomematicIpClient(config, loggerFactory); + Assert.AreSame(loggerFactory, client.loggerFactory); + }); await Task.CompletedTask; } [Test()] - public async Task DisposeWithCustomHttpClientTest() + public async Task CtorWithHttpClientAndLoggerTest() { - var config = new HomematicIpConfiguration() {AccessPointId = AccessPoint, AuthToken = AuthToken }; - using var httpClient = new HttpClient(); - var client = new HomematicIpClient(config, httpClient); - await client.InitializeAsync(CancellationToken.None); - var events = client.PushEventReceived.Subscribe(msg => { }); - - Assert.DoesNotThrow(client.Dispose); - Assert.IsNotNull(client.httpClient); + Assert.DoesNotThrow(() => + { + using var loggerFactory = new NullLoggerFactory(); + using var httpClient = new HttpClient(); + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + using var client = new HomematicIpClient(config, httpClient, loggerFactory); + Assert.AreSame(loggerFactory, client.loggerFactory); + Assert.AreSame(httpClient, client.httpClient); + }); await Task.CompletedTask; } } diff --git a/src/AleRoe.HomematicIPApi.Tests/HomematicClientDisposeTests.cs b/src/AleRoe.HomematicIPApi.Tests/HomematicClientDisposeTests.cs new file mode 100644 index 0000000..c0f4bd0 --- /dev/null +++ b/src/AleRoe.HomematicIPApi.Tests/HomematicClientDisposeTests.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.Logging.Abstractions; +using NUnit.Framework; +using System; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace AleRoe.HomematicIpApi.Tests +{ + [TestFixture()] + public class HomematicClientDisposeTests : HomematicClientTestsBase + { + [Test()] + public async Task DisposeTest() + { + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + var client = new HomematicIpClient(config); + await client.InitializeAsync(CancellationToken.None); + var events = client.PushEventReceived.Subscribe(msg => { }); + Assert.DoesNotThrow(client.Dispose); + await Task.CompletedTask; + } + + [Test()] + public async Task DisposeWithoutInitializeTest() + { + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + var client = new HomematicIpClient(config); + Assert.DoesNotThrow(client.Dispose); + await Task.CompletedTask; + } + + [Test()] + public async Task DisposeWithCustomHttpClientTest() + { + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + using var httpClient = new HttpClient(); + var client = new HomematicIpClient(config, httpClient); + await client.InitializeAsync(CancellationToken.None); + var events = client.PushEventReceived.Subscribe(msg => { }); + + Assert.DoesNotThrow(client.Dispose); + Assert.IsNotNull(client.httpClient); + await Task.CompletedTask; + } + + + [Test()] + public async Task DisposeWithCustomLoggerFactoryTest() + { + var config = new HomematicIpConfiguration() { AccessPointId = AccessPoint, AuthToken = AuthToken }; + using var loggerFactory = new NullLoggerFactory(); + var client = new HomematicIpClient(config, loggerFactory); + await client.InitializeAsync(CancellationToken.None); + var events = client.PushEventReceived.Subscribe(msg => { }); + + Assert.DoesNotThrow(client.Dispose); + Assert.IsNotNull(client.loggerFactory); + await Task.CompletedTask; + } + } +}