Beispiel #1
0
        public async Task <IActionResult> CreateLesson(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "Lesson/Create")]
            [RequestBodyType(typeof(Lesson), "CreateLesson request")]  HttpRequest req,
            [SwaggerIgnore] ILogger log)
        {
            try
            {
                string reqBody = await new StreamReader(req.Body).ReadToEndAsync();
                var    input   = JsonConvert.DeserializeObject <Lesson>(reqBody);

                var dataToBeInserted = new Lesson
                {
                    LessonCode  = input.LessonCode,
                    Description = input.Description
                };

                var data = await _lessonService.CreateLesson(dataToBeInserted);

                var dataDTO = _mapper.Map <LessonDTO>(data);

                return(new OkObjectResult(dataDTO));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
            public async Task CreateLesson_Created()
            {
                var repo = new Mock<IDocumentDBRepository<Lesson>>();

                var lessons = new Lesson
                {
                    Id = "1",
                    LessonCode = "lCOde",
                    Description = "abcd"
                };

                repo.Setup(c => c.CreateAsync(
                    It.IsAny<Lesson>(),
                    It.IsAny<EventGridOptions>(),
                    It.IsAny<string>(),
                    It.IsAny<string>()
                    )).Returns(Task.FromResult(lessons));

                var svc = new LessonService(repo.Object);

                var act = await svc.CreateLesson(lessons);
                Assert.Equal(lessons, act);

            }