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")); }
public async Task ErrorOnLoadingPracticeHistoryEntriesTest() { NotificationProviderMock notificationProviderMock = new NotificationProviderMock(); NotificationMessageProvider.Initialize(notificationProviderMock, 500000); 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" }); ApiConnectorMock mock = new ApiConnectorMock(); mock.Replies.Push(new ApiReply <List <PracticeHistoryEntry> >() { WasSuccessful = false, ResultMessage = "test-error" }); mock.Replies.Push(new ApiReply <Card>() { WasSuccessful = true, Result = card }); CardStatisticsViewModel viewModel = new CardStatisticsViewModel(navigationManagerMock, mock); bool result = await viewModel.InitializeAsync(); Assert.IsFalse(result); Assert.AreEqual(NotificationKind.ErrorNotification, notificationProviderMock.NotificationKind); Assert.AreEqual("test-error", notificationProviderMock.Message); }