Ejemplo n.º 1
0
        public void GetByIdAsyncTest_ThrowsDataException()
        {
            // Arrange
            var loggerMock = new Mock <ILogger <CourseRepository> >();
            var repository = new CourseRepository(_contextFactory, loggerMock.Object);

            // Act
            _contextFactory.SimulateSqlException = true;
            async Task TestAction() => await repository.DeleteAsync(new Course { Id = 1 });

            // Assert
            Assert.ThrowsAsync <DataException>(TestAction);
        }
Ejemplo n.º 2
0
        // DELETE api/coursedata/5
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                await CheckCourseCanModifyByUser(id);

                await _courseRepository.DeleteAsync(id);

                return(Ok());
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(InternalServerError());
            }
        }