Beispiel #1
0
        public IHttpActionResult PostLecture(NewLectureDTO lecture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = LectureService.AddLecture(lecture);

            if (!result.Created)
            {
                return(BadRequest("Adding lecture error. Try again."));
            }

            return(CreatedAtRoute("GetLecture", new { id = result.Lecture.LectureId }, result.Lecture));
        }
Beispiel #2
0
        public async Task AddLectureTest(LectureDto lectureDto, Lecture expected)
        {
            // Arrange
            Mock <ICrudRepository <Lecture> > repositoryMock = new();
            var loggerMock = new Mock <ILogger <LectureService> >();
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(mapper => mapper.Map <Lecture>(lectureDto)).Returns(expected);
            var service = new LectureService(repositoryMock.Object, mapperMock.Object, loggerMock.Object);

            // Act
            int id = await service.AddLecture(lectureDto);

            // Assert
            Assert.That(id, Is.EqualTo(expected.Id));
            repositoryMock.Verify(repository => repository.SaveAsync(expected, It.IsAny <CancellationToken>()));
            repositoryMock.VerifyNoOtherCalls();
        }