예제 #1
0
        public async Task OneCardWithImages()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var image1 = await ImageHelper.CreateAsync(db, user);

            var image2 = await ImageHelper.CreateAsync(db, user);

            var createdCard = await CardHelper.CreateAsync(db, user, frontSideImages : new[] { image1, image2 });

            var addDate = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, createdCard.Id, 1, addDate);

            using var dbContext = new MemCheckDbContext(db);
            var request      = new GetCardsToRepeat.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), 10);
            var cards        = await new GetCardsToRepeat(dbContext.AsCallContext(), addDate.AddDays(1)).RunAsync(request);
            var resultImages = cards.Cards.Single().Images;

            Assert.AreEqual(2, resultImages.Count());
            Assert.AreEqual(image1, resultImages.First().ImageId);
            Assert.AreEqual(image2, resultImages.Last().ImageId);
        }
        public async Task UnknownCardsLearnt_CheckOrder()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : DeveloperHeapingAlgorithm.ID);

            const int cardCount = 100;

            for (int i = 0; i < cardCount; i++)
            {
                var card = await CardHelper.CreateAsync(db, user);

                await DeckHelper.AddCardAsync(db, deck, card.Id, 0);
            }
            using var dbContext = new MemCheckDbContext(db);
            var request = new GetUnknownCardsToLearn.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount);
            var cards   = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.ToImmutableArray();

            Assert.AreEqual(cardCount, cards.Length);
            for (int i = 1; i < cards.Length; i++)
            {
                Assert.IsTrue(cards[i].LastLearnUtcTime >= cards[i - 1].LastLearnUtcTime);
            }
        }
예제 #3
0
        public async Task OneDeck()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : HeapingAlgorithms.DefaultAlgoId);

            var tag1 = await TagHelper.CreateAsync(db);

            var tag2 = await TagHelper.CreateAsync(db);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user, tagIds: tag1.AsArray())).Id, 0);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user)).Id, 0);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user)).Id, 1);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user, tagIds: new[] { tag1, tag2 })).Id, 1);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user)).Id, 2);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user)).Id, 4);

            await DeckHelper.AddCardAsync(db, deck, (await CardHelper.CreateAsync(db, user)).Id, 4);

            using var dbContext = new MemCheckDbContext(db);
            var result     = await new GetUserDecksWithHeapsAndTags(dbContext.AsCallContext()).RunAsync(new GetUserDecksWithHeapsAndTags.Request(user));
            var resultDeck = result.Single();

            Assert.AreEqual(deck, resultDeck.DeckId);
            Assert.IsTrue(resultDeck.Heaps.SequenceEqual(new[] { 0, 1, 2, 4 }));
            Assert.AreEqual(2, resultDeck.Tags.Count());
            Assert.IsTrue(resultDeck.Tags.Any(tag => tag.TagId == tag1));
            Assert.IsTrue(resultDeck.Tags.Any(tag => tag.TagId == tag2));
        }
        public async Task ComplexCaseWithLessCardsThanRequested()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : DeveloperHeapingAlgorithm.ID);

            const int cardCount = 10;

            for (int i = 0; i < cardCount / 2; i++)
            {
                await DeckHelper.AddNeverLearntCardAsync(db, deck, await CardHelper.CreateIdAsync(db, user));

                await DeckHelper.AddCardAsync(db, deck, await CardHelper.CreateIdAsync(db, user), 0);
            }
            using var dbContext = new MemCheckDbContext(db);
            var request = new GetUnknownCardsToLearn.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount * 2);
            var cards   = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.ToImmutableArray();

            Assert.AreEqual(cardCount, cards.Length);
            for (int i = 1; i < cardCount / 2; i++)
            {
                Assert.AreEqual(CardInDeck.NeverLearntLastLearnTime, cards[i].LastLearnUtcTime);
            }
            for (int i = cardCount / 2; i < cards.Length; i++)
            {
                Assert.IsTrue(cards[i].LastLearnUtcTime >= cards[i - 1].LastLearnUtcTime);
            }
        }
예제 #5
0
        public async Task TwoDecks()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck1Name = RandomHelper.String();
            var deck1Algo = RandomHelper.HeapingAlgorithm();
            var deck1     = await DeckHelper.CreateAsync(db, user, deck1Name, deck1Algo);

            var deck2Name = RandomHelper.String();
            var deck2Algo = RandomHelper.HeapingAlgorithm();
            var deck2     = await DeckHelper.CreateAsync(db, user, deck2Name, deck2Algo);

            using var dbContext = new MemCheckDbContext(db);
            var result = await new GetUserDecks(dbContext.AsCallContext()).RunAsync(new GetUserDecks.Request(user));

            Assert.AreEqual(2, result.Count());
            var resultDeck1 = result.Single(d => d.DeckId == deck1);

            Assert.AreEqual(deck1Name, resultDeck1.Description);
            Assert.AreEqual(deck1Algo, resultDeck1.HeapingAlgorithmId);
            var resultDeck2 = result.Single(d => d.DeckId == deck2);

            Assert.AreEqual(deck2Name, resultDeck2.Description);
            Assert.AreEqual(deck2Algo, resultDeck2.HeapingAlgorithmId);
        }
예제 #6
0
        public async Task MoveToZeroTwice()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var card = await CardHelper.CreateAsync(db, user);

            var addTime = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, card.Id, heap : 8, lastLearnUtcTime : addTime);

            using (var dbContext = new MemCheckDbContext(db))
                await new MoveCardsToHeap(dbContext.AsCallContext()).RunAsync(new MoveCardsToHeap.Request(user, deck, CardInDeck.UnknownHeap, card.Id.AsArray()));

            for (int i = 0; i < 2; i++)
            {
                using (var dbContext = new MemCheckDbContext(db))
                {
                    var loadedCard = dbContext.CardsInDecks.Single();
                    Assert.AreEqual(CardInDeck.UnknownHeap, loadedCard.CurrentHeap);
                    Assert.AreEqual(addTime, loadedCard.LastLearnUtcTime);
                    Assert.AreEqual(DateTime.MinValue, loadedCard.ExpiryUtcTime);
                    Assert.AreEqual(2, loadedCard.NbTimesInNotLearnedHeap);
                    Assert.AreEqual(8, loadedCard.BiggestHeapReached);
                }
            }
        }
예제 #7
0
        public async Task ReduceVisibility_OnlyUserWithView_NoOtherUserHasInDeck_OnlyAuthor()
        {
            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>());

            var deck = await DeckHelper.CreateAsync(db, cardCreator);

            await DeckHelper.AddCardAsync(db, deck, card.Id, 0);

            var otherUser = await UserHelper.CreateInDbAsync(db);

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

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForVisibilityChange(card, cardCreator.AsArray());
                await new UpdateCard(dbContext.AsCallContext()).RunAsync(r);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, cardCreator, card.Id);
                Assert.ThrowsException <InvalidOperationException>(() => CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, otherUser, card.Id));
            }
        }
예제 #8
0
        public async Task Complex()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var tag1 = await TagHelper.CreateAsync(db);

            var card1 = await CardHelper.CreateAsync(db, user, tagIds : tag1.AsArray());

            await DeckHelper.AddCardAsync(db, deck, card1.Id);

            var tag2 = await TagHelper.CreateAsync(db);

            var card2 = await CardHelper.CreateAsync(db, user, tagIds : tag2.AsArray());

            await DeckHelper.AddCardAsync(db, deck, card2.Id);

            var card3 = await CardHelper.CreateAsync(db, user, tagIds : new[] { tag1, tag2 });

            await DeckHelper.AddCardAsync(db, deck, card3.Id);

            var card4 = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card4.Id);

            using var dbContext = new MemCheckDbContext(db);
            var request = new GetTagsOfDeck.Request(user, deck);
            var result  = await new GetTagsOfDeck(dbContext).RunAsync(request);

            Assert.AreEqual(2, result.Count());
            Assert.IsTrue(result.Any(t => t.TagId == tag1));
            Assert.IsTrue(result.Any(t => t.TagId == tag2));
        }
예제 #9
0
        public async Task TestSearchExcludingDeck()
        {
            var testDB = DbHelper.GetEmptyTestDB();
            var userId = await UserHelper.CreateInDbAsync(testDB);

            var deckId = await DeckHelper.CreateAsync(testDB, userId);

            using (var dbContext = new MemCheckDbContext(testDB))
            {
                var request = new SubscribeToSearch.Request(userId, deckId, RandomHelper.String(), "", Array.Empty <Guid>(), Array.Empty <Guid>());
                await new SubscribeToSearch(dbContext.AsCallContext()).RunAsync(request);
            }

            using (var dbContext = new MemCheckDbContext(testDB))
            {
                var subscription = await dbContext.SearchSubscriptions
                                   .Include(subscription => subscription.ExcludedTags)
                                   .Include(subscription => subscription.RequiredTags)
                                   .SingleAsync();

                Assert.AreEqual(userId, subscription.UserId);
                Assert.AreEqual(deckId, subscription.ExcludedDeck);
                Assert.AreEqual("", subscription.RequiredText);
                Assert.AreEqual(0, subscription.RequiredTags.Count());
                Assert.IsFalse(subscription.ExcludeAllTags);
                Assert.AreEqual(0, subscription.ExcludedTags !.Count());
            }
        }
예제 #10
0
        public async Task LearnMoveToUnknown()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var card = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card.Id, heap : 4);

            var runTime = RandomHelper.Date();

            using (var dbContext = new MemCheckDbContext(db))
                await new MoveCardToHeap(dbContext.AsCallContext(), runTime).RunAsync(new MoveCardToHeap.Request(user, deck, card.Id, CardInDeck.UnknownHeap));

            using (var dbContext = new MemCheckDbContext(db))
            {
                var cardInDeck = dbContext.CardsInDecks.Single();
                Assert.AreEqual(CardInDeck.UnknownHeap, cardInDeck.CurrentHeap);
                Assert.AreEqual(runTime, cardInDeck.LastLearnUtcTime);
                Assert.AreEqual(2, cardInDeck.NbTimesInNotLearnedHeap);
                Assert.AreEqual(4, cardInDeck.BiggestHeapReached);
                Assert.AreEqual(DateTime.MinValue, cardInDeck.ExpiryUtcTime);
            }
        }
        public async Task CardsNeverLearnt_NotTheSameOrderOnSuccessiveRuns()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : DefaultHeapingAlgorithm.ID);

            const int cardCount = 100;

            for (int i = 0; i < cardCount; i++)
            {
                var card = await CardHelper.CreateAsync(db, user);

                await DeckHelper.AddNeverLearntCardAsync(db, deck, card.Id);
            }
            using var dbContext = new MemCheckDbContext(db);
            var request       = new GetUnknownCardsToLearn.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount);
            var firstRunCards = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.Select(c => c.CardId).ToImmutableArray();

            Assert.AreEqual(cardCount, firstRunCards.Length);
            var secondRunCards = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.Select(c => c.CardId).ToImmutableArray();

            Assert.AreEqual(cardCount, secondRunCards.Length);
            var thirdRunCards = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.Select(c => c.CardId).ToImmutableArray();

            Assert.AreEqual(cardCount, thirdRunCards.Length);
            Assert.IsFalse(firstRunCards.SequenceEqual(secondRunCards));
            Assert.IsFalse(firstRunCards.SequenceEqual(thirdRunCards));
            Assert.IsFalse(secondRunCards.SequenceEqual(thirdRunCards));
        }
예제 #12
0
        public async Task LearnMoveToSameHeap()
        {
            //This could happen due to multiple sessions by the user

            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var card = await CardHelper.CreateAsync(db, user);

            var initialTime = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, card.Id, heap : 1, lastLearnUtcTime : initialTime);

            using (var dbContext = new MemCheckDbContext(db))
                await new MoveCardToHeap(dbContext.AsCallContext(), RandomHelper.Date(initialTime)).RunAsync(new MoveCardToHeap.Request(user, deck, card.Id, 1));

            using (var dbContext = new MemCheckDbContext(db))
            {
                var cardInDeck = dbContext.CardsInDecks.Single();
                Assert.AreEqual(1, cardInDeck.CurrentHeap);
                Assert.AreEqual(initialTime, cardInDeck.LastLearnUtcTime);
                Assert.AreEqual(1, cardInDeck.NbTimesInNotLearnedHeap);
                Assert.AreEqual(1, cardInDeck.BiggestHeapReached);
                Assert.AreEqual(initialTime.AddDays(1), cardInDeck.ExpiryUtcTime);
            }
        }
        public async Task TwoCardsWithLanguages()
        {
            var db     = DbHelper.GetEmptyTestDB();
            var french = await CardLanguagHelper.CreateAsync(db, "Français");

            var otherLanguage = await CardLanguagHelper.CreateAsync(db, RandomHelper.String());

            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var frenchCreatedCard = await CardHelper.CreateAsync(db, user, language : french);

            var otherLanguageCard = await CardHelper.CreateAsync(db, user, language : otherLanguage);

            await DeckHelper.AddNeverLearntCardAsync(db, deck, frenchCreatedCard.Id);

            await DeckHelper.AddNeverLearntCardAsync(db, deck, otherLanguageCard.Id);

            using var dbContext = new MemCheckDbContext(db);
            var request = new GetUnknownCardsToLearn.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), 10);
            var cards   = await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request);

            Assert.IsTrue(cards.Cards.Single(card => card.CardId == frenchCreatedCard.Id).IsInFrench);
            Assert.IsFalse(cards.Cards.Single(card => card.CardId == otherLanguageCard.Id).IsInFrench);
        }
        public async Task OrderingOfNeverLearnt()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : DefaultHeapingAlgorithm.ID);

            var randomDate     = RandomHelper.Date();
            var cardAddedLater = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddNeverLearntCardAsync(db, deck, cardAddedLater.Id, randomDate.AddDays(1));

            for (int i = 0; i < 9; i++)
            {
                var card = await CardHelper.CreateAsync(db, user);

                await DeckHelper.AddNeverLearntCardAsync(db, deck, card.Id, randomDate);
            }

            using var dbContext = new MemCheckDbContext(db);
            var request         = new GetUnknownCardsToLearn.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), 3);
            var downloadedCards = (await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request)).Cards.Select(c => c.CardId).ToImmutableHashSet();

            Assert.IsFalse(downloadedCards.Contains(cardAddedLater.Id));
        }
예제 #15
0
        public async Task DoesNotDeleteOtherUserDeck()
        {
            var db         = DbHelper.GetEmptyTestDB();
            var loggedUser = await UserHelper.CreateInDbAsync(db);

            var deckNotToDelete = await DeckHelper.CreateAsync(db, loggedUser);

            var userToDelete = await UserHelper.CreateInDbAsync(db);

            var deckToDelete = await DeckHelper.CreateAsync(db, userToDelete);

            var card = await CardHelper.CreateAsync(db, userToDelete);

            await DeckHelper.AddCardAsync(db, deckToDelete, card.Id);

            await DeckHelper.AddCardAsync(db, deckNotToDelete, card.Id);

            using (var dbContext = new MemCheckDbContext(db))
            {
                using var userManager = UserHelper.GetUserManager(dbContext);
                await new DeleteUserAccount(dbContext.AsCallContext(new TestRoleChecker(loggedUser)), userManager).RunAsync(new DeleteUserAccount.Request(loggedUser, userToDelete));
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                Assert.IsFalse(await dbContext.Decks.AnyAsync(deck => deck.Id == deckToDelete));
                Assert.IsFalse(await dbContext.CardsInDecks.AnyAsync(cardInDeck => cardInDeck.Deck.Id == deckToDelete));

                Assert.IsTrue(await dbContext.Decks.AnyAsync(deck => deck.Id == deckNotToDelete));
                Assert.IsTrue(await dbContext.CardsInDecks.AnyAsync(cardInDeck => cardInDeck.Deck.Id == deckNotToDelete));
            }
        }
예제 #16
0
        public async Task Complex()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var card1 = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card1.Id);

            var card2 = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card2.Id);

            var card3 = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card3.Id);

            using (var dbContext = new MemCheckDbContext(db))
                await new RemoveCardFromDeck(dbContext.AsCallContext()).RunAsync(new RemoveCardFromDeck.Request(user, deck, card2.Id));

            await DeckHelper.CheckDeckDoesNotContainCard(db, deck, card2.Id);

            await DeckHelper.CheckDeckContainsCards(db, deck, card1.Id, card3.Id);
        }
예제 #17
0
        public async Task LearnMoveUp()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : UnitTestsHeapingAlgorithm.ID);

            var card = await CardHelper.CreateAsync(db, user);

            await DeckHelper.AddCardAsync(db, deck, card.Id, heap : 1);

            var runTime = RandomHelper.Date();

            using (var dbContext = new MemCheckDbContext(db))
                await new MoveCardToHeap(dbContext.AsCallContext(), runTime).RunAsync(new MoveCardToHeap.Request(user, deck, card.Id, 2));

            using (var dbContext = new MemCheckDbContext(db))
            {
                var cardInDeck = dbContext.CardsInDecks.Single();
                Assert.AreEqual(2, cardInDeck.CurrentHeap);
                Assert.AreEqual(runTime, cardInDeck.LastLearnUtcTime);
                Assert.AreEqual(1, cardInDeck.NbTimesInNotLearnedHeap);
                Assert.AreEqual(2, cardInDeck.BiggestHeapReached);
                Assert.AreEqual(runTime.AddDays(2), cardInDeck.ExpiryUtcTime);
            }
        }
예제 #18
0
        public async Task MoveToSameHeap()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            var card = await CardHelper.CreateAsync(db, user);

            var lastLearnTime = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, card.Id, heap : 1, lastLearnUtcTime : lastLearnTime);

            using (var dbContext = new MemCheckDbContext(db))
                await new MoveCardsToHeap(dbContext.AsCallContext()).RunAsync(new MoveCardsToHeap.Request(user, deck, 1, card.Id.AsArray()));

            using (var dbContext = new MemCheckDbContext(db))
            {
                var cardInDeck = dbContext.CardsInDecks.Single();
                Assert.AreEqual(1, cardInDeck.CurrentHeap);
                Assert.AreEqual(lastLearnTime, cardInDeck.LastLearnUtcTime);
                Assert.AreEqual(lastLearnTime.AddDays(1), cardInDeck.ExpiryUtcTime);
                Assert.AreEqual(1, cardInDeck.NbTimesInNotLearnedHeap);
                Assert.AreEqual(1, cardInDeck.BiggestHeapReached);
            }
        }
예제 #19
0
        public async Task RequestedCount()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user, algorithmId : DeveloperHeapingAlgorithm.ID);

            var       loadTime  = RandomHelper.Date();
            const int cardCount = 50;

            for (int i = 0; i < cardCount; i++)
            {
                var card = await CardHelper.CreateAsync(db, user);

                await DeckHelper.AddCardAsync(db, deck, card.Id, RandomHelper.Heap(true), RandomHelper.DateBefore(loadTime));
            }
            using var dbContext = new MemCheckDbContext(db);
            var request = new GetCardsToRepeat.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount / 2);
            var cards   = await new GetCardsToRepeat(dbContext.AsCallContext(), loadTime).RunAsync(request);

            Assert.AreEqual(request.CardsToDownload, cards.Cards.Count());

            request = new GetCardsToRepeat.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount);
            cards   = await new GetCardsToRepeat(dbContext.AsCallContext(), loadTime).RunAsync(request);
            Assert.AreEqual(request.CardsToDownload, cards.Cards.Count());

            request = new GetCardsToRepeat.Request(user, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), cardCount * 2);
            cards   = await new GetCardsToRepeat(dbContext.AsCallContext(), loadTime).RunAsync(request);
            Assert.AreEqual(cardCount, cards.Cards.Count());
        }
예제 #20
0
        public async Task DoesNotThrowWhenCardDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            await new RemoveCardsFromDeck(dbContext.AsCallContext()).RunAsync(new RemoveCardsFromDeck.Request(user, deck, Guid.NewGuid().AsArray()));
        }
예제 #21
0
        public async Task UserNotLoggedIn()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetTagsOfDeck(dbContext).RunAsync(new GetTagsOfDeck.Request(Guid.Empty, deck)));
        }
예제 #22
0
        public async Task CardDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new RemoveCardFromDeck(dbContext.AsCallContext()).RunAsync(new RemoveCardFromDeck.Request(user, deck, Guid.NewGuid())));
        }
예제 #23
0
        public async Task UserDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetUserDecksWithHeapsAndTags(dbContext.AsCallContext()).RunAsync(new GetUserDecksWithHeapsAndTags.Request(Guid.NewGuid())));
        }
        public async Task UserDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new GetRemainingCardsInLesson.Request(Guid.NewGuid(), deck, RandomHelper.Bool(), Array.Empty <Guid>());
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetRemainingCardsInLesson(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #25
0
        public async Task NameTooLong()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateDeck.Request(user, deck, RandomHelper.String(QueryValidationHelper.DeckMaxNameLength + 1), 0);
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateDeck(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #26
0
        public async Task NameNotTrimmed()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateDeck.Request(user, deck, RandomHelper.String() + '\t', 0);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new UpdateDeck(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #27
0
        public async Task InexistentAlgorithm()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateDeck.Request(user, deck, RandomHelper.String(), RandomHelper.ValueNotInSet(HeapingAlgorithms.Instance.Ids));
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new UpdateDeck(dbContext.AsCallContext()).RunAsync(request));
        }
        public async Task UserNotLoggedIn()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new GetUnknownCardsToLearn.Request(Guid.Empty, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), 10);
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new GetUnknownCardsToLearn(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #29
0
        public async Task DeckWithThisNameExists()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var otherDeckName = RandomHelper.String();
            await DeckHelper.CreateAsync(db, user, otherDeckName);

            using var dbContext = new MemCheckDbContext(db);
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new CreateDeck(dbContext.AsCallContext()).RunAsync(new CreateDeck.Request(user, otherDeckName, RandomHelper.HeapingAlgorithm())));
        }
예제 #30
0
        public async Task ReduceVisibility_OtherUserHasInDeck_OtherAuthor()
        {
            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>());

            var userWithCardInDeck = await UserHelper.CreateInDbAsync(db);

            var deck = await DeckHelper.CreateAsync(db, userWithCardInDeck);

            await DeckHelper.AddCardAsync(db, deck, card.Id, 0);

            var otherUser = await UserHelper.CreateInDbAsync(db);

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), otherUser);
                await new UpdateCard(dbContext.AsCallContext()).RunAsync(r);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForVisibilityChange(card, cardCreator.AsArray());
                await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r));
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForVisibilityChange(card, otherUser.AsArray(), otherUser);
                await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r));
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { userWithCardInDeck }, userWithCardInDeck);
                await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r));
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { cardCreator, otherUser, userWithCardInDeck });
                await new UpdateCard(dbContext.AsCallContext()).RunAsync(r);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, cardCreator, card.Id);
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, otherUser, card.Id);
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, userWithCardInDeck, card.Id);
            }
        }