public async Task Title_AfterGotoLocation_ExpectedValue() { // 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); SetupGenericBreadCrumbFactory(); var windowViewModel = this.CreateViewModel(locationModel: locationModel, nodeHistoryState: new NodeHistoryState(new HistoryNode("history node name", "history node id"), 10)); var unitUnderTest = (INavigationContext)windowViewModel; _locationService .Setup(ls => ls.GetLocationById(It.IsAny <string>())) .Returns(Task.FromResult(new LocationModel { Name = expected })); // Act await unitUnderTest.GoToLocation("some location id"); var actual = windowViewModel.Title; // Assert Assert.AreEqual(expected, actual); }
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); }
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); }