public void Test_NormalViewModel() { ClearAll(); IMvxViewModel outViewModel = new Test2ViewModel(); var mockLocator = new Mock<IMvxViewModelLocator>(); mockLocator.Setup( m => m.Load(It.IsAny<Type>(), It.IsAny<IMvxBundle>(), It.IsAny<IMvxBundle>())) .Returns(() => outViewModel); var mockCollection = new Moq.Mock<IMvxViewModelLocatorCollection>(); mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>())) .Returns(() => mockLocator.Object); Ioc.RegisterSingleton(mockCollection.Object); var parameters = new Dictionary<string, string> { { "foo", "bar" } }; var request = new MvxViewModelRequest<Test2ViewModel>(new MvxBundle(parameters), null, MvxRequestedBy.UserAction); var state = new MvxBundle(); var loader = new MvxViewModelLoader(); var viewModel = loader.LoadViewModel(request, state); Assert.AreSame(outViewModel, viewModel); Assert.AreEqual(MvxRequestedBy.UserAction, viewModel.RequestedBy); }
public void Test_LoaderForNull() { ClearAll(); var request = new MvxViewModelRequest<MvxNullViewModel>(null, null, MvxRequestedBy.UserAction); var state = new MvxBundle(); var loader = new MvxViewModelLoader(); var viewModel = loader.LoadViewModel(request, state); Assert.IsInstanceOf<MvxNullViewModel>(viewModel); }
public void Test_FailedViewModelLocatorCollection() { ClearAll(); var mockCollection = new Moq.Mock<IMvxViewModelLocatorCollection>(); mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>())) .Returns(() => null); Ioc.RegisterSingleton(mockCollection.Object); var parameters = new Dictionary<string, string> { { "foo", "bar" } }; var request = new MvxViewModelRequest<Test2ViewModel>(new MvxBundle(parameters), null, MvxRequestedBy.UserAction); var state = new MvxBundle(); var loader = new MvxViewModelLoader(); Assert.Throws<MvxException>(() => { var viewModel = loader.LoadViewModel(request, state); }); }