Exemplo n.º 1
0
        public async Task DoesNotReportResultWhenNotActivePracticeTest()
        {
            Deck deck = new Deck()
            {
                Title = "test", DeckId = 1
            };
            Card card = new Card()
            {
                CardId = 1, DeckId = 1
            };

            deck.Cards.Add(card);
            card.Fields.Add(new CardField()
            {
                FieldId = 1, Value = "test 1", FieldName = "test1", DueDate = DateTime.Today.AddDays(1)
            });
            card.Fields.Add(new CardField()
            {
                FieldId = 2, Value = "test 2", FieldName = "test2", DueDate = DateTime.Today.AddDays(1)
            });
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock)
            {
                IsShowingSolution = true
            };
            await viewModel.InitializeAsync();

            mock.Methods.Clear();
            mock.Parameters.Clear();
            viewModel.EasyResultCommand.ExecuteCommand();

            Assert.AreEqual(0, mock.Methods.Count);
            Assert.AreEqual(0, mock.Parameters.Count);
        }
Exemplo n.º 2
0
        public async Task NextCommandTest()
        {
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock)
            {
                InputText         = "test123",
                IsShowingSolution = true,
                WasInputCorrect   = true
            };
            await viewModel.InitializeAsync();

            CardField previous = viewModel.Current;

            viewModel.NextCommand.ExecuteCommand();

            Assert.IsTrue(string.IsNullOrEmpty(viewModel.InputText));
            Assert.IsNull(viewModel.WasInputCorrect);
            Assert.IsFalse(viewModel.IsShowingSolution);
            Assert.AreNotSame(previous, viewModel.Current);
            Assert.IsFalse(viewModel.IsSummary);

            viewModel.NextCommand.ExecuteCommand();
            viewModel.NextCommand.ExecuteCommand();
            Assert.IsTrue(viewModel.IsSummary);
        }
Exemplo n.º 3
0
        public async Task CommandsAreInitializedCorrectlyTest()
        {
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            await viewModel.InitializeAsync();

            Assert.IsNotNull(viewModel.CloseCommand.ToolTip);

            Assert.IsNotNull(viewModel.CloseSummaryCommand.CommandText);
            Assert.IsNotNull(viewModel.CloseSummaryCommand.ToolTip);
            Assert.AreEqual("/", viewModel.CloseSummaryCommand.TargetUri);

            Assert.IsNotNull(viewModel.EasyResultCommand.CommandText);
            Assert.IsNotNull(viewModel.EasyResultCommand.ToolTip);

            Assert.IsNotNull(viewModel.DifficultResultCommand.CommandText);
            Assert.IsNotNull(viewModel.DifficultResultCommand.ToolTip);

            Assert.IsNotNull(viewModel.DoesNotKnowResultCommand.CommandText);
            Assert.IsNotNull(viewModel.DoesNotKnowResultCommand.ToolTip);

            Assert.IsNotNull(viewModel.ShowSolutionCommand.CommandText);
            Assert.IsNotNull(viewModel.ShowSolutionCommand.ToolTip);

            Assert.IsNotNull(viewModel.NextCommand.CommandText);
            Assert.IsNotNull(viewModel.NextCommand.ToolTip);
        }
Exemplo n.º 4
0
        public async Task LoadDataOnInitializeTest()
        {
            card1.Fields.Add(new CardField()
            {
                DueDate = DateTime.Today, FieldName = "FieldWithoutValue"
            });
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            bool result = await viewModel.InitializeAsync();

            Assert.IsTrue(result);
            Assert.AreSame(deck, viewModel.Entity);
            Assert.AreEqual(3, viewModel.PracticeFields.Count); //Only fields that are due and have a value
            Assert.IsTrue(viewModel.PracticeFields.Contains(field1));
            Assert.IsTrue(viewModel.PracticeFields.Contains(field2));
            Assert.IsTrue(viewModel.PracticeFields.Contains(field3));
            Assert.AreSame(viewModel.PracticeFields[0], viewModel.Current);
            Assert.AreEqual(viewModel.Current.FieldName, viewModel.CurrentFieldName);
            CardField expectedDisplayField = viewModel.Current.Card.Fields
                                             .Single(field => field.Value != null && field != viewModel.Current);

            Assert.AreSame(expectedDisplayField, viewModel.DisplayedCardField);
            Assert.IsFalse(viewModel.IsSummary);
            Assert.IsFalse(viewModel.IsShowingSolution);
        }
Exemplo n.º 5
0
        public async Task InitializeFailsOnErrorWhenLoadingDeckTest()
        {
            ApiConnectorMock      mock      = CreateMockForInitialize(false, null);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            bool result = await viewModel.InitializeAsync();

            Assert.IsFalse(result);
            Assert.AreEqual(NotificationKind.ErrorNotification, notificationProviderMock.NotificationKind);
            Assert.AreEqual("test-error", notificationProviderMock.Message);
        }
Exemplo n.º 6
0
        public async Task TitleTest()
        {
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            bool result = await viewModel.InitializeAsync();

            Assert.IsTrue(result);
            Assert.AreEqual(Messages.PracticePageTitle.FormatWith(deck.Title), viewModel.Title);
            viewModel.IsSummary = true;
            Assert.AreEqual(Messages.PracticePageSummaryTitle, viewModel.Title);
        }
Exemplo n.º 7
0
        private async Task ResultCommandTestCore(PracticeResultKind expectedResult)
        {
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock)
            {
                IsShowingSolution = true
            };
            await viewModel.InitializeAsync();

            mock.Replies.Push(new ApiReply <PracticeHistoryEntry>()
            {
                WasSuccessful = true, Result = new PracticeHistoryEntry()
            });
            long      cardId        = viewModel.Current.CardId;
            int       fieldId       = viewModel.Current.FieldId;
            CardField previousField = viewModel.Current;

            switch (expectedResult)
            {
            case PracticeResultKind.Easy:
                viewModel.EasyResultCommand.ExecuteCommand();
                break;

            case PracticeResultKind.Hard:
                viewModel.DifficultResultCommand.ExecuteCommand();
                break;

            case PracticeResultKind.Wrong:
                viewModel.DoesNotKnowResultCommand.ExecuteCommand();
                break;

            default:
                break;
            }

            TestReportedResult(viewModel, expectedResult, mock, cardId, fieldId);

            Assert.AreEqual(1, viewModel.PracticeResults.Count);
            Assert.AreEqual(1, viewModel.PracticeResults[cardId].FieldResults.Count);
            Assert.IsFalse(viewModel.IsShowingSolution);
            if (expectedResult == PracticeResultKind.Wrong)
            {
                Assert.AreEqual(4, viewModel.PracticeFields.Count);
            }
            else
            {
                Assert.AreEqual(3, viewModel.PracticeFields.Count);
                //Because field is added again when wrong or don't know could be same field again
                Assert.AreNotSame(previousField, viewModel.Current);
            }
            Assert.IsNotNull(viewModel.Current);
            Assert.IsFalse(viewModel.IsSummary);
        }
Exemplo n.º 8
0
        public async Task UseAllFieldsWhenNoFieldIsDueTest()
        {
            card1.Fields.Add(new CardField()
            {
                DueDate = DateTime.Today, FieldName = "FieldWithoutValue"
            });
            field1.DueDate = field2.DueDate = field3.DueDate = field4.DueDate = DateTime.Today.AddDays(-1);
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            bool result = await viewModel.InitializeAsync();

            Assert.IsTrue(result);
            Assert.AreSame(deck, viewModel.Entity);
            Assert.AreEqual(4, viewModel.PracticeFields.Count); //All fields that have a value
            Assert.IsTrue(viewModel.PracticeFields.Contains(field1));
            Assert.IsTrue(viewModel.PracticeFields.Contains(field3));
            Assert.AreSame(viewModel.PracticeFields[0], viewModel.Current);
        }
Exemplo n.º 9
0
        private async Task ShowSolutionCommandTestCore(bool useInput, bool expectedResult)
        {
            if (useInput)
            {
                fieldDefinition1.ShowInputForPractice = fieldDefinition2.ShowInputForPractice = true;
            }
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            await viewModel.InitializeAsync();

            viewModel.InputText = expectedResult ? viewModel.Current.Value : null;
            viewModel.ShowSolutionCommand.ExecuteCommand();

            if (useInput)
            {
                Assert.AreEqual(expectedResult, viewModel.WasInputCorrect);
            }
            Assert.IsTrue(viewModel.IsShowingSolution);
        }
Exemplo n.º 10
0
        private async Task OnInputFinishedTestCore(bool expectedResult)
        {
            fieldDefinition1.ShowInputForPractice = fieldDefinition2.ShowInputForPractice = true;
            ApiConnectorMock      mock      = CreateMockForInitialize(true, deck);
            PracticeDeckViewModel viewModel = new PracticeDeckViewModel(navigationManagerMock, mock);
            await viewModel.InitializeAsync();

            mock.Replies.Push(new ApiReply <PracticeHistoryEntry>()
            {
                WasSuccessful = true
            });
            long cardId  = viewModel.Current.CardId;
            int  fieldId = viewModel.Current.FieldId;

            viewModel.InputText = expectedResult ? viewModel.Current.Value : null;
            viewModel.OnInputFinished();

            Assert.AreEqual(expectedResult, viewModel.WasInputCorrect);
            Assert.IsTrue(viewModel.IsShowingSolution);
            TestReportedResult(viewModel, expectedResult ? PracticeResultKind.Easy : PracticeResultKind.Wrong, mock, cardId, fieldId);
        }