This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(back-end): Add Certificates controller tests and add new service…
…s controller test See also: #119
- Loading branch information
1 parent
186783a
commit 09f713c
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ICertificatesRepository> _certificatesRepository; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_certificatesRepository = new Mock<ICertificatesRepository>(); | ||
|
||
_certificatesController = | ||
new CertificatesController(_certificatesRepository.Object, ServiceProvider.GetService<IMapper>()); | ||
|
||
SetUpCertificatesRepository(); | ||
} | ||
|
||
private void SetUpCertificatesRepository() | ||
{ | ||
_certificatesRepository.Setup(r => r.GetClientCertificates("1007870922")).ReturnsAsync( | ||
new List<Certificate> | ||
{ | ||
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<IEnumerable<CertificateViewModel>>(result.Value); | ||
|
||
var value = result.Value as IEnumerable<CertificateViewModel>; | ||
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<NotFoundObjectResult>(result.Result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters