コード例 #1
0
        public async Task UpdateNothing()
        {
            var db          = DbHelper.GetEmptyTestDB();
            var cardCreator = await UserHelper.CreateInDbAsync(db);

            var languageId = await CardLanguagHelper.CreateAsync(db);

            var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>());

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateCard.Request(
                card.Id,
                card.VersionCreator.Id,
                card.FrontSide,
                card.Images.Where(i => i.CardSide == ImageInCard.FrontSide).Select(i => i.ImageId),
                card.BackSide,
                card.Images.Where(i => i.CardSide == ImageInCard.BackSide).Select(i => i.ImageId),
                card.AdditionalInfo,
                card.Images.Where(i => i.CardSide == ImageInCard.AdditionalInfo).Select(i => i.ImageId),
                card.CardLanguage.Id,
                card.TagsInCards.Select(t => t.TagId),
                card.UsersWithView.Select(uwv => uwv.UserId),
                RandomHelper.String());
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(request));
        }
コード例 #2
0
        public async Task CardDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            using var dbContext = new MemCheckDbContext(db);
            var r = new UpdateCard.Request(Guid.NewGuid(), user, RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), Guid.NewGuid(), Array.Empty <Guid>(), Array.Empty <Guid>(), RandomHelper.String());
            await Assert.ThrowsExceptionAsync <ApplicationException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r));
        }
コード例 #3
0
        public async Task <IActionResult> UpdateCard(Guid cardId, [FromBody] UpdateCardRequest card)
        {
            CheckBodyParameter(card);
            var user = await userManager.GetUserAsync(HttpContext.User);

            var request = new UpdateCard.Request(cardId, user.Id, card.FrontSide, card.FrontSideImageList, card.BackSide, card.BackSideImageList, card.AdditionalInfo, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, card.VersionDescription);

            await new UpdateCard(callContext).RunAsync(request);
            return(ControllerResultWithToast.Success(Get("CardSavedOk"), this));
        }
コード例 #4
0
        public async Task NotFoundAnymoreToReport()
        {
            var db = DbHelper.GetEmptyTestDB();

            var user = await UserHelper.CreateInDbAsync(db);

            var language = await CardLanguagHelper.CreateAsync(db);

            var card1 = await CardHelper.CreateAsync(db, user, versionDate : new DateTime(2050, 03, 01), language : language);

            var card2 = await CardHelper.CreateAsync(db, user, versionDate : new DateTime(2050, 04, 02), language : language);

            var subscription = await SearchSubscriptionHelper.CreateAsync(db, user, requiredText : card1.FrontSide);

            using (var dbContext = new MemCheckDbContext(db))
            {
                var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, new DateTime(2050, 05, 01)).RunAsync(subscription.Id);
                Assert.AreEqual(1, searchResult.TotalNewlyFoundCardCount);
                Assert.AreEqual(1, searchResult.NewlyFoundCards.Length);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserAllowedToView);
                Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Length);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserAllowedToView);
                Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_Deleted_UserAllowedToView.Length);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserNotAllowedToView);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var updateRequest = new UpdateCard.Request(card1.Id, user, RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), language, Array.Empty <Guid>(), Array.Empty <Guid>(), RandomHelper.String());
                await new UpdateCard(dbContext.AsCallContext(), new DateTime(2050, 05, 02)).RunAsync(updateRequest);
            }

            var runDate = new DateTime(2050, 05, 03);

            using (var dbContext = new MemCheckDbContext(db))
            {
                var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, runDate).RunAsync(subscription.Id);

                Assert.AreEqual(0, searchResult.TotalNewlyFoundCardCount);
                Assert.AreEqual(0, searchResult.NewlyFoundCards.Length);
                Assert.AreEqual(1, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserAllowedToView);
                Assert.AreEqual(1, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Length);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserAllowedToView);
                Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_Deleted_UserAllowedToView.Length);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserNotAllowedToView);
                Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView);

                Assert.AreEqual(card1.Id, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Single().CardId);
            }

            using (var dbContext = new MemCheckDbContext(db))
                Assert.AreEqual(runDate, dbContext.SearchSubscriptions.Single(s => s.Id == subscription.Id).LastRunUtcDate);
        }
コード例 #5
0
        public async Task <IActionResult> UpdateCard(Guid cardId, [FromBody] UpdateCardRequest card)
        {
            if (card.FrontSide == null)
            {
                return(ControllerError.BadRequest(localizer["InvalidCardEmptyFrontSide"].Value, this));
            }
            if (card.BackSide == null)
            {
                card.BackSide = "";
            }
            if (card.AdditionalInfo == null)
            {
                card.AdditionalInfo = "";
            }
            if (card.FrontSideImageList == null)
            {
                return(ControllerError.BadRequest("Invalid input: card.FrontSideImageList == null", this));
            }
            if (card.BackSideImageList == null)
            {
                return(ControllerError.BadRequest("Invalid input: card.BackSideImageList == null", this));
            }
            if (card.AdditionalInfoImageList == null)
            {
                return(ControllerError.BadRequest("Invalid input: card.AdditionalInfoImageList == null", this));
            }
            if (card.UsersWithVisibility == null)
            {
                return(ControllerError.BadRequest("Invalid input: card.UsersWithVisibility == null", this));
            }
            if (card.Tags == null)
            {
                return(ControllerError.BadRequest("Invalid input: card.Tags == null", this));
            }
            if (string.IsNullOrWhiteSpace(card.VersionDescription))
            {
                return(ControllerError.BadRequest(localizer["InvalidCardEmptyVersionDescription"].Value, this));
            }

            try
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                var request = new UpdateCard.Request(cardId, user, card.FrontSide, card.FrontSideImageList, card.BackSide, card.BackSideImageList, card.AdditionalInfo, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, card.VersionDescription);
                await new UpdateCard(dbContext).RunAsync(request, localizer);
                return(Ok());
            }
            catch (Exception e)
            {
                return(ControllerError.BadRequest(e, this));
            }
        }
コード例 #6
0
 public static async Task RunAsync(DbContextOptions <MemCheckDbContext> db, UpdateCard.Request request)
 {
     using var dbContext = new MemCheckDbContext(db);
     await new UpdateCard(dbContext.AsCallContext()).RunAsync(request);
 }
コード例 #7
0
        public async Task UpdateAllFields()
        {
            var db          = DbHelper.GetEmptyTestDB();
            var cardCreator = await UserHelper.CreateInDbAsync(db);

            var languageId = await CardLanguagHelper.CreateAsync(db);

            var originalCard = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>());

            var newVersionCreator = await UserHelper.CreateInDbAsync(db);

            var frontSide          = RandomHelper.String();
            var backSide           = RandomHelper.String();
            var additionalInfo     = RandomHelper.String();
            var versionDescription = RandomHelper.String();
            var newLanguageId      = await CardLanguagHelper.CreateAsync(db);

            var imageOnFrontSideId = await ImageHelper.CreateAsync(db, cardCreator);

            var imageOnBackSide1Id = await ImageHelper.CreateAsync(db, cardCreator);

            var imageOnBackSide2Id = await ImageHelper.CreateAsync(db, cardCreator);

            var imageOnAdditionalInfoId = await ImageHelper.CreateAsync(db, cardCreator);

            var tagId = await TagHelper.CreateAsync(db);

            using (var dbContext = new MemCheckDbContext(db))
            {
                var request = new UpdateCard.Request(
                    originalCard.Id,
                    newVersionCreator,
                    frontSide,
                    new Guid[] { imageOnFrontSideId },
                    backSide,
                    new Guid[] { imageOnBackSide1Id, imageOnBackSide2Id },
                    additionalInfo,
                    new Guid[] { imageOnAdditionalInfoId },
                    languageId,
                    new Guid[] { tagId },
                    new Guid[] { cardCreator, newVersionCreator },
                    versionDescription);
                await new UpdateCard(dbContext.AsCallContext()).RunAsync(request);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var updatedCard = dbContext.Cards
                                  .Include(c => c.VersionCreator)
                                  .Include(c => c.CardLanguage)
                                  .Include(c => c.UsersWithView)
                                  .Include(c => c.Images)
                                  .Include(c => c.TagsInCards)
                                  .Single(c => c.Id == originalCard.Id);
                Assert.AreEqual(newVersionCreator, updatedCard.VersionCreator.Id);
                Assert.AreEqual(frontSide, updatedCard.FrontSide);
                Assert.AreEqual(backSide, updatedCard.BackSide);
                Assert.AreEqual(additionalInfo, updatedCard.AdditionalInfo);
                Assert.AreEqual(versionDescription, updatedCard.VersionDescription);
                Assert.AreEqual(languageId, updatedCard.CardLanguage.Id);
                Assert.AreEqual(ImageInCard.FrontSide, updatedCard.Images.Single(i => i.ImageId == imageOnFrontSideId).CardSide);
                Assert.AreEqual(ImageInCard.BackSide, updatedCard.Images.Single(i => i.ImageId == imageOnBackSide1Id).CardSide);
                Assert.AreEqual(ImageInCard.BackSide, updatedCard.Images.Single(i => i.ImageId == imageOnBackSide2Id).CardSide);
                Assert.AreEqual(ImageInCard.AdditionalInfo, updatedCard.Images.Single(i => i.ImageId == imageOnAdditionalInfoId).CardSide);
                Assert.IsTrue(updatedCard.TagsInCards.Any(t => t.TagId == tagId));
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, cardCreator, originalCard.Id);
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, newVersionCreator, originalCard.Id);
            }
        }