public async Task GivenValidRequest_WhenTheArticleDoesNotExist_ThrowsApiExpceptionForNotFound() { // Arrange var unfavoriteCommand = new UnfavoriteArticleCommand("a-girl-does-not-have-a-name"); // Act var handler = new UnfavoriteArticleCommandHandler(CurrentUserContext, Context, Mapper); var response = await Should.ThrowAsync <ConduitApiException>(async() => { await handler.Handle(unfavoriteCommand, CancellationToken.None); }); // Assert response.ShouldNotBeNull(); response.ShouldBeOfType <ConduitApiException>(); response.StatusCode.ShouldBe(HttpStatusCode.NotFound); }
public async Task GivenValidRequest_WhenTheArticleExistsAndTheUserHasNotFavorited_ReturnsArticleViewModelWithArticleUnfavorited() { // Arrange var unfavoriteCommand = new UnfavoriteArticleCommand("why-beer-is-gods-gift-to-the-world"); var existingFavorite = Context.Favorites.Where(f => f.Article.Slug == "why-beer-is-gods-gift-to-the-world").ToList(); existingFavorite.ShouldNotBeNull(); existingFavorite.ShouldNotContain(f => f.User.UserName == "test.user"); Context.Articles.FirstOrDefault(a => a.Slug == "why-beer-is-gods-gift-to-the-world")?.FavoritesCount.ShouldBe(0); // Act var handler = new UnfavoriteArticleCommandHandler(CurrentUserContext, Context, Mapper); var response = await handler.Handle(unfavoriteCommand, CancellationToken.None); // Assert response.ShouldNotBeNull(); response.ShouldBeOfType <ArticleViewModel>(); response.Article.ShouldNotBeNull(); response.Article.ShouldBeOfType <ArticleDto>(); response.Article.Favorited.ShouldBeFalse(); Context.Articles.FirstOrDefault(a => a.Slug == "why-beer-is-gods-gift-to-the-world")?.FavoritesCount.ShouldBe(0); Context.Articles.FirstOrDefault(a => a.Slug == "why-beer-is-gods-gift-to-the-world")?.Favorites.ShouldNotContain(f => f.User.UserName == "test.user"); }