예제 #1
0
        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);

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

            await DeckHelper.AddCardAsync(db, deck, otherLanguageCard.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);

            Assert.IsTrue(cards.Cards.Single(card => card.CardId == frenchCreatedCard.Id).IsInFrench);
            Assert.IsFalse(cards.Cards.Single(card => card.CardId == otherLanguageCard.Id).IsInFrench);
        }
예제 #2
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);
        }
예제 #3
0
        public async Task CheckOrder()
        {
            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 = 100;

            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);
            var cards   = (await new GetCardsToRepeat(dbContext.AsCallContext(), loadTime).RunAsync(request)).Cards.ToImmutableArray();

            Assert.AreEqual(cardCount, cards.Length);
            for (int i = 1; i < cards.Length; i++)
            {
                Assert.IsTrue(cards[i].Heap <= cards[i - 1].Heap);
                if (cards[i].Heap == cards[i - 1].Heap)
                {
                    Assert.IsTrue(cards[i].LastLearnUtcTime >= cards[i - 1].LastLearnUtcTime);
                }
            }
        }
예제 #4
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());
        }
예제 #5
0
        public async Task DeckDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            using var dbContext = new MemCheckDbContext(db);
            var request = new GetCardsToRepeat.Request(user, Guid.NewGuid(), Array.Empty <Guid>(), Array.Empty <Guid>(), 10);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetCardsToRepeat(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #6
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);
            var request = new GetCardsToRepeat.Request(Guid.Empty, deck, Array.Empty <Guid>(), Array.Empty <Guid>(), 10);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetCardsToRepeat(dbContext.AsCallContext()).RunAsync(request));
        }
예제 #7
0
        public async Task EmptyDeck()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

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

            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(), new DateTime(2000, 1, 2)).RunAsync(request);

            Assert.IsFalse(cards.Cards.Any());
        }
예제 #8
0
        public async Task MultipleImagesOnAdditionalSide()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var language = await CardLanguagHelper.CreateAsync(db);

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

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

            Guid cardGuid;
            var  createRequest = new CreateCard.Request(
                user,
                RandomHelper.String(),
                Array.Empty <Guid>(),
                RandomHelper.String(),
                Array.Empty <Guid>(),
                RandomHelper.String(),
                new Guid[] { image1, image2 },
                language,
                Array.Empty <Guid>(),
                Array.Empty <Guid>(),
                RandomHelper.String());

            using (var dbContext = new MemCheckDbContext(db))
                cardGuid = (await new CreateCard(dbContext.AsCallContext()).RunAsync(createRequest)).CardId;

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

            var addToDeckDate = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, cardGuid, 1, addToDeckDate);

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

                var images = card.Images;
                Assert.AreEqual(2, images.Count());

                var first = card.Images.First();
                Assert.AreEqual(ImageInCard.AdditionalInfo, first.CardSide);
                Assert.AreEqual(image1, first.ImageId);

                var last = card.Images.Last();
                Assert.AreEqual(ImageInCard.AdditionalInfo, last.CardSide);
                Assert.AreEqual(image2, last.ImageId);
            }
        }
예제 #9
0
        public async Task OneCardNonExpired()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

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

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

            var addDate = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, card.Id, 4, lastLearnUtcTime : 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(4)).RunAsync(request);

            Assert.IsFalse(cards.Cards.Any());
        }
예제 #10
0
        public async Task OneCardExpired()
        {
            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 addDate = RandomHelper.Date();
            await DeckHelper.AddCardAsync(db, deck, card.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);

            Assert.AreEqual(card.Id, cards.Cards.Single().CardId);
        }