public void CreateRole() { unitOfWork.Data = Utils.CreateAdminAndUser(); unitOfWork.Data.Roles = new List <Role> { new Role(), new Role() }; var role = new Role { name = "test", Permissions = new List <Permission> { new Permission { id = 1 }, new Permission { id = 2 } } }; controller.Request.Headers.Authorization = new AuthenticationHeaderValue("jwt", "2"); var result = controller.CreateRole(role); Assert.IsInstanceOfType(result, typeof(UnauthorizedResult)); controller.Request.Headers.Authorization = new AuthenticationHeaderValue("jwt", "1"); result = controller.CreateRole(role); Assert.IsNotInstanceOfType(result, typeof(UnauthorizedResult)); Assert.AreEqual(3, unitOfWork.Data.Roles.Count); CompareObjects(unitOfWork.Data.Roles.Last(), role, new[] { "name" }); var permProp = result.GetType().GetProperty("permissions"); Assert.IsNotNull(permProp); TestCollection(permProp.GetValue(result), 2); var permData = permProp.GetValue(result) as IEnumerable <object>; Assert.IsNotNull(permData.First().GetType().GetProperty("id")); }