public async Task UpdateGroupDoesntUpdateWithNonExistentId() { await this.SeedData(); var input = new EditGroupInputModel { Description = "test", Name = "test", Image = null, Id = 2, }; await this.groupsService.UpdateAsync(input, "test"); var result = this.groupsService.GetById <FakeGroupModel>(1); Assert.Null(result.Description); }
public async Task <IActionResult> Edit(EditGroupInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var profileId = this.profilesService.GetId(userId); var hasAdminPermissions = this.groupsService.HasAdminPermissions(input.Id, profileId); if (hasAdminPermissions) { await this.groupsService.UpdateAsync(input, $"{this.webHost.WebRootPath}/img/groups"); } return(this.RedirectToAction(nameof(this.List))); }
public async Task UpdateGroupWorksCorrectly() { await this.SeedData(); var input = new EditGroupInputModel { Description = "test", Name = "test", Image = null, Id = 1, }; await this.groupsService.UpdateAsync(input, "test"); var result = this.groupsService.GetById <FakeGroupModel>(1); Assert.Equal("test", result.Description); }
public async Task UpdateAsync(EditGroupInputModel input, string path) { var group = this.groupsRepository.All().Where(x => x.Id == input.Id).FirstOrDefault(); if (group != null) { group.Name = input.Name; group.Description = input.Description; if (input.Image?.Length > 0) { group.ImageId = await this.imagesService.CreateAsync(input.Image, path); } this.groupsRepository.Update(group); await this.groupsRepository.SaveChangesAsync(); } }
public async Task UpdateGroupWorksCorrectlyWithImage() { var imageMock = new Mock <IFormFile>(); imageMock.Setup(x => x.Length).Returns(1); await this.SeedData(); var input = new EditGroupInputModel { Description = "test", Name = "test", Image = imageMock.Object, Id = 1, }; await this.groupsService.UpdateAsync(input, "test"); var result = this.groupsService.GetById <FakeGroupModel>(1); Assert.Equal("test", result.Description); }