Files
2026-03-31 14:32:23 -05:00

74 lines
2.3 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using AutoMapper;
using Moq;
using LCU.Api.Internal.CoreApiWrapper.Mappers;
using LCU.Api.Internal.CoreApiWrapper.Services;
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Branches;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
namespace LCU.Api.Internal.CoreApiWrapperTest.Service
{
public class BranchServiceTest
{
private readonly BranchService _branchService;
private readonly IMapper _mapper;
private readonly Mock<IBranchDao> _mockBranchDao;
public BranchServiceTest()
{
if (_mapper == null)
{
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new BranchMapper());
});
IMapper mapper = mappingConfig.CreateMapper();
_mapper = mapper;
}
_mockBranchDao = new Mock<IBranchDao>();
_branchService = new BranchService(_mapper, _mockBranchDao.Object);
}
[Test]
public async Task GetBranches_Returns_FilledOutBranches()
{
var testBranch = new List<Branch>()
{
new Branch()
{
BranchNumber = 1,
BranchName = "Test Branch One"
},
new Branch()
{
BranchNumber = 2,
BranchName = "Test Branch Two"
}
};
_mockBranchDao.Setup(x => x.FindBranches(It.IsAny<CoreRequestParameters>())).ReturnsAsync(testBranch);
var result = await _branchService.GetBranches();
Assert.NotNull(result);
Assert.AreEqual(2, result.Count());
Assert.AreEqual(1, result.FirstOrDefault().BranchId);
Assert.AreEqual("Test Branch One", result.FirstOrDefault().BranchName);
}
[Test]
public void GetBranches_Exception()
{
_mockBranchDao.Setup(x => x.FindBranches(It.IsAny<CoreRequestParameters>())).Throws(new Exception());
Assert.ThrowsAsync<Exception>(() => _branchService.GetBranches());
}
}
}