public void PatchNewCollegue_WhenCollegueNonTrouveExceptionIsThrownByCollegueService_ShouldReturnNotFoundResult() { // Arrange var collegueService = Mock.Of <ICollegueService>(); using var collegueController = new CollegueController(collegueService); var collegueDto = GetAValidColleguePatchDto(); collegueDto.Matricule = null; Mock.Get(collegueService) .Setup(c => c.ModifierCollegue(It.IsAny <ColleguePatchDto>())) .Throws(new CollegueNonTrouveException()); // Act var result = collegueController.PatchColleagueAsync("matricule", collegueDto); // Assert result.Should() .BeOfType <NotFoundResult>(); }
public void PostNewCollegue_WithAValidColleagueDto_ShouldReturnOkResult() { // Arrange var collegueService = Mock.Of <ICollegueService>(); using var collegueController = new CollegueController(collegueService); var collegueDto = GetAValidColleguePostDto(); var collegue = GetAValidCollegue(); Mock.Get(collegueService) .Setup(c => c.AjouterUnCollegue(collegueDto)) .Returns(Task.FromResult(collegue)); // Act var result = collegueController.PostNewCollegue(collegueDto); // Assert result.Should() .BeOfType <OkObjectResult>(); }
public void PostNewCollegue_WithAColleagueDtoWithAnInvalidNameOfOneCharacter_ShouldReturnBadRequestResult() { // Arrange var collegueService = Mock.Of <ICollegueService>(); using var collegueController = new CollegueController(collegueService); var collegueDto = GetAValidColleguePostDto(); collegueDto.Nom = "o"; var collegue = GetAValidCollegue(); Mock.Get(collegueService) .Setup(c => c.AjouterUnCollegue(collegueDto)) .Returns(Task.FromResult(collegue)); // Act var result = collegueController.PostNewCollegue(collegueDto); // Assert result.Should() .BeOfType <BadRequestResult>(); }