Commit 94790c4c authored by HankG's avatar HankG

Cleanup link preview service test

parent 10de703b
......@@ -4,15 +4,20 @@ using System.IO;
using MySocialPortalLib.Repository;
using MySocialPortalLib.Service;
using Xunit;
using Xunit.Abstractions;
namespace MySocialPortalLibTest.Service
{
public class LinkPreviewServiceTest : IDisposable
{
private readonly ITestOutputHelper _testOutputHelper;
private readonly string _tmpFolder = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid().ToString()}");
public LinkPreviewServiceTest()
private FileCacheLiteDbRepository _cacheRepository;
private LinkPreviewLiteDbRepository _linkPreviewRepository;
public LinkPreviewServiceTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
Directory.CreateDirectory(_tmpFolder);
}
......@@ -38,6 +43,16 @@ namespace MySocialPortalLibTest.Service
Assert.NotEqual(DateTimeOffset.UnixEpoch, preview.TimeGeneraterated);
}
[Fact]
public void TestDisposeLockup()
{
var url = "https://twitter.com/dcherring/status/1198968638285524995";
var service = GetTmpLinkPreviewService();
var preview = service.GetPreview(url).Result;
Assert.NotNull(preview);
_testOutputHelper.WriteLine(preview.PreviewImageName);
}
[Fact]
public void TestBadUrl()
{
......@@ -49,20 +64,22 @@ namespace MySocialPortalLibTest.Service
private LinkPreviewService GetTmpLinkPreviewService()
{
IFileCacheRepository cacheRepository = new FileCacheLiteDbRepository(new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate,
_cacheRepository = new FileCacheLiteDbRepository(new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.None, 4096,
FileOptions.RandomAccess | FileOptions.DeleteOnClose));
var imageService = new ImageService(cacheRepository, _tmpFolder);
var imageService = new ImageService(_cacheRepository, _tmpFolder);
var lpRepo = new LinkPreviewLiteDbRepository(new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate,
_linkPreviewRepository = new LinkPreviewLiteDbRepository(new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.None, 4096,
FileOptions.RandomAccess | FileOptions.DeleteOnClose));
return new LinkPreviewService(lpRepo, imageService);
return new LinkPreviewService(_linkPreviewRepository, imageService);
}
public void Dispose()
{
_cacheRepository.Dispose();
_linkPreviewRepository.Dispose();
Directory.Delete(_tmpFolder, true);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment