Adding
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Configuration;
|
||||
using LCU.API.Collections.RepoApi.HostedServices;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Services.AutoIms;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using Microsoft.AspNetCore.Identity.UI.V3.Pages.Internal.Account.Manage;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AutoImsServiceTest
|
||||
{
|
||||
private readonly AutoImsService _autoImsProcessor;
|
||||
private readonly Mock<IImsAutoFileDataConverter> mockImsAutoFileDataConverter;
|
||||
private readonly Mock<IImsAutoFileNoteConverter> mockImsAutoFileNoteConverter;
|
||||
private readonly Mock<IAutoImsDownloaderService> mockDownloader;
|
||||
private readonly RepoApiConfiguration testConfig;
|
||||
private readonly Mock<IAutoImsImporterService> mockAutoImsImporterService;
|
||||
private readonly Mock<IEmailer> mockEmailer;
|
||||
|
||||
public AutoImsServiceTest()
|
||||
{
|
||||
mockImsAutoFileDataConverter = new Mock<IImsAutoFileDataConverter>();
|
||||
mockImsAutoFileNoteConverter = new Mock<IImsAutoFileNoteConverter>();
|
||||
mockDownloader = new Mock<IAutoImsDownloaderService>();
|
||||
testConfig = new RepoApiConfiguration()
|
||||
{
|
||||
CheckForLocalFiles = true,
|
||||
DownloadNewFiles = true,
|
||||
MoveProcessedFiles = false,
|
||||
LocalDirectoryPath = ".\\SampleData",
|
||||
RemoteFilePath = "."
|
||||
};
|
||||
mockAutoImsImporterService = new Mock<IAutoImsImporterService>();
|
||||
mockEmailer = new Mock<IEmailer>();
|
||||
|
||||
_autoImsProcessor = new AutoImsService(mockDownloader.Object,
|
||||
testConfig, mockAutoImsImporterService.Object, mockImsAutoFileDataConverter.Object,
|
||||
mockImsAutoFileNoteConverter.Object, mockEmailer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_Download_Exception()
|
||||
{
|
||||
mockDownloader.Setup(down => down.DownLoadAuctionFiles()).Throws(new Exception("oops"));
|
||||
mockDownloader.Setup(down => down.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo,string>>())).Returns(new Dictionary<FileInfo, string>() { { new FileInfo("filename"), "test1" } });
|
||||
|
||||
var res = _autoImsProcessor.Download();
|
||||
Assert.NotNull(res);
|
||||
Assert.Empty(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Download_Test()
|
||||
{
|
||||
mockDownloader.Setup(service => service.DownLoadAuctionFiles())
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.ConvertToFileList(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Returns(
|
||||
new List<FileInfo>());
|
||||
Assert.True(testConfig.DownloadNewFiles);
|
||||
Assert.True(testConfig.CheckForLocalFiles);
|
||||
var files = _autoImsProcessor.Download();
|
||||
mockDownloader.VerifyAll();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessDownloadedFiles_Ok()
|
||||
{
|
||||
var fileInfos = new List<FileInfo>() { new FileInfo("Test1"), new FileInfo("Test2") };
|
||||
|
||||
_autoImsProcessor.ProcessDownloadedFiles(fileInfos);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessDownloadedFiles_Exception()
|
||||
{
|
||||
List<FileInfo> fileInfos = null;
|
||||
|
||||
Assert.Throws<Exception>(() => _autoImsProcessor.ProcessDownloadedFiles(fileInfos));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_autoImsProcessor);
|
||||
Assert.Throws<Exception>(() => { _autoImsProcessor.ProcessDownloadedFiles(null); });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_Files_Test()
|
||||
{
|
||||
testConfig.DownloadNewFiles = false;
|
||||
testConfig.CheckForLocalFiles = false;
|
||||
mockDownloader.Setup(service => service.DownLoadAuctionFiles())
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.ConvertToFileList(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Returns(
|
||||
new List<FileInfo>());
|
||||
Assert.False(testConfig.DownloadNewFiles);
|
||||
Assert.False(testConfig.CheckForLocalFiles);
|
||||
var files = _autoImsProcessor.Download();
|
||||
mockDownloader.Verify(foo => foo.DownLoadAuctionFiles(), Times.Never());
|
||||
mockDownloader.Verify(foo => foo.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()),
|
||||
Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user