public void TestAddRolepermission_ShouldNotAddRolePermissionWithoutMandatoryFields() { var controller = new RolePermissionController(); var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("Authorization", "Bearer " + _accessToken); // Don't forget these lines, if you do then the request will be null. controllerContext.Request = request; controller.ControllerContext = controllerContext; var item = AddRolePermission3(); controller.Configuration = new HttpConfiguration(); controller.Validate(item); var negResult = controller.AddRolePermission(item) as NegotiatedContentResult <string>; Assert.IsNotNull(negResult); Assert.AreEqual(HttpStatusCode.BadRequest, negResult.StatusCode); }
public void TestAddRolepermission_ShouldAddRolePermissionWithCorrectParameters() { var controller = new RolePermissionController(); var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("Authorization", "Bearer " + _accessToken); // Don't forget these lines, if you do then the request will be null. controllerContext.Request = request; controller.ControllerContext = controllerContext; var item = AddRolePermission1(); controller.Configuration = new HttpConfiguration(); controller.Validate(item); var negResult = controller.AddRolePermission(item) as NegotiatedContentResult <string>; Assert.IsNotNull(negResult); Assert.AreEqual("RolePermission has been created successfully.", negResult.Content); Assert.AreNotEqual("RolePermission is already exist.", negResult.Content); Assert.AreEqual(HttpStatusCode.OK, negResult.StatusCode); }