diff --git a/Kaizen.Test/Controllers/CertificatesControllerTest.cs b/Kaizen.Test/Controllers/CertificatesControllerTest.cs new file mode 100644 index 00000000..81df3d5a --- /dev/null +++ b/Kaizen.Test/Controllers/CertificatesControllerTest.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using Kaizen.Controllers; +using Kaizen.Domain.Entities; +using Kaizen.Domain.Repositories; +using Kaizen.Models.Certificate; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Moq; +using NUnit.Framework; + +namespace Kaizen.Test.Controllers +{ + public class CertificatesControllerTest : BaseControllerTest + { + private CertificatesController _certificatesController; + private Mock _certificatesRepository; + + [SetUp] + public void SetUp() + { + _certificatesRepository = new Mock(); + + _certificatesController = + new CertificatesController(_certificatesRepository.Object, ServiceProvider.GetService()); + + SetUpCertificatesRepository(); + } + + private void SetUpCertificatesRepository() + { + _certificatesRepository.Setup(r => r.GetClientCertificates("1007870922")).ReturnsAsync( + new List + { + new() + { + Id = 1, + Validity = DateTime.Now.AddDays(10), + WorkOrderCode = 1 + }, + new() + { + Id = 2, + Validity = DateTime.Now.AddDays(15), + WorkOrderCode = 2 + } + }); + + _certificatesRepository.Setup(r => r.FindByIdAsync(1)).ReturnsAsync(new Certificate + { + Id = 1, + Validity = DateTime.Now.AddDays(10), + WorkOrderCode = 1 + }); + _certificatesRepository.Setup(r => r.FindByIdAsync(3)).ReturnsAsync((Certificate) null); + } + + [Test] + public async Task Get_Client_Certificates() + { + var result = (await _certificatesController.GetClientCertificates("1007870922")).Result as OkObjectResult; + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Value); + Assert.IsInstanceOf>(result.Value); + + var value = result.Value as IEnumerable; + Assert.IsNotNull(value); + Assert.AreEqual(2, value.Count()); + } + + [Test] + public async Task Get_Existing_Certificate() + { + var result = await _certificatesController.GetCertificate(1); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Value); + Assert.AreEqual(1, result.Value.Id); + } + + [Test] + public async Task Get_Non_Existent_Certificate() + { + var result = await _certificatesController.GetCertificate(3); + + Assert.IsNotNull(result); + Assert.IsNull(result.Value); + + Assert.IsInstanceOf(result.Result); + } + } +} diff --git a/Kaizen.Test/Controllers/ServicesControllerTest.cs b/Kaizen.Test/Controllers/ServicesControllerTest.cs index 2cdfbced..2e904446 100644 --- a/Kaizen.Test/Controllers/ServicesControllerTest.cs +++ b/Kaizen.Test/Controllers/ServicesControllerTest.cs @@ -78,6 +78,7 @@ private void SetUpServicesRepository() _servicesRepository.Setup(r => r.Update(It.IsAny())).Verifiable(); _servicesRepository.Setup(r => r.Insert(It.IsAny())).Verifiable(); + _servicesRepository.Setup(r => r.Insert(It.IsAny())).Verifiable(); } private void SetUpUnitWork() @@ -199,5 +200,18 @@ public async Task Save_Existing_Service() Assert.IsNull(result.Value); Assert.IsInstanceOf(result.Result); } + + [Test] + public async Task Save_New_ServiceType() + { + var result = await _servicesController.ServiceTypes(new ServiceTypeInputModel + { + Name = "Control de plagas" + }); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Value); + Assert.AreEqual("Control de plagas", result.Value.Name); + } } }