130 lines
4.3 KiB
C#
130 lines
4.3 KiB
C#
using LCU.Api.Internal.Dispatcher.Services;
|
|
using LCU.Api.Internal.DispatcherLib.Repositories;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
|
|
|
public class CleanUpJobSettingServiceTest
|
|
{
|
|
private readonly CleanUpJobSettingService _cleanUpJobSettingService;
|
|
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
|
private readonly Mock<ICleanUpJobSettingRepository> _mockCleanUpJobSettingRepository;
|
|
|
|
public CleanUpJobSettingServiceTest()
|
|
{
|
|
_mockCleanUpJobSettingRepository = new Mock<ICleanUpJobSettingRepository>();
|
|
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
|
|
|
_cleanUpJobSettingService = new CleanUpJobSettingService(_mockUnitOfWork.Object,
|
|
_mockCleanUpJobSettingRepository.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetAsync_Success()
|
|
{
|
|
// Arrange
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(new List<CleanUpJobSetting>()
|
|
{
|
|
new CleanUpJobSetting(),
|
|
new CleanUpJobSetting(),
|
|
new CleanUpJobSetting()
|
|
});
|
|
|
|
// Act
|
|
var result = await _cleanUpJobSettingService.GetAsync();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(3, result.Count());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetByCleanUpJobSettingIdAsync_Success()
|
|
{
|
|
// Arrange
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(new CleanUpJobSetting());
|
|
|
|
// Act
|
|
var result = await _cleanUpJobSettingService.GetByCleanUpJobSettingIdAsync(100);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetByCleanUpJobSettingIdAsync_Null()
|
|
{
|
|
// Arrange
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync((CleanUpJobSetting)null);
|
|
|
|
// Act
|
|
var result = await _cleanUpJobSettingService.GetByCleanUpJobSettingIdAsync(100);
|
|
|
|
// Assert
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveAsync_Success()
|
|
{
|
|
// Arrange
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.AddAsync(It.IsAny<CleanUpJobSetting>())).ReturnsAsync(new CleanUpJobSetting());
|
|
|
|
// Act
|
|
var result = await _cleanUpJobSettingService.SaveAsync(new CleanUpJobSetting());
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
_mockCleanUpJobSettingRepository.Verify(x => x.AddAsync(It.IsAny<CleanUpJobSetting>()), Times.Once);
|
|
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async void UpdateAsync_Success()
|
|
{
|
|
// Arrange
|
|
var cleanUpJobSettingToUpdate = new CleanUpJobSetting()
|
|
{
|
|
CleanUpJobSettingId = 100,
|
|
CompletionDaysPast = 15
|
|
};
|
|
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(cleanUpJobSettingToUpdate);
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.Update(It.IsAny<CleanUpJobSetting>())).Verifiable();
|
|
|
|
// Act
|
|
var result = await _cleanUpJobSettingService.UpdateAsync(cleanUpJobSettingToUpdate);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(cleanUpJobSettingToUpdate.CleanUpJobSettingId, result.CleanUpJobSettingId);
|
|
Assert.Equal(cleanUpJobSettingToUpdate.CompletionDaysPast, result.CompletionDaysPast);
|
|
_mockCleanUpJobSettingRepository.VerifyAll();
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public async Task DeleteAsync_Success()
|
|
{
|
|
// Arrange
|
|
var cleanUpJobSettingReturned = new CleanUpJobSetting()
|
|
{
|
|
CleanUpJobSettingId = 100,
|
|
CompletionDaysPast = 15
|
|
};
|
|
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(cleanUpJobSettingReturned);
|
|
_mockCleanUpJobSettingRepository.Setup(repo => repo.Remove(It.IsAny<CleanUpJobSetting>())).Verifiable();
|
|
|
|
// Act
|
|
var cleanUpJobSettingIdToDelete = 100;
|
|
await _cleanUpJobSettingService.DeleteAsync(cleanUpJobSettingIdToDelete); ;
|
|
|
|
// Assert
|
|
_mockCleanUpJobSettingRepository.VerifyAll();
|
|
}
|
|
}
|