Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
Updated dependencies
  • Loading branch information
AleRoe committed Nov 11, 2023
1 parent 32e6be3 commit 97d157d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

Expand Down
45 changes: 20 additions & 25 deletions src/AleRoe.HomematicIPApi.Tests/HomematicClientCtorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using Microsoft.Extensions.Logging.Abstractions;
using NUnit.Framework;
using System;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -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;
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/AleRoe.HomematicIPApi.Tests/HomematicClientDisposeTests.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 97d157d

Please sign in to comment.