コード例 #1
0
ファイル: Delete.cs プロジェクト: n1ghtmare/Kauntr
        public async Task DeleteRequestWithCommentId_DeletesTheComment() {
            const long id = 123;
            const int currentAccountId = 1337;

            var commentRepository = new FakeCommentRepository();
            await commentRepository.CreateAsync(new Comment {Id = id, CreatedById = currentAccountId});

            var mockContextService = new Mock<IContextService>();
            mockContextService
                .Setup(x => x.GetCurrentAccountAsync())
                .Returns(Task.FromResult(new Account {Id = currentAccountId}));

            var commentController = new CommentController(commentRepository, new Mock<IVoteService>().Object, mockContextService.Object);

            await commentController.Delete(id);

            Assert.AreEqual(0, commentRepository.InMemoryComments.Count);
        }
コード例 #2
0
ファイル: Delete.cs プロジェクト: n1ghtmare/Kauntr
        public async Task DeleteRequestWithCommentIdThatDoesntBelongToTheCurrentUser_ThrowsAnHttpExceptionForbidden() {
            const long id = 123;

            var mockContextService = new Mock<IContextService>();
            mockContextService
                .Setup(x => x.GetCurrentAccountAsync())
                .Returns(Task.FromResult(new Account {Id = 1337}));

            var commentRepository = new FakeCommentRepository();
            await commentRepository.CreateAsync(new Comment {Id = id, CreatedById = 1234});

            var commentController = new CommentController(commentRepository, new Mock<IVoteService>().Object, mockContextService.Object);

            var ex = Assert.Throws<HttpException>(async () => await commentController.Delete(id));

            Assert.AreEqual(403, ex.GetHttpCode());
            Assert.AreEqual("Forbidden", ex.Message);
            Assert.AreEqual(1, commentRepository.InMemoryComments.Count);
        }