mirror of
https://dev.azure.com/tstanciu94/PhantomMind/_git/Bitip
synced 2025-10-13 01:52:19 +03:00
- Implement GetHealthTests to validate health check responses and error handling. - Implement GetIpLocationTests for IP geolocation lookups, including valid and invalid cases. - Implement GetVersionTests to check version retrieval and error handling. - Create BitipClientTestFixture for mocking HTTP responses in tests. - Add RealApiIntegrationTests for testing against a live Bitip API instance. - Introduce TestConfiguration for managing test settings and API keys. - Update Bitip.Client.csproj with package metadata and licensing information. - Add LICENSE file for MIT License compliance. - Create README.md with detailed usage instructions and examples. - Establish RELEASE.md for publishing guidelines and version management. - Add AssemblyInfo.cs for internal visibility to tests.
107 lines
3.3 KiB
C#
107 lines
3.3 KiB
C#
// Copyright (c) 2025 Tudor Stanciu
|
|
|
|
using Bitip.Client.Services;
|
|
using Bitip.Client.Tests.Helpers;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Bitip.Client.Tests.Integration
|
|
{
|
|
/// <summary>
|
|
/// Integration tests that make real API calls to a live Bitip instance.
|
|
/// These tests are DISABLED by default (TestConfiguration.UseRealApi = false).
|
|
/// </summary>
|
|
public class RealApiIntegrationTests
|
|
{
|
|
private readonly IServiceProvider? _realServiceProvider;
|
|
|
|
public RealApiIntegrationTests()
|
|
{
|
|
_realServiceProvider = BitipClientTestFixture.CreateRealServiceProvider();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetHealth_ReturnsHealthInfo()
|
|
{
|
|
// Skip if not configured for real API
|
|
if (!TestConfiguration.UseRealApi || _realServiceProvider == null)
|
|
return;
|
|
|
|
// Arrange
|
|
var client = _realServiceProvider.GetRequiredService<IBitipClient>();
|
|
|
|
// Act
|
|
var result = await client.GetHealth();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.NotNull(result.Status);
|
|
Assert.NotNull(result.Service);
|
|
Assert.True(result.Timestamp > DateTime.MinValue);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetVersion_ReturnsVersionInfo()
|
|
{
|
|
// Skip if not configured for real API
|
|
if (!TestConfiguration.UseRealApi || _realServiceProvider == null)
|
|
return;
|
|
|
|
// Arrange
|
|
var client = _realServiceProvider.GetRequiredService<IBitipClient>();
|
|
|
|
// Act
|
|
var result = await client.GetVersion();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.NotNull(result.Version);
|
|
Assert.NotNull(result.CommitHash);
|
|
Assert.True(result.BuildDate > DateTime.MinValue);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetIpLocation_ReturnsLocation()
|
|
{
|
|
// Skip if not configured for real API
|
|
if (!TestConfiguration.UseRealApi || _realServiceProvider == null)
|
|
return;
|
|
|
|
// Arrange
|
|
var client = _realServiceProvider.GetRequiredService<IBitipClient>();
|
|
|
|
// Act
|
|
var result = await client.GetIpLocation(TestConfiguration.ValidIpV4);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(TestConfiguration.ValidIpV4, result.Ip);
|
|
Assert.NotNull(result.Country);
|
|
Assert.NotNull(result.CountryCode);
|
|
Assert.NotNull(result.City);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetDetailedIpLocation_ReturnsDetailedLocation()
|
|
{
|
|
// Skip if not configured for real API
|
|
if (!TestConfiguration.UseRealApi || _realServiceProvider == null)
|
|
return;
|
|
|
|
// Arrange
|
|
var client = _realServiceProvider.GetRequiredService<IBitipClient>();
|
|
|
|
// Act
|
|
var result = await client.GetDetailedIpLocation(TestConfiguration.ValidIpV4);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(TestConfiguration.ValidIpV4, result.Ip);
|
|
Assert.NotNull(result.Location);
|
|
Assert.NotNull(result.Asn);
|
|
}
|
|
}
|
|
}
|