2022-06-30 01:46:41 +02:00
|
|
|
|
using Bit.Icons.Services;
|
2021-10-28 20:30:41 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Icons.Test.Services;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2021-10-28 20:30:41 +02:00
|
|
|
|
public class IconFetchingServiceTests
|
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
[Theory]
|
2021-10-28 20:30:41 +02:00
|
|
|
|
[InlineData("www.google.com")] // https site
|
|
|
|
|
[InlineData("neverssl.com")] // http site
|
|
|
|
|
[InlineData("ameritrade.com")]
|
|
|
|
|
[InlineData("icloud.com")]
|
|
|
|
|
[InlineData("bofa.com", Skip = "Broken in pipeline for .NET 6. Tracking link: https://bitwarden.atlassian.net/browse/PS-982")]
|
|
|
|
|
public async Task GetIconAsync_Success(string domain)
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2021-10-28 20:30:41 +02:00
|
|
|
|
var sut = new IconFetchingService(GetLogger());
|
|
|
|
|
var result = await sut.GetIconAsync(domain);
|
2022-08-29 20:53:16 +02:00
|
|
|
|
|
2021-10-28 20:30:41 +02:00
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.NotNull(result.Icon);
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
[Theory]
|
2021-10-28 20:30:41 +02:00
|
|
|
|
[InlineData("1.1.1.1")]
|
|
|
|
|
[InlineData("")]
|
|
|
|
|
[InlineData("localhost")]
|
|
|
|
|
public async Task GetIconAsync_ReturnsNull(string domain)
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-10-28 20:30:41 +02:00
|
|
|
|
var sut = new IconFetchingService(GetLogger());
|
|
|
|
|
var result = await sut.GetIconAsync(domain);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2021-10-28 20:30:41 +02:00
|
|
|
|
Assert.Null(result);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 20:30:41 +02:00
|
|
|
|
private static ILogger<IconFetchingService> GetLogger()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-10-28 20:30:41 +02:00
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
|
services.AddLogging(b =>
|
|
|
|
|
{
|
|
|
|
|
b.ClearProviders();
|
|
|
|
|
b.AddDebug();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
return provider.GetRequiredService<ILogger<IconFetchingService>>();
|
|
|
|
|
}
|
|
|
|
|
}
|