public void GoBack_HasBackHistory_LocationChanged() { // Arrange var locationModel = new LocationModel { Name = "Initial" }; var viewmodel = new LocationViewmodel(locationModel, null, null, null, null); var nodeHistoryState = new NodeHistoryState(new HistoryNode(locationModel.Name, locationModel.Id.ToString()), 1, new [] { new HistoryNode("back node", "back node id"), }); _locationViewmodelFactory .Setup(lvf => lvf(It.IsAny <LocationModel>(), It.IsAny <INavigationContext>())) .Returns(viewmodel); SetupGenericBreadCrumbFactory(); var unitUnderTest = this.CreateViewModel(locationModel: locationModel, nodeHistoryState: nodeHistoryState); const string expected = "expected"; _locationService .Setup(ls => ls.GetLocationById(It.IsAny <string>())) .Returns(Task.FromResult(new LocationModel { Name = expected })); // Act unitUnderTest .BackCommand .Execute(null); var actual = unitUnderTest.Title; // Assert Assert.AreEqual(expected, actual); }
public NodeWindowViewModel(LocationModel locationModel, INodeNavigationService nodeNavigationService, ILocationService locationService, LocationViewmodel.Factory locationViewmodelFactory, DispatcherAccessor dispatcherAccessor, NodeHistoryState nodeHistoryState, BreadCrumbViewmodel.Factory breadCrumbViewmodelFactory) { _locationViewModel = locationViewmodelFactory(locationModel, this); _nodeNavigationService = nodeNavigationService; _locationService = locationService; _locationViewmodelFactory = locationViewmodelFactory; _dispatcherAccessor = dispatcherAccessor; _title = locationModel.Name; _nodeHistoryState = nodeHistoryState; _breadCrumbViewmodelFactory = breadCrumbViewmodelFactory; BackCommand = new AwaitableDelegateCommand(GoBack, () => BackAvailable); ForwardCommand = new AwaitableDelegateCommand(GoForward, () => ForwardAvailable); var breadCrumbs = ConvertToBreadCrumbs(_nodeHistoryState); BreadCrumbs = new ObservableCollection <BreadCrumbViewmodel>(breadCrumbs); }
private async Task OpenNewLocationWindow(string locationId) { var locationModel = await _locationService.GetLocationById(locationId); var current = new HistoryNode(locationModel.Name, locationModel.Id.ToString()); var nodeHistoryState = new NodeHistoryState(current, 100); var windowViewModel = _nodeWindowLocationFactory.Invoke(locationModel, nodeHistoryState); await _windowService.OpenNewNode(windowViewModel); }
private IEnumerable <BreadCrumbViewmodel> ConvertToBreadCrumbs(NodeHistoryState nodeHistoryState) { foreach (var historyNode in nodeHistoryState.BackNodes) { async void OnClicked() { var newHistoryState = nodeHistoryState.GoBackTo(historyNode); var locationModel = await _locationService.GetLocationById(historyNode.LocationId); await GoToLocation(locationModel, newHistoryState); } yield return(_breadCrumbViewmodelFactory(historyNode.NodeName, OnClicked)); } }
private NodeWindowViewModel CreateViewModel(LocationModel locationModel = null, NodeHistoryState nodeHistoryState = null) { if (locationModel == null) { locationModel = new LocationModel(); } return(new NodeWindowViewModel( locationModel, this.mockNodeNavigationService.Object, _locationService.Object, _locationViewmodelFactory.Object, _dispatcherAccessor, nodeHistoryState, _breadCrumbViewmodelFactory.Object)); }
public void GoBack_OneBack_CurrentSet() { // Arrange const string expected = "back node"; var unitUnderTest = new NodeHistoryState( new HistoryNode("First", "location1"), 1, new [] { new HistoryNode(expected, "back location"), }, null); // Act var actual = unitUnderTest .GoBack() .Current .NodeName; // Assert Assert.AreEqual(expected, actual); }
public void GoBack_OneBack_BackEmpty() { // Arrange var unitUnderTest = new NodeHistoryState( new HistoryNode("First", "location1"), 1, new [] { new HistoryNode("back node", "back location"), }, null); const int expected = 0; // Act var actual = unitUnderTest .GoBack() .BackNodes .Count(); // Assert Assert.AreEqual(expected, actual); }
public void Append_BackEmpty_CurrentSet() { // Arrange var unitUnderTest = new NodeHistoryState( new HistoryNode("First", "location1"), 1, null, null); const string expected = "new"; HistoryNode current = new HistoryNode(expected, "location2"); // Act var actual = unitUnderTest .Append(current) .Current .NodeName; // Assert Assert.AreEqual(expected, actual); }
public void Append_BackHasMax_BackMaximumMaintained() { // Arrange const int expected = 1; var unitUnderTest = new NodeHistoryState( new HistoryNode("First", "location1"), expected, new [] { new HistoryNode("back node", "back location"), }, null); HistoryNode current = new HistoryNode("new", "location2"); // Act var actual = unitUnderTest .Append(current) .BackNodes .Count(); // Assert Assert.AreEqual(expected, actual); }
public void GoBackTo_TwoBack_CurrentSet() { // Arrange const string expected = "back node"; var backNode = new HistoryNode(expected, "back location"); var unitUnderTest = new NodeHistoryState( new HistoryNode("First", "location1"), 1, new [] { backNode, new HistoryNode("some other node", "some other location id"), }, null); // Act var actual = unitUnderTest .GoBackTo(backNode) .Current .NodeName; // Assert Assert.AreEqual(expected, actual); }
public void GoBackTo_OneBack_CurrentBecomesForward() { // Arrange const string expected = "First"; var backNode = new HistoryNode("back node", "back location"); var unitUnderTest = new NodeHistoryState( new HistoryNode(expected, "location1"), 1, new [] { backNode, }, null); // Act var actual = unitUnderTest .GoBackTo(backNode) .ForwardNodes .First() .NodeName; // Assert Assert.AreEqual(expected, actual); }
private async Task GoToLocation(LocationModel locationModel, NodeHistoryState newHistoryState) { //var locationModel = await _locationService.GetLocationById(locationId); var locationViewModel = _locationViewmodelFactory.Invoke(locationModel, this); Location = locationViewModel; //this is a dirty hack Location .LoadedCommand .Execute(null); Title = locationModel.Name; _nodeHistoryState = newHistoryState; UpdateBreadkCrumbs(); ((IRaiseCanExecuteChanged)BackCommand).RaiseCanExecuteChanged(); ((IRaiseCanExecuteChanged)ForwardCommand).RaiseCanExecuteChanged(); }
public async Task History_AfterGotoLocation_Appended() { // Arrange const string expected = "expected"; var locationModel = new LocationModel { Name = "Initial" }; var viewmodel = new LocationViewmodel(locationModel, null, null, null, null); _locationViewmodelFactory .Setup(lvf => lvf(It.IsAny <LocationModel>(), It.IsAny <INavigationContext>())) .Returns(viewmodel); var nodeHistoryState = new NodeHistoryState(new HistoryNode(expected, "old location id"), 10); _breadCrumbViewmodelFactory .Setup(bcf => bcf(It.IsAny <string>(), It.IsAny <Action>())) .Returns(new BreadCrumbViewmodel(expected, () => { })); var windowViewModel = this.CreateViewModel(locationModel: locationModel, nodeHistoryState: nodeHistoryState); var unitUnderTest = (INavigationContext)windowViewModel; _locationService .Setup(ls => ls.GetLocationById(It.IsAny <string>())) .Returns(Task.FromResult(new LocationModel { Name = "some name" })); // Act await unitUnderTest.GoToLocation("some location id"); var actual = windowViewModel .BreadCrumbs .First() .DisplayText; // Assert Assert.AreEqual(expected, actual); }