using System.Collections.Generic; using Xunit; using Moq; using LCU.API.Collections.RepoApi.HostedServices; using LCU.API.Collections.RepoApi.Services; using LCU.API.Collections.RepoApi.Configuration; using LCU.API.Collections.RepoApi.DataAccess; using LCU.Shared.Collections.RepoApiLib.Models.Producer; using LCU.API.Collections.RepoApi.Exceptions; using LCU.Shared.Collections.RepoApiLib.Repositories; using LCU.Shared.Realtime.QueueLib.Models; using LCU.Shared.Realtime.QueueLib.Queue; namespace LCU.API.Collections.RepoApiTests.HostedServices { public class RepoQueueProducerServiceTests { private RepoApiConfiguration _repoApiConfig; private Mock _mockRepoAccountService; private Mock _mockQueueConnectionConfig; private QueueItemProducer _mockQueueItemProducer; private Mock _mockSettingsService; private Mock _mockProcessingReceiptService; private Mock _mockCollectionsDao; private RepoQueueProducerService _repoQueueProducerService; public RepoQueueProducerServiceTests() { _repoApiConfig = new RepoApiConfiguration() { QueueConsumerConfigs = StaticTestConfigs.GetQueueConsumerConfigs() }; _mockRepoAccountService = new Mock(); _mockQueueConnectionConfig = new Mock(); _mockQueueItemProducer = new QueueItemProducer(_mockQueueConnectionConfig.Object); _mockProcessingReceiptService = new Mock(); _mockSettingsService = new Mock(); _mockCollectionsDao = new Mock(); _repoQueueProducerService = new RepoQueueProducerService(_mockQueueConnectionConfig.Object, _mockRepoAccountService.Object, _repoApiConfig, _mockSettingsService.Object, _mockCollectionsDao.Object, _mockProcessingReceiptService.Object); } [Fact] public async void RetrieveRepoAccountsOfInterest_OK() { //setup _mockRepoAccountService.Setup(serv => serv.GetItemsForProcessing()).ReturnsAsync(new List() { new ProcessingItem() { AccountNo = "123456-789" }, new ProcessingItem() { AccountNo = "223456-789" }, new ProcessingItem() { AccountNo = "323456-789" } }); //act var res = await _repoQueueProducerService.RetrieveRepoAccountsOfInterest(); //assert Assert.Equal(3, res.Count); } [Fact] public async void RetrieveRepoAccountsOfInterest_Exception() { //setup _mockRepoAccountService.Setup(serv => serv.GetItemsForProcessing()).ThrowsAsync(new ServerErrorException()); //act var res = await _repoQueueProducerService.RetrieveRepoAccountsOfInterest(); //assert Assert.Equal(0, res.Count); } } }