public async Task HasPermissionForActivity_BoardUserExists_ReturnOutputOfIBoardUserPermissionService() { var userId = "user-id"; _currentUser.Setup(u => u.UserId).Returns(userId); _boardUserPermissionService.Setup(s => s.HasPermission(It.IsAny <BoardUser>(), It.IsAny <BoardUserPermission>())).Returns(true); var dbName = $"{nameof(CurrentUserPermissionServiceTests)}_{nameof(HasPermissionForActivity_BoardUserExists_ReturnOutputOfIBoardUserPermissionService)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var card = Card.Create("card-title"); var activity = Activity.Create("activity-title"); var boardUser = new BoardUserFactory().CreateOwner(1, userId); board.AddCard(card); card.AddActivity(activity); context.Boards.Add(board); context.BoardUsers.Add(boardUser); await context.SaveChangesAsync(cancellationToken); var service = new CurrentUserPermissionService(context, _currentUser.Object, _boardUserPermissionService.Object); var result = await service.HasPermissionForActivity(activity.Id, BoardUserPermission.CAN_VIEW_ACTIVITY, cancellationToken); Assert.True(result); }
public async Task HasPermissionForActivity_ActivityNotExists_ThrowNotFoundApplicationException() { var dbName = $"{nameof(CurrentUserPermissionServiceTests)}_{nameof(HasPermissionForActivity_ActivityNotExists_ThrowNotFoundApplicationException)}"; var context = TestApplicationDbContext.Create(dbName); var service = new CurrentUserPermissionService(context, _currentUser.Object, _boardUserPermissionService.Object); Task action() => service.HasPermissionForActivity(1, BoardUserPermission.CAN_VIEW_ACTIVITY, new CancellationToken()); await Assert.ThrowsAsync <NotFoundApplicationException>(action); }