public async Task <IActionResult> PutCustomActivityInfo(int id, CustomActivityInfo customActivityInfo)
        {
            if (id != customActivityInfo.CustomActivityInfoId)
            {
                return(BadRequest());
            }

            string userEmail = ((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.Email).FirstOrDefault().Value;
            var    user      = await _userManager.FindByEmailAsync(userEmail);

            if (user == null)
            {
                return(Unauthorized());
            }

            var activity = await _context.Activities.FirstAsync(a => a.CustomActivityInfoId == customActivityInfo.CustomActivityInfoId);

            if (activity == null)
            {
                return(NotFound());
            }

            var project = await _context.Projects.FindAsync(activity.ProjectId);

            if (project == null)
            {
                return(NotFound());
            }

            // Check if user got W or RW permissions for the project the activity belongs to
            var userproject = _context.UserProjects.Where(p => p.ProjectId == project.ProjectId &&
                                                          p.UserId == user.Id && (p.Rights == UserProjectPermissions.READWRITE || p.Rights == UserProjectPermissions.WRITE)).FirstOrDefault();

            if (userproject == null)
            {
                return(Forbid());
            }

            _context.Entry(customActivityInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(customActivityInfo));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomActivityInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
        private async Task <CustomActivityInfo> PutActivityAsync(CustomActivityInfo activity, HttpStatusCode expectedHttpStatus)
        {
            var response = await _httpClient.PutAsync("api/CustomActivityInfos/" + activity.CustomActivityInfoId,
                                                      new StringContent(JsonSerializer.Serialize(activity), Encoding.UTF8, MediaTypeNames.Application.Json));

            Assert.AreEqual(expectedHttpStatus, response.StatusCode);
            if (expectedHttpStatus == HttpStatusCode.OK)
            {
                var putResponseBody = await response.Content.ReadAsStringAsync();

                var updated_activity = JsonSerializer.Deserialize <CustomActivityInfo>(putResponseBody);
                return(updated_activity);
            }
            return(null);
        }
        private async Task <CustomActivityInfo> CreateActivity(String name, HttpStatusCode expectedHttpStatus)
        {
            // Get a theme
            var themes = await GetThemesAsync(HttpStatusCode.OK);

            Assert.IsNotNull(themes);
            Assert.IsTrue(themes.Count > 0);
            var theme = themes[0];
            // Create a new base activity
            var activity = new CustomActivityInfo
            {
                Name        = "TestCustomActivityInfo " + name,
                Description = "Activity for UnitTest CustomActivityInfosControllerTest",
                Phase       = ActivityPhase.DEVELOPMENT,
                Theme       = theme,
                ThemeId     = theme.ThemeId
            };

            var response = await _httpClient.PostAsync("api/CustomActivityInfos/",
                                                       new StringContent(JsonSerializer.Serialize(activity), Encoding.UTF8, MediaTypeNames.Application.Json));

            Assert.AreEqual(expectedHttpStatus, response.StatusCode);
            if (expectedHttpStatus == HttpStatusCode.Created)
            {
                // Get created theme from body
                var postResponseBody = await response.Content.ReadAsStringAsync();

                var new_activity = JsonSerializer.Deserialize <CustomActivityInfo>(postResponseBody);
                // Check the result
                Assert.IsNotNull(new_activity);
                Assert.AreEqual(activity.Name, new_activity.Name);
                Assert.AreEqual(activity.Description, new_activity.Description);
                // return the new activity
                return(new_activity);
            }
            return(null);
        }
        public async Task AA_ShouldBeAbleToCreateActivities()
        {
            // Autherized users should be able to create a custom activity
            // Autherize
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(JwtBearerDefaults.AuthenticationScheme, authUser1);
            var newActivity1 = await CreateActivity("Custom1", HttpStatusCode.OK);

            Assert.IsNotNull(newActivity1);

            var newActivity2 = await CreateActivity("Custom2", HttpStatusCode.OK);

            Assert.IsNotNull(newActivity1);

            // Autherize
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(JwtBearerDefaults.AuthenticationScheme, authUser2);

            var newActivity3 = await CreateActivity("Custom3", HttpStatusCode.OK);

            Assert.IsNotNull(newActivity3);

            _newActivity1 = newActivity1;
            _newActivity2 = newActivity2;
            _newActivity3 = newActivity3;
        }
        private async void DelActivityAsync(CustomActivityInfo activity, HttpStatusCode expectedHttpStatus)
        {
            var response = await _httpClient.DeleteAsync("api/CustomActivityInfos/" + activity.CustomActivityInfoId);

            Assert.AreEqual(expectedHttpStatus, response.StatusCode);
        }