public void OperationShouldSerializeAsyncMethodWithViewModel() { var vmMock = new NavigableViewModelMock(); ServiceProvider.OperationCallbackFactory = new SerializableOperationCallbackFactory(); var operation = new AsyncOperation <bool>(); IOperationResult <bool> result = OperationResult.CreateResult(OperationType.PageNavigation, this, true, new NavigationContext(NavigationType.Page, NavigationMode.Back, vmMock, vmMock, this)); AsyncMethodWithViewModel(operation, true, vmMock); var callback = operation.ToOperationCallback(); var serialize = Serializer.Serialize(callback); serialize.Position = 0; callback = (IOperationCallback)Serializer.Deserialize(serialize); IocContainer.GetFunc = (type, s, arg3) => { if (type == GetType()) { return(this); } return(Activator.CreateInstance(type)); }; AsyncMethodInvoked.ShouldBeFalse(); ViewModel.ShouldBeNull(); callback.Invoke(result); AsyncMethodInvoked.ShouldBeTrue(); ViewModel.ShouldEqual(vmMock); }
public void OperationShouldSerializeAnonymousClassMethods() { var vmMock = new NavigableViewModelMock(); ToolkitServiceProvider.OperationCallbackFactory = new SerializableOperationCallbackFactory(Serializer); var operation = new AsyncOperation <bool>(); var result = OperationResult.CreateResult(OperationType.PageNavigation, this, true, new NavigationContext(NavigationType.Page, NavigationMode.Back, vmMock, vmMock, this)); operation.ContinueWith(operationResult => CallbackAnonMethod(operationResult, vmMock)); ResultAnon.ShouldBeNull(); ViewModel.ShouldBeNull(); var callback = operation.ToOperationCallback(); var serialize = Serializer.Serialize(callback); serialize.Position = 0; callback = (IOperationCallback)Serializer.Deserialize(serialize); IocContainer.GetFunc = (type, s, arg3) => { if (type == GetType()) { return(this); } return(Activator.CreateInstance(type)); }; ResultAnon.ShouldBeNull(); ViewModel.ShouldBeNull(); callback.Invoke(result); ResultAnon.ShouldEqual(result); ViewModel.ShouldEqual(vmMock); }
public async Task Should_Observe_Pushed() { // Given PopupNavigationEvent pushing = null; var viewModel = new NavigableViewModelMock(); var popup = new PopupMock { ViewModel = viewModel }; var navigation = Substitute.For <IPopupNavigation>(); var viewLocator = Substitute.For <IViewLocator>(); viewLocator.ResolveView(Arg.Any <IViewModel>()).Returns(popup); PopupViewStackService sut = new PopupViewStackServiceFixture().WithNavigation(navigation).WithViewLocator(viewLocator); sut.Pushed.Subscribe(x => pushing = x); // When await sut.PushPopup(viewModel); navigation.Pushed += Raise.EventWith(new PopupNavigationEventArgs(popup, true)); // Then pushing.ViewModel.Should().Be(viewModel); }
public void Should_Observe_Pushing() { // Given PopupNavigationEvent?pushing = null; var viewModel = new NavigableViewModelMock(); var popup = new PopupMock { ViewModel = viewModel }; var navigation = Substitute.For <IPopupNavigation>(); PopupViewStackService sut = new PopupViewStackServiceFixture().WithNavigation(navigation); sut.Pushing.Subscribe(x => pushing = x); // When navigation.Pushing += Raise.EventWith(new PopupNavigationEventArgs(popup, true)); if (pushing is null) { throw new InvalidOperationException("pushing should not be null."); } // Then pushing.ViewModel.Should().Be(viewModel); }
public async Task Should_Call_Popup_Navigation() { // Given var viewModel = new NavigableViewModelMock(); var navigation = Substitute.For <IPopupNavigation>(); PopupViewStackService sut = new PopupViewStackServiceFixture().WithNavigation(navigation); // When await sut.PushPopup(viewModel); // Then await navigation.Received(1).PushAsync(Arg.Any <PopupPage>()).ConfigureAwait(false); }
public async Task Should_Call_View_Locator() { // Given var viewModel = new NavigableViewModelMock(); var viewLocator = Substitute.For <IViewLocator>(); viewLocator.ResolveView(Arg.Any <IViewModel>()).Returns(new PopupMock()); PopupViewStackService sut = new PopupViewStackServiceFixture().WithViewLocator(viewLocator); // When await sut.PushPopup(viewModel); // Then viewLocator.Received(1).ResolveView(Arg.Any <IViewModel>()); }
public void Should_Observe_Popped() { // Given PopupNavigationEvent pushing = null; var viewModel = new NavigableViewModelMock(); var popup = new PopupMock { ViewModel = viewModel }; var navigation = Substitute.For <IPopupNavigation>(); PopupViewStackService sut = new PopupViewStackServiceFixture().WithNavigation(navigation); sut.Popped.Subscribe(x => pushing = x); // When navigation.Popped += Raise.EventWith(new PopupNavigationEventArgs(popup, true)); // Then pushing.ViewModel.Should().Be(viewModel); }
public void CallbackAnonMethod(IOperationResult <bool> result, NavigableViewModelMock vm) { ResultAnon = result; ViewModel = vm; }