Ejemplo n.º 1
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>();
        }
        public async Task CRUD_Succeeds()
        {
            var languageCode = "sv";
            var name         = "dummy";

            var creationResult =
                (await ArticleCollectionsController.Create(new ArticleCollectionCreate
            {
                Name = name,
                LanguageCode = languageCode,
                Public = true,
            }))
                .ShouldBeOfType <CreatedAtActionResult>();
            var createdId = creationResult.Value.ShouldBeOfType <ArticleCollectionViewModel>().Id;

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

            var created = await Get(createdId);

            created.Name.ShouldBe(name);
            created.LanguageCode.ShouldBe(languageCode);
            created.Public.ShouldBe(true);

            using (User(2))
            {
                (await ArticleCollectionsController.Update(createdId, new ArticleCollectionUpdate
                {
                    LanguageCode = "en",
                    Name = "another",
                    Public = false,
                })).ShouldBeOfType <NotFoundResult>();
            }

            var updatedName         = "updated";
            var updatedLanguadeCode = "en";
            await ArticleCollectionsController.Update(createdId, new ArticleCollectionUpdate
            {
                LanguageCode = updatedLanguadeCode,
                Name         = updatedName,
                Public       = false,
            });

            var updated = await Get(createdId);

            updated.Name.ShouldBe(updatedName);
            updated.LanguageCode.ShouldBe(updatedLanguadeCode);
            updated.Public.ShouldBe(false);

            (await List("en")).Items.Count.ShouldBe(1);

            // Another user shouldn't be able to see the article collection because it's not public
            using (User(2))
            {
                (await List("en")).Items.Count.ShouldBe(0);
                (await ArticleCollectionsController.Get(createdId, new ArticleCollectionGet {
                })).ShouldBeOfType <NotFoundResult>();
            }

            (await ArticleCollectionsController.Delete(createdId, new ArticleCollectionDelete {
            })).ShouldBeOfType <NoContentResult>();
            (await List("en")).Items.Count.ShouldBe(0);
            (await ArticleCollectionsController.Get(createdId, new ArticleCollectionGet {
            })).ShouldBeOfType <NotFoundResult>();
        }