Exemplo n.º 1
0
        private void TestReportedResult(PracticeDeckViewModel viewModel, PracticeResultKind expectedResult,
                                        ApiConnectorMock mock, long cardId, int fieldId)
        {
            PracticeHistoryEntry entry = mock.Parameters.Pop() as PracticeHistoryEntry;

            Assert.AreEqual(HttpMethod.Post, mock.Methods.Pop());
            Assert.AreEqual(DateTime.Today, entry.PracticeDate);
            Assert.AreEqual(cardId, entry.CardId);
            Assert.AreEqual(fieldId, entry.FieldId);
            Assert.AreEqual(deck.DeckId, entry.DeckId);

            int correct = expectedResult == PracticeResultKind.Easy ? 1 : 0;
            int hard    = expectedResult == PracticeResultKind.Hard ? 1 : 0;
            int wrong   = expectedResult == PracticeResultKind.Wrong ? 1 : 0;

            Assert.AreEqual(correct, entry.CorrectCount);
            Assert.AreEqual(hard, entry.HardCount);
            Assert.AreEqual(wrong, entry.WrongCount);
            Assert.AreEqual(correct, viewModel.PracticeResults[cardId].Correct);
            Assert.AreEqual(hard, viewModel.PracticeResults[cardId].Difficult);
            Assert.AreEqual(wrong, viewModel.PracticeResults[cardId].Wrong);
            Assert.AreEqual(correct, viewModel.PracticeResults[cardId].FieldResults[fieldId].Correct);
            Assert.AreEqual(hard, viewModel.PracticeResults[cardId].FieldResults[fieldId].Difficult);
            Assert.AreEqual(wrong, viewModel.PracticeResults[cardId].FieldResults[fieldId].Wrong);
        }
Exemplo n.º 2
0
        public async Task GetProblemWordsOnInitializeTest()
        {
            Deck deck = new Deck()
            {
                Title = "test", DeckId = 1
            };
            PracticeHistoryEntry entry = new PracticeHistoryEntry()
            {
                DeckId = deck.DeckId
            };
            ApiConnectorMock mock = IntializeApiConnectorMock(new List <Deck>(), new List <PracticeHistoryEntry>()
            {
                entry
            }, deck);
            HomeViewModel viewModel = new HomeViewModel(navigationManagerMock, mock);
            await viewModel.InitializeAsync();

            Assert.AreEqual(1, viewModel.ProblemWords.Count);
            Assert.AreSame(entry, viewModel.ProblemWords[0]);
            Assert.AreEqual(1, viewModel.ProblemWordDecks.Count);
            Assert.AreSame(deck, viewModel.ProblemWordDecks[1]);
            Assert.AreEqual(1, (long)mock.Parameters.Pop());
            Assert.AreEqual(HttpMethod.Get, mock.Methods.Pop());
            Dictionary <string, object> parameters = mock.Parameters.Pop() as Dictionary <string, object>;

            Assert.IsTrue(parameters.ContainsKey(nameof(HomeViewModel.ProblemWords)));
            Assert.AreEqual(HttpMethod.Get, mock.Methods.Pop());
        }
        public async Task LoadsPracticeHistoryEntriesOnIntializeTest()
        {
            Card card = new Card()
            {
                CardId = 1
            };

            card.Fields.Add(new CardField()
            {
                FieldId = 1, FieldName = "Field 1"
            });
            card.Fields.Add(new CardField()
            {
                FieldId = 2, FieldName = "Field 2"
            });
            PracticeHistoryEntry entry1 = new PracticeHistoryEntry()
            {
                Field = new CardField()
                {
                    FieldName = "Field 1"
                }
            };
            PracticeHistoryEntry entry2 = new PracticeHistoryEntry()
            {
                Field = new CardField()
                {
                    FieldName = "Field 2"
                }
            };
            ApiConnectorMock mock = new ApiConnectorMock();

            mock.Replies.Push(new ApiReply <List <PracticeHistoryEntry> >()
            {
                WasSuccessful = true,
                Result        = new List <PracticeHistoryEntry>()
                {
                    entry1, entry2
                }
            });
            mock.Replies.Push(new ApiReply <Card>()
            {
                WasSuccessful = true,
                Result        = card
            });
            CardStatisticsViewModel viewModel = new CardStatisticsViewModel(navigationManagerMock, mock);
            bool result = await viewModel.InitializeAsync();

            Assert.IsTrue(result);
            Assert.AreEqual(HttpMethod.Get, mock.Methods.Pop());
            Dictionary <string, object> parameters = mock.Parameters.Pop() as Dictionary <string, object>;

            Assert.AreEqual((long)1, parameters[nameof(Card.CardId)]);
            Assert.IsTrue(viewModel.PracticeHistoryEntries.Contains(entry1));
            Assert.IsTrue(viewModel.PracticeHistoryEntries.Contains(entry2));
            Assert.AreEqual(EntityNameHelper.GetName <Card>(), viewModel.SelectableDisplayUnits[0]);
            Assert.AreEqual(EntityNameHelper.GetName <Card>(), viewModel.SelectedDisplayUnit);
            Assert.IsTrue(viewModel.SelectableDisplayUnits.Contains("Field 1"));
            Assert.IsTrue(viewModel.SelectableDisplayUnits.Contains("Field 2"));
        }
Exemplo n.º 4
0
        public async Task PracticeDeckCommandEnabledTest()
        {
            Deck deck = new Deck()
            {
                Title = "test", DeckId = 1
            };
            PracticeHistoryEntry entry = new PracticeHistoryEntry()
            {
                DeckId = deck.DeckId
            };
            ApiConnectorMock mock = IntializeApiConnectorMock(new List <Deck>(), new List <PracticeHistoryEntry>()
            {
                entry
            }, deck);
            HomeViewModel viewModel = new HomeViewModel(navigationManagerMock, mock);
            await viewModel.InitializeAsync();

            Assert.IsFalse(viewModel.PracticeDeckCommand.IsEnabledFunction(deck));
            deck.CardCount = 1;
            Assert.IsTrue(viewModel.PracticeDeckCommand.IsEnabledFunction(deck));
        }
        public void SelectsDisplayedEntriesCorrectlyTest()
        {
            PracticeHistoryEntry entry1 = new PracticeHistoryEntry()
            {
                Field = new CardField()
                {
                    FieldName = "Field 1"
                }
            };
            PracticeHistoryEntry entry2 = new PracticeHistoryEntry()
            {
                Field = new CardField()
                {
                    FieldName = "Field 2"
                }
            };
            CardStatisticsViewModel viewModel = new CardStatisticsViewModel(navigationManagerMock, new ApiConnectorMock());

            viewModel.PracticeHistoryEntries.AddRange(new List <PracticeHistoryEntry>()
            {
                entry1, entry2
            });
            viewModel.SelectableDisplayUnits.Add(EntityNameHelper.GetName <Card>());
            viewModel.SelectableDisplayUnits.Add("Field 1");
            viewModel.SelectableDisplayUnits.Add("Field 2");

            viewModel.SelectedDisplayUnit = EntityNameHelper.GetName <Card>();
            Assert.AreEqual(2, viewModel.DisplayedEntries.Count());
            Assert.IsTrue(viewModel.DisplayedEntries.Contains(entry1));
            Assert.IsTrue(viewModel.DisplayedEntries.Contains(entry2));

            viewModel.SelectedDisplayUnit = "Field 1";
            Assert.AreEqual(1, viewModel.DisplayedEntries.Count());
            Assert.IsTrue(viewModel.DisplayedEntries.Contains(entry1));

            viewModel.SelectedDisplayUnit = "Field 2";
            Assert.AreEqual(1, viewModel.DisplayedEntries.Count());
            Assert.IsTrue(viewModel.DisplayedEntries.Contains(entry2));
        }
#pragma warning disable IDE0060 // Remove unused parameter
        public static void ClassInitialize(TestContext context)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            otherUser = new User()
            {
                UserId   = Guid.NewGuid(),
                Email    = "*****@*****.**",
                Password = "******"
            };
            entry1 = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 1,
                PracticeDate           = DateTime.Today,
                PracticeHistoryEntryId = 1,
                UserId                 = User.UserId,
                CorrectCount           = 1,
                HardCount              = 2,
                WrongCount             = 3
            };
            entry2 = new PracticeHistoryEntry()
            {
                CardId                 = 2,
                DeckId                 = 2,
                FieldId                = 1,
                PracticeDate           = DateTime.Today,
                PracticeHistoryEntryId = 2,
                UserId                 = User.UserId
            };
            entry3 = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 3,
                PracticeDate           = DateTime.Today,
                PracticeHistoryEntryId = 3,
                UserId                 = User.UserId,
                CorrectCount           = 2,
                HardCount              = 4,
                WrongCount             = 6
            };
            otherUserEntry = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 2,
                PracticeDate           = DateTime.Today,
                PracticeHistoryEntryId = 4,
                UserId                 = otherUser.UserId
            };
            field1 = new CardField()
            {
                FieldName        = "Field 1",
                CardId           = 1,
                FieldId          = 1,
                ProficiencyLevel = 3
            };
            field2 = new CardField()
            {
                FieldName        = "Field 12",
                CardId           = 1,
                FieldId          = 2,
                ProficiencyLevel = 3
            };
            field3 = new CardField()
            {
                FieldName        = "Field 2",
                CardId           = 1,
                FieldId          = 3,
                ProficiencyLevel = 3
            };
            field4 = new CardField()
            {
                FieldName        = "Field 2",
                CardId           = 2,
                FieldId          = 1,
                ProficiencyLevel = 3
            };
        }
        public async Task PostEntryTest()
        {
            using DbContext context = CreateContext();
            PracticeHistoryEntriesController controller = CreateController(context);

            //null as parameter -> bad request
            ActionResult <PracticeHistoryEntry> result = await controller.PostAsync(null);

            Assert.IsTrue(result.Result is BadRequestResult);

            //Same day -> update existing
            PracticeHistoryEntry newEntry = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 1,
                PracticeDate           = DateTime.Today,
                PracticeHistoryEntryId = 5,
                UserId                 = User.UserId,
                CorrectCount           = 0,
                HardCount              = 0,
                WrongCount             = 1
            };

            result = await controller.PostAsync(newEntry);

            Assert.IsNotNull(result.Value);
            newEntry = context.Find <PracticeHistoryEntry>((long)5);
            Assert.IsNull(newEntry);
            newEntry = context.Find <PracticeHistoryEntry>((long)1);
            Assert.AreEqual(4, newEntry.WrongCount);
            CardField field1 = context.Find <CardField>((long)1, 1);

            Assert.AreEqual(1, field1.ProficiencyLevel);
            Assert.AreEqual(DateTime.Today.AddDays(1).Date, field1.DueDate.Date);

            //other day -> new entry
            newEntry = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 1,
                PracticeDate           = DateTime.Today.AddDays(1),
                PracticeHistoryEntryId = 5,
                UserId                 = User.UserId,
                CorrectCount           = 1,
                HardCount              = 0,
                WrongCount             = 0
            };
            result = await controller.PostAsync(newEntry);

            Assert.IsNotNull(result.Value);
            newEntry = context.Find <PracticeHistoryEntry>((long)5);
            Assert.AreEqual(1, newEntry.CorrectCount);
            field1 = context.Find <CardField>((long)1, 1);
            Assert.AreEqual(2, field1.ProficiencyLevel);
            Assert.AreEqual(DateTime.Today.AddDays(3).Date, field1.DueDate.Date);

            //other day -> new entry
            newEntry = new PracticeHistoryEntry()
            {
                CardId                 = 1,
                DeckId                 = 1,
                FieldId                = 1,
                PracticeDate           = DateTime.Today.AddDays(1),
                PracticeHistoryEntryId = 6,
                UserId                 = User.UserId,
                CorrectCount           = 0,
                HardCount              = 1,
                WrongCount             = 0
            };
            result = await controller.PostAsync(newEntry);

            Assert.IsNotNull(result.Value);
            field1 = context.Find <CardField>((long)1, 1);
            Assert.AreEqual((long)1, field1.ProficiencyLevel);
            Assert.AreEqual(DateTime.Today.AddDays(2).Date, field1.DueDate.Date);
        }