public void Get_GetByIdIfPublicationNotFound_NotFound404() { // Arrange var getPublication = new Mock <IGetablePublication>(); var mapper = new Mock <IMapper>(); var adminPublicationController = new AdminPublicationController( getPublication.Object, mapper.Object); getPublication.Setup(gp => gp.GetById(_publication.Id)) .Throws(new ObjectNotFoundException("Publication not found.")); // Act var result = adminPublicationController.Get(_publication.Id); // Assert Assert.IsType <NotFoundObjectResult>(result.Result); }
public void Get_GetPublicationsIfIndexInvalid_BadRequest400() { // Arrange var getPublication = new Mock <IGetablePublication>(); var mapper = new Mock <IMapper>(); var adminPublicationController = new AdminPublicationController( getPublication.Object, mapper.Object); var invalidIndex = -1; getPublication.Setup(gp => gp.GetByPagination(invalidIndex)) .Throws(new InvalidOperationException("Invalid index.")); // Act var result = adminPublicationController.Get(invalidIndex); // Assert Assert.IsType <BadRequestObjectResult>(result.Result); }
public void Get_GetPublicationsIfPublicationsNoMore_NotFound404() { // Arrange var getPublication = new Mock <IGetablePublication>(); var mapper = new Mock <IMapper>(); var adminPublicationController = new AdminPublicationController( getPublication.Object, mapper.Object); var validIndex = 0; getPublication.Setup(gp => gp.GetByPagination(validIndex)) .Throws(new ObjectNotFoundException("No more publications.")); // Act var result = adminPublicationController.Get(validIndex); // Assert Assert.IsType <NotFoundObjectResult>(result.Result); }
public void Get_GetPublicationById_OkObjectResult() { // Arrange var getablePublication = new Mock <IGetablePublication>(); var mapper = new Mock <IMapper>(); getablePublication.Setup(gp => gp.GetById(_publicationEntities.ElementAt(0).Id)) .Returns(_publicationEntities.ElementAt(0)); mapper.Setup(m => m.Map <PublicationDTO>(_publicationEntities.ElementAt(0))) .Returns(_publicationsDTO.ElementAt(0)); var adminPublicationController = new AdminPublicationController( getablePublication.Object, mapper.Object); // Act var result = adminPublicationController.Get(_publicationEntities.ElementAt(0).Id); // Assert Assert.NotNull(adminPublicationController); Assert.NotNull(result); Assert.IsType <OkObjectResult>(result.Result); }
public void Get_GetAllPublications_OkObjectResult() { // Arrange var getablePublication = new Mock <IGetablePublication>(); var mapper = new Mock <IMapper>(); getablePublication.Setup(gp => gp.GetAll()) .Returns(_publicationEntities); mapper.Setup(p => p.Map <IEnumerable <PublicationDTO> >(_publicationEntities)) .Returns(_publicationsDTO); var adminPublicationController = new AdminPublicationController( getablePublication.Object, mapper.Object); // Act var results = adminPublicationController.Get(); // Assert Assert.NotNull(adminPublicationController); Assert.NotNull(results); Assert.IsType <OkObjectResult>(results.Result); }