public async Task CommandsAreInitializedCorrectlyTest() { CardTemplate template = new CardTemplate() { CardTemplateId = 2 }; ApiConnectorMock mock = CreateMockForInitialize(new List <CardTemplate>()); CardTemplateSearchViewModel viewModel = new CardTemplateSearchViewModel(navigationManagerMock, mock) { SelectedEntity = template }; await viewModel.InitializeAsync(); Assert.IsNotNull(viewModel.NewCommand.CommandText); Assert.IsNotNull(viewModel.NewCommand.ToolTip); Assert.AreEqual("/New", viewModel.NewCommand.TargetUri); Assert.IsTrue(viewModel.NewCommand.IsRelative); Assert.IsNotNull(viewModel.EditCommand.CommandText); Assert.IsNotNull(viewModel.EditCommand.ToolTip); Assert.AreEqual("/2", viewModel.EditCommand.TargetUriFactory.Invoke(template)); Assert.IsTrue(viewModel.EditCommand.IsRelative); Assert.IsNotNull(viewModel.DeleteCommand.CommandText); Assert.IsNotNull(viewModel.DeleteCommand.ToolTip); }
public async Task DoesExecuteSearchOnInitializeTest() { CardTemplate template = new CardTemplate(); ApiConnectorMock mock = CreateMockForInitialize(new List <CardTemplate>() { template }); NavigationManagerMock navigationManagerMock = new NavigationManagerMock(); CardTemplateSearchViewModel viewModel = new CardTemplateSearchViewModel(navigationManagerMock, mock); bool result = await viewModel.InitializeAsync(); Assert.IsTrue(result); Assert.AreEqual(1, viewModel.SearchResults.Count); Assert.AreSame(template, viewModel.SearchResults[0]); }
public async Task ExecuteSearchParametersTest() { ApiConnectorMock mock = CreateMockForInitialize(new List <CardTemplate>()); CardTemplateSearchViewModel viewModel = new CardTemplateSearchViewModel(navigationManagerMock, mock); await viewModel.SearchAsync(); Dictionary <string, object> parameters = mock.Parameters.Pop() as Dictionary <string, object>; Assert.AreEqual(0, parameters.Count); viewModel.SearchText = "text"; mock.Replies.Push(new ApiReply <List <CardTemplate> >() { WasSuccessful = true, Result = new List <CardTemplate>() }); await viewModel.SearchAsync(); parameters = mock.Parameters.Pop() as Dictionary <string, object>; Assert.AreEqual(1, parameters.Count); Assert.AreEqual("text", parameters[nameof(viewModel.SearchText)]); }