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 _mockBranchDao; public BranchServiceTest() { if (_mapper == null) { var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new BranchMapper()); }); IMapper mapper = mappingConfig.CreateMapper(); _mapper = mapper; } _mockBranchDao = new Mock(); _branchService = new BranchService(_mapper, _mockBranchDao.Object); } [Test] public async Task GetBranches_Returns_FilledOutBranches() { var testBranch = new List() { new Branch() { BranchNumber = 1, BranchName = "Test Branch One" }, new Branch() { BranchNumber = 2, BranchName = "Test Branch Two" } }; _mockBranchDao.Setup(x => x.FindBranches(It.IsAny())).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())).Throws(new Exception()); Assert.ThrowsAsync(() => _branchService.GetBranches()); } } }