100 lines
3.5 KiB
C#
100 lines
3.5 KiB
C#
using Omika.Core.Observability.Diagnostic;
|
|
|
|
namespace Omika.Tests.Observability.Diagnostic;
|
|
|
|
/// <summary>
|
|
/// Tests des helpers purs de capture d'appareil (T17-C). La logique commune aux
|
|
/// providers Android/iOS (normalisation, bornage, orientation stable, chaîne
|
|
/// DeviceInfo) est testée ici sans runtime mobile.
|
|
/// </summary>
|
|
public class DeviceInfoCaptureTests
|
|
{
|
|
[Theory]
|
|
[InlineData(null, null)]
|
|
[InlineData("", null)]
|
|
[InlineData(" ", null)]
|
|
[InlineData("Xiaomi", "Xiaomi")]
|
|
[InlineData(" Xiaomi ", "Xiaomi")]
|
|
public void Clean_TrimsAndNullsEmpty(string? input, string? expected)
|
|
=> Assert.Equal(expected, DeviceInfoCapture.Clean(input));
|
|
|
|
[Fact]
|
|
public void Clean_TruncatesToMaxLength()
|
|
{
|
|
string longValue = new string('a', DeviceInfoCapture.MaxFieldLength + 50);
|
|
|
|
string? result = DeviceInfoCapture.Clean(longValue);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal(DeviceInfoCapture.MaxFieldLength, result!.Length);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1080, 2400, 1080, 2400)] // portrait
|
|
[InlineData(2400, 1080, 1080, 2400)] // paysage → même résultat (stable)
|
|
[InlineData(1290, 2796, 1290, 2796)]
|
|
[InlineData(0, 100, null, null)]
|
|
[InlineData(-5, 100, null, null)]
|
|
[InlineData(null, 100, null, null)]
|
|
public void Normalize_IsOrientationStable(int? w, int? h, int? expectedWidth, int? expectedHeight)
|
|
{
|
|
(int Width, int Height)? result = DeviceInfoCapture.Normalize(w, h);
|
|
|
|
Assert.Equal(expectedWidth, result?.Width);
|
|
Assert.Equal(expectedHeight, result?.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void NormalizeScale_RejectsNonPositiveOrNaN()
|
|
{
|
|
Assert.Null(DeviceInfoCapture.NormalizeScale(null));
|
|
Assert.Null(DeviceInfoCapture.NormalizeScale(0));
|
|
Assert.Null(DeviceInfoCapture.NormalizeScale(-1));
|
|
Assert.Null(DeviceInfoCapture.NormalizeScale(double.NaN));
|
|
Assert.Equal(2.75, DeviceInfoCapture.NormalizeScale(2.75));
|
|
Assert.Equal(3.0, DeviceInfoCapture.NormalizeScale(3.00004));
|
|
}
|
|
|
|
[Fact]
|
|
public void RoundDimension_ReturnsNullForInvalid()
|
|
{
|
|
Assert.Null(DeviceInfoCapture.RoundDimension(null));
|
|
Assert.Null(DeviceInfoCapture.RoundDimension(0));
|
|
Assert.Null(DeviceInfoCapture.RoundDimension(double.NaN));
|
|
Assert.Equal(393, DeviceInfoCapture.RoundDimension(392.6));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildLicenseDeviceInfo_ContainsOnlyManufacturerAndModel()
|
|
{
|
|
var snapshot = new DeviceInfoSnapshot
|
|
{
|
|
DeviceManufacturer = "Apple",
|
|
DeviceModel = "iPhone17,2"
|
|
};
|
|
|
|
Assert.Equal("manufacturer=Apple;model=iPhone17,2", DeviceInfoCapture.BuildLicenseDeviceInfo(snapshot));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildLicenseDeviceInfo_ReturnsNullWhenNoHardware()
|
|
=> Assert.Null(DeviceInfoCapture.BuildLicenseDeviceInfo(DeviceInfoSnapshot.Empty));
|
|
|
|
[Fact]
|
|
public void BuildLicenseDeviceInfo_NeverContainsForbiddenIdentifiers()
|
|
{
|
|
var snapshot = new DeviceInfoSnapshot
|
|
{
|
|
DeviceManufacturer = "Samsung",
|
|
DeviceModel = "SM-S928B"
|
|
};
|
|
|
|
string? info = DeviceInfoCapture.BuildLicenseDeviceInfo(snapshot);
|
|
|
|
Assert.DoesNotContain("device", info, StringComparison.OrdinalIgnoreCase);
|
|
Assert.DoesNotContain("token", info, StringComparison.OrdinalIgnoreCase);
|
|
Assert.DoesNotContain("imei", info, StringComparison.OrdinalIgnoreCase);
|
|
Assert.DoesNotContain("serial", info, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|