using LCU.Api.Internal.CoreApiWrapper.Controllers; using LCU.Api.Internal.CoreApiWrapper.Services; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.IndirectLoan; using Microsoft.AspNetCore.Mvc; using Moq; using NUnit.Framework; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace LCU.Api.Internal.CoreApiWrapperTest.Controllers { public class IndirectLoanControllerTest { private IndirectLoanController _indirectLoanController; private Mock _mockIndirectLoanService; [SetUp] public void SetUp() { _mockIndirectLoanService = new Mock(); _indirectLoanController = new IndirectLoanController(_mockIndirectLoanService.Object); } [Test] public async Task GetIndirectLoanByAccountNumber_OK() { _mockIndirectLoanService.Setup(x => x.GetIndirectLoanByAccountNumber(It.IsAny())).ReturnsAsync(new IndirectLoanDetail()); var result = await _indirectLoanController.GetIndirectLoanByAccountNumber(1234); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task GetIndirectLoanByAccountNumber_Exception() { _mockIndirectLoanService.Setup(x => x.GetIndirectLoanByAccountNumber(It.IsAny())) .Throws(new Exception("Oops")); var result = await _indirectLoanController.GetIndirectLoanByAccountNumber(1234); Assert.NotNull(result); var badResult = result as StatusCodeResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task GetIndirectLoanByPostedDate_OK() { _mockIndirectLoanService.Setup(x => x.GetIndirectLoansByPostedDate(It.IsAny())).ReturnsAsync(new List()); var result = await _indirectLoanController.GetIndirectLoansByPostedDate("5/1/2021"); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task GetIndirectLoanByPostedDate_Exception() { _mockIndirectLoanService.Setup(x => x.GetIndirectLoansByPostedDate(It.IsAny())) .Throws(new Exception("Oops")); var result = await _indirectLoanController.GetIndirectLoansByPostedDate("5/1/2021"); Assert.NotNull(result); var badResult = result as StatusCodeResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task GetClosedIndirectLoanByPostedDate_OK() { _mockIndirectLoanService.Setup(x => x.GetClosedIndirectLoansByPostedDate(It.IsAny())).ReturnsAsync(new List()); var result = await _indirectLoanController.GetClosedIndirectLoansByPostedDate("5/1/2021"); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task GetClosedIndirectLoanByPostedDate_Exception() { _mockIndirectLoanService.Setup(x => x.GetClosedIndirectLoansByPostedDate(It.IsAny())) .Throws(new Exception("Oops")); var result = await _indirectLoanController.GetClosedIndirectLoansByPostedDate("5/1/2021"); Assert.NotNull(result); var badResult = result as StatusCodeResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task GetClosedIndirectLoanWithDetailByPostedDate_OK() { _mockIndirectLoanService.Setup(x => x.GetClosedIndirectLoansWithDetailByPostedDate(It.IsAny())).ReturnsAsync(new List()); var result = await _indirectLoanController.GetClosedIndirectLoansWithDetailByPostedDate("5/1/2021"); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task GetClosedIndirectLoanWithDetailByPostedDate_Exception() { _mockIndirectLoanService.Setup(x => x.GetClosedIndirectLoansWithDetailByPostedDate(It.IsAny())) .Throws(new Exception("Oops")); var result = await _indirectLoanController.GetClosedIndirectLoansWithDetailByPostedDate("5/1/2021"); Assert.NotNull(result); var badResult = result as StatusCodeResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task PutDealerOriginalBalance_Ok() { var accountNumber = "111111111111"; _mockIndirectLoanService.Setup(x => x.UpdateDealerOriginalBalance(It.IsAny())).ReturnsAsync( new List() { }); var result = await _indirectLoanController.PutDealerOriginalBalance(accountNumber); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task PutDealerOriginalBalance_Exception() { var accountNumber = "111111111111"; _mockIndirectLoanService.Setup(x => x.UpdateDealerOriginalBalance(It.IsAny())) .Throws(new Exception("Oops")); var results = await _indirectLoanController.PutDealerOriginalBalance(accountNumber); Assert.NotNull(results); var badResult = results as StatusCodeResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } } }