public async Task <IActionResult> UpdateLesson( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "Lesson/Update/{id}")] [RequestBodyType(typeof(Lesson), "UpdateLesson request")] HttpRequest req, string id, [SwaggerIgnore] ILogger log) { try { string reqBody = await new StreamReader(req.Body).ReadToEndAsync(); var input = JsonConvert.DeserializeObject <Lesson>(reqBody); var dataExisting = await _lessonService.GetLessonById(id, new Dictionary <string, string> { { "LessonCode", input.LessonCode } }); if (dataExisting == null) { return(new NotFoundObjectResult("Data not found !!!!")); } dataExisting.Description = input.Description; var data = await _lessonService.UpdateLesson(id, dataExisting); var dataDTO = _mapper.Map <LessonDTO>(data); return(new OkObjectResult(dataDTO)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } }
public async Task UpdateLesson_ReturnsLessonUpdated() { //Arrange var lesson = AutoFaker.Generate <Lesson>(); _askmeRepository.Setup(x => x.UpdateLesson(It.IsAny <Lesson>())) .ReturnsAsync(true); //Act var result = await _sut.UpdateLesson(lesson); //Assert result.Should().BeTrue(); }
public async Task <ActionResponse> UpdateLesson(Lesson lesson) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var lessonAccess = await _userService.AuthorizeLesson(userId, lesson.Id); if (lessonAccess) { return(await _lessonService.UpdateLesson(lesson)); } else { return(new ActionResponse(false, "Invalid User access")); } }
public async Task UpdateLesson_Updated(string id) { var repo = new Mock<IDocumentDBRepository<Lesson>>(); var lessons = new Lesson { Id = "1", LessonCode = "lcode", Description = "abcd" }; repo.Setup(c => c.UpdateAsync( It.IsAny<string>(), It.IsAny<Lesson>(), It.IsAny<EventGridOptions>(), It.IsAny<string>() )).Returns(Task.FromResult(lessons)); var svc = new LessonService(repo.Object); var act = await svc.UpdateLesson(id, lessons); Assert.Equal(lessons, act); }