public async Task DeleteArticle_WithSucceedingCommit_ReturnsStatusCodeNoContent()
        {
            _deleteCommandMock.Setup(m => m.Execute(It.IsAny <int>())).Returns(Task.FromResult(true));
            var idOfArticleToDelete = 1;

            // act
            var result = await _articlesController.DeleteArticle(idOfArticleToDelete);

            // assert
            _deleteCommandMock.Verify(m => m.Execute(idOfArticleToDelete), Times.Once);
            Assert.That(result, Is.Not.Null);
            Assert.That(result.GetType(), Is.EqualTo(typeof(OkResult)));
            Assert.That(((OkResult)result).StatusCode, Is.EqualTo(200));
        }
Example #2
0
        public async void DeleteArticleInvalidIdTest()
        {
            var controller = new ArticlesController(_context, _userManager);

            var result = await controller.DeleteArticle(40);

            Assert.IsType <NotFoundResult>(result);

            var result2 = await controller.GetArticle(-1);

            Assert.IsType <BadRequestResult>(result2);
        }
Example #3
0
        public async void DeleteArticleTest()
        {
            var controller = new ArticlesController(_context, _userManager);

            var article = _articleDTOs.First();


            var result = await controller.DeleteArticle(article.Id);

            Assert.IsType <OkResult>(result);

            var result2 = await controller.GetArticle(article.Id);

            Assert.IsType <NotFoundResult>(result2);
        }
Example #4
0
        public void CallDeleteArticleMethod_WhenParamsAreValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var id      = Guid.NewGuid();
            var article = new Article();

            articleServiceMock.Setup(x => x.GetArticleById(id)).Returns(article);
            articleServiceMock.Setup(x => x.DeleteArticle(article));

            // Act
            controller.DeleteArticle(id);

            // Assert
            articleServiceMock.Verify(x => x.DeleteArticle(article), Times.Once);
        }