Esempio n. 1
0
        public void Get_Always_CallsRepositoryWithId()
        {
            // arrange
            const int ARTICLE_ID = 123;

            // act
            _articlesController.Get(ARTICLE_ID);

            // assert
            _mockArticleRepository.Verify(r => r.Fetch(It.Is <long>(p => p == ARTICLE_ID)));
        }
Esempio n. 2
0
        public async Task Get_NotFound()
        {
            // Arrange
            _articleRepositoryMock.Setup(m => m.GetAsync(1)).Returns(Task.FromResult <Article>(null));

            // Act
            var result = await _articlesController.Get(1);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as NotFoundResult;

            Assert.NotNull(objectResult);
        }
Esempio n. 3
0
        public async Task Get_NotFound()
        {
            //Arrange
            _context.Articles = null;

            // Act
            var result = await _articlesController.Get(1);

            // Assert
            Assert.NotNull(result);

            var objectResult = result as NotFoundResult;

            Assert.NotNull(objectResult);
        }
        public async Task Get_ReturnsOk()
        {
            //Arrange
            var dummyArticles = new List <Article>();

            _mockArticleService.Setup(service => service.GetAll())
            .Returns(Task.FromResult((IEnumerable <Article>)dummyArticles));

            //Act
            var result = await _articlesController.Get() as OkObjectResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(200, result.StatusCode);
        }
Esempio n. 5
0
        public void GetAll_When16ArticlesInDb_ShouldReturn10Articles()
        {
            Article[] articles = this.GenerateValidTestArticles(16);

            var repo = Mock.Create <IRepository <Article> >();

            Mock.Arrange(() => repo.All())
            .Returns(() => articles.AsQueryable());

            var data = Mock.Create <IArticlesData>();

            Mock.Arrange(() => data.Articles)
            .Returns(() => repo);

            var controller = new ArticlesController(data);

            this.SetupController(controller);

            var actionResult = controller.Get();

            var response = actionResult.ExecuteAsync(CancellationToken.None).Result;

            var actual = response.Content.ReadAsAsync <IEnumerable <ArticleDataModel> >().Result.Select(a => a.ID).ToList();

            var expected = articles.AsQueryable()
                           .OrderByDescending(a => a.DateCreated)
                           .Take(10)
                           .Select(a => a.ID).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public async void GetAllArticler()// System.NotSupportedException
        {
            var result = await controller.GetAll();

            var viewResult = Assert.IsType <ActionResult <List <Article> > >(result);
            var articleV   = Assert.IsType <OkObjectResult>(viewResult.Result);
            var articleRes = Assert.IsAssignableFrom <IEnumerable <Article> >(articleV.Value);

            Assert.Equal(2, articleRes.Count());

            foreach (var article in articleRes)
            {
                var articlePage = await controller.Get(article.Id);

                var articleView  = Assert.IsType <ActionResult <Article> >(articlePage);
                var articleVw    = Assert.IsType <OkObjectResult>(articleView.Result);
                var articleModel = Assert.IsAssignableFrom <Article>(articleVw.Value);

                Assert.NotNull(articleModel);
                Assert.NotNull(articleModel.Text);
            }
        }
Esempio n. 7
0
 private async Task <ArticleViewModel> Get(Guid id)
 {
     return((await ArticlesController.Get(id, new ArticleGet {
     })).ShouldBeOfType <OkObjectResult>()
            .Value.ShouldBeOfType <ArticleViewModel>());
 }
Esempio n. 8
0
        public async Task CRUD_Succeeds()
        {
            var created = await SetupArticle(
                articleCollectionLanguageCode : "sv",
                articleCollectionName : "collection",
                articleCollectionIsPublic : false,
                articleName : "dummy",
                articleText : "Hallå!"
                );

            var articleCollectionId = created.ArticleCollectionId;

            (await List(articleCollectionId)).Items.Count.ShouldBe(1);

            // Article in private article collection should not be accessible by another user.
            using (User(2))
            {
                (await ArticlesController.Get(created.Id, new ArticleGet {
                })).ShouldBeOfType <NotFoundResult>();
            }

            await ArticleCollectionsController.Update(articleCollectionId, new ArticleCollectionUpdate { Public = true });

            // Article in public article collection should be accessible by another user.
            using (User(2))
            {
                (await Get(created.Id)).ShouldSatisfyAllConditions(
                    x => x.Name.ShouldBe(created.Name),
                    x => JsonConvert
                    .SerializeObject(x.ConlluDocument, Formatting.Indented)
                    .ShouldMatchApproved(c => c.WithDiscriminator("CreatedConlluDocument"))
                    );

                (await ArticlesController.Update(created.Id, new ArticleUpdate
                {
                    Name = "another",
                    Text = "another",
                })).ShouldBeOfType <NotFoundResult>();
            }

            var updatedName = "updated";
            var upadtedText =
                @"Hallå värld!

Han är min pappa,
hon är min mamma,
de är mina föräldrar.



Varför vill du lära dig svenska?
Det beror på att det gör det lättare att förstå vad folk säger.
";
            await ArticlesController.Update(created.Id, new ArticleUpdate
            {
                Name = updatedName,
                Text = upadtedText,
            });

            var updated = await Get(created.Id);

            updated.Name.ShouldBe(updatedName);
            JsonConvert.SerializeObject(updated.ConlluDocument, Formatting.Indented)
            .ShouldMatchApproved(c => c.WithDiscriminator("UpdatedConlluDocument"));

            using (User(2))
            {
                (await ArticlesController.Delete(created.Id, new ArticleDelete {
                })).ShouldBeOfType <NotFoundResult>();
            }
            (await List(articleCollectionId)).Items.Count.ShouldBe(1);

            // Listing without specifying article collection ID should return articles from any article collection
            (await List(null)).Items.Count.ShouldBe(1);

            (await ArticlesController.Delete(created.Id, new ArticleDelete {
            })).ShouldBeOfType <NoContentResult>();
            (await List(articleCollectionId)).Items.Count.ShouldBe(0);
            (await ArticlesController.Get(created.Id, new ArticleGet {
            })).ShouldBeOfType <NotFoundResult>();
        }