public async Task AddNoticeBoardThread_ExceptionOnEmptyThreadContent() { var requestDto = new AddNoticeBoardThreadRequest( "Thread Title", "", 1, "image.png", UserRoles.Administrator, 1 ); var exception = await Assert.ThrowsAsync<InvalidThreadContentException>(() => _sut.AddNoticeBoardThread(requestDto)); Assert.Equal("The thread content cannot be null or empty", exception.Message); }
public async Task AddNoticeBoardThread_ExceptionOnInvalidUserID() { var requestDto = new AddNoticeBoardThreadRequest( "Thread Title", "Thread Content", 1, "image.png", UserRoles.Administrator, -1 ); var exception = await Assert.ThrowsAsync<InvalidUserIdException>(() => _sut.AddNoticeBoardThread(requestDto)); Assert.Equal("UserID is invalid", exception.Message); }
public async Task <AddNoticeBoardThreadResponse> AddNoticeBoardThread(AddNoticeBoardThreadRequest request) { /*var threadId = request.ThreadId;*/ var threadTitle = request.ThreadTitle; var threadContent = request.ThreadContent; var minLevel = request.MinLevel; var imageUrl = request.ImageUrl; var permittedUserRoles = request.PermittedUserRoles; var userId = request.UserId; Models.NoticeBoard.NoticeBoard noticeBoardThread = new Models.NoticeBoard.NoticeBoard(threadTitle, threadContent, minLevel, imageUrl, permittedUserRoles, userId); _noticeBoard.NoticeBoard.Add(noticeBoardThread); await _noticeBoard.SaveChanges(); return(new AddNoticeBoardThreadResponse(HttpStatusCode.Created)); }
public async Task CreateNoticeBoardThread_ExpectedReturnStatus() { var requestDto = new AddNoticeBoardThreadRequest( "Thread Title", "Thread Content", 1, "image.url", UserRoles.Administrator, 1 ); var responseDto = new AddNoticeBoardThreadResponse(HttpStatusCode.Created); _noticeBoardRepoMock.Setup(n => n.AddNoticeBoardThread(requestDto)).ReturnsAsync(responseDto); var createdNoticeBoardThread = await _sut.AddNoticeBoardThread(requestDto); Assert.Equal(responseDto, createdNoticeBoardThread); }
public async Task <AddNoticeBoardThreadResponse> AddNoticeBoardThread(AddNoticeBoardThreadRequest request) { if (request == null) { throw new InvalidNoticeBoardRequestException("Invalid AddNoticeBoardRequest object"); } if (request.ThreadTitle.IsNullOrEmpty()) { throw new InvalidThreadTitleException("The thread title cannot be null or empty"); } if (request.ThreadContent.IsNullOrEmpty()) { throw new InvalidThreadContentException("The thread content cannot be null or empty"); } if (request.UserId <= 0) { throw new InvalidUserIdException("UserID is invalid"); } return(await _noticeBoardRepository.AddNoticeBoardThread(request)); }
public async Task <AddNoticeBoardThreadResponse> AddNoticeBoardThread([FromBody] AddNoticeBoardThreadRequest request) { return(await _service.AddNoticeBoardThread(request)); }