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 Equipments controller tests
- Loading branch information
1 parent
65fa5be
commit 2287ec6
Showing
1 changed file
with
131 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,131 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Kaizen.Controllers; | ||
using Kaizen.Domain.Entities; | ||
using Kaizen.Domain.Repositories; | ||
using Kaizen.Models.Equipment; | ||
using Kaizen.Test.Helpers; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Kaizen.Test.Controllers | ||
{ | ||
[TestFixture] | ||
public class EquipmentsControllerTest : BaseControllerTest | ||
{ | ||
private EquipmentsController _equipmentsController; | ||
private Mock<IEquipmentsRepository> _equipmentsRepository; | ||
private Mock<IUnitWork> _unitWork; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_equipmentsRepository = new Mock<IEquipmentsRepository>(); | ||
_unitWork = new Mock<IUnitWork>(); | ||
|
||
_equipmentsController = new EquipmentsController(_equipmentsRepository.Object, _unitWork.Object, | ||
ServiceProvider.GetService<IMapper>()); | ||
} | ||
|
||
[Test] | ||
public async Task GetEquipments() | ||
{ | ||
_equipmentsRepository.Setup(r => r.GetAll()).Returns(new TestAsyncEnumerable<Equipment>(new List<Equipment> | ||
{ | ||
new() | ||
{ | ||
Code = "EER2", | ||
Name = "Rociador" | ||
}, | ||
new() | ||
{ | ||
Code = "FFR3", | ||
Name = "Tijeras" | ||
} | ||
})); | ||
|
||
OkObjectResult result = (await _equipmentsController.GetEquipments()).Result as OkObjectResult; | ||
|
||
Assert.NotNull(result); | ||
Assert.NotNull(result.Value); | ||
} | ||
|
||
[Test] | ||
public async Task GetEquipment() | ||
{ | ||
_equipmentsRepository.Setup(r => r.FindByIdAsync("EER2")).ReturnsAsync(new Equipment | ||
{ | ||
Code = "EER2", | ||
Name = "Rociador" | ||
}); | ||
|
||
ActionResult<EquipmentViewModel> result = await _equipmentsController.GetEquipment("EER2"); | ||
|
||
Assert.NotNull(result); | ||
Assert.NotNull(result.Value); | ||
} | ||
|
||
[Test] | ||
public async Task CheckExists() | ||
{ | ||
_equipmentsRepository.Setup(r => r.GetAll()).Returns(new TestAsyncEnumerable<Equipment>(new List<Equipment> | ||
{ | ||
new() | ||
{ | ||
Code = "EER2", | ||
Name = "Rociador" | ||
}, | ||
new() | ||
{ | ||
Code = "FFR3", | ||
Name = "Tijeras" | ||
} | ||
})); | ||
|
||
bool result = await _equipmentsController.CheckExists("EER2"); | ||
|
||
Assert.NotNull(result); | ||
Assert.IsTrue(result); | ||
} | ||
|
||
[Test] | ||
public async Task PutEquipment() | ||
{ | ||
_equipmentsRepository.Setup(r => r.FindByIdAsync("EER2")).ReturnsAsync(new Equipment | ||
{ | ||
Code = "EER2", | ||
Name = "Rociador" | ||
}); | ||
_equipmentsRepository.Setup(r => r.Update(It.IsAny<Equipment>())).Verifiable(); | ||
_unitWork.Setup(r => r.SaveAsync()).Returns(Task.CompletedTask); | ||
|
||
ActionResult<EquipmentViewModel> result = await _equipmentsController.PutEquipment("EER2", new EquipmentEditModel | ||
{ | ||
Name = "Rociador de pesticida" | ||
}); | ||
|
||
Assert.NotNull(result); | ||
Assert.NotNull(result.Value); | ||
Assert.AreEqual("Rociador de pesticida", result.Value.Name); | ||
} | ||
|
||
[Test] | ||
public async Task PostEquipment() | ||
{ | ||
_equipmentsRepository.Setup(r => r.Insert(It.IsAny<Equipment>())).Verifiable(); | ||
_unitWork.Setup(r => r.SaveAsync()).Returns(Task.CompletedTask); | ||
|
||
var result = await _equipmentsController.PostEquipment(new EquipmentInputModel() | ||
{ | ||
Code = "EERT5", | ||
Name = "Rociador" | ||
}); | ||
|
||
Assert.NotNull(result); | ||
Assert.NotNull(result.Value); | ||
} | ||
} | ||
} |
2287ec6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#119