コード例 #1
0
        public async Task CreateCard_ShouldAddNewCard()
        {
            A.CallTo(() => fakeStorage.FindCollection(A <Guid> ._, default(CancellationToken)))
            .Returns(ownedCollection);

            var result = await controller.CreateCard(cardDto, default(CancellationToken));

            result.Should().BeOfType <CreatedAtRouteResult>();
            A.CallTo(() => fakeStorage.AddCard(A <Card> .That.Matches(
                                                   card => card.Term == cardDto.Term &&
                                                   card.Definition == cardDto.Definition &&
                                                   card.OwnerLogin == "admin"), default(CancellationToken)))
            .MustHaveHappened();
        }
コード例 #2
0
        public async Task <ActionResult> CreateCard([FromBody] CardDto cardDto, CancellationToken token)
        {
            var newCard    = new Card(cardDto.Term, cardDto.Definition, User.Identity.Name, cardDto.CollectionId);
            var collection = await storage.FindCollection(cardDto.CollectionId, token);

            if (collection == null)
            {
                return(UnprocessableEntity("collection does not exist"));
            }
            if (!User.OwnsResource(collection))
            {
                return(Forbid());
            }

            await storage.AddCard(newCard, token);

            return(CreatedAtRoute(
                       "GetCardById", new { id = newCard.Id }, newCard.Id));
        }