public void PostTraining_ValidModelReturnOkResult() { var item = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.Add(item)).ReturnsAsync(true); var controller = new TrainingController(mock.Object); var result = controller.PostTraining(item); Assert.NotNull(result); var response = Assert.IsType <OkObjectResult>(result.Result); Assert.Equal(200, response.StatusCode); }
public void PutTrainingPostTraining() { var controller = new TrainingController(); Training training = new Training { TrainingName = "Test Training", StartDate = System.DateTime.Now, EndDate = System.DateTime.Now }; // Act IHttpActionResult actionResult = controller.PostTraining(training); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <Training>; // Assert Assert.IsNotNull(createdResult); Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.IsNotNull(createdResult.RouteValues["id"]); }
public void PostTraining_InValidModelBadRequestError() { var item = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.Add(item)).ReturnsAsync(true); var controller = new TrainingController(mock.Object); controller.ModelState.AddModelError("name", "name is required"); var result = controller.PostTraining(item); Assert.NotNull(result); var response = Assert.IsType <BadRequestObjectResult>(result.Result); Assert.Equal(400, response.StatusCode); }