public void Test_SaveState() { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxStringToTypeParser>(new MvxStringToTypeParser()); var viewModel = new Test3ViewModel { AdditionalSaveStateFields = new Dictionary <string, string> { { "Life1", "John" }, { "Life2", "Jane" } }, SaveStateBundleObject = new BundleObject { TheBool1 = false, TheBool2 = true, TheGuid1 = Guid.NewGuid(), TheGuid2 = new Guid(123, 10, 444, 1, 2, 3, 4, 5, 6, 7, 8), TheInt1 = 123, TheInt2 = 456, TheString1 = "Hello World", TheString2 = null } }; var bundle = viewModel.SaveStateBundle(); var extracted = bundle.Read <BundleObject>(); Assert.Equal(viewModel.SaveStateBundleObject, extracted); Assert.Equal("John", bundle.Data["Life1"]); Assert.Equal("Jane", bundle.Data["Life2"]); }
public void Test_LoaderForNull() { _fixture.ClearAll(); var request = new MvxViewModelRequest <MvxNullViewModel>(null, null); var state = new MvxBundle(); var loader = new MvxViewModelLoader(null); var viewModel = loader.LoadViewModel(request, state); Assert.IsType <MvxNullViewModel>(viewModel); }
public void Test_LoaderForNull() { _fixture.ClearAll(); var request = new MvxViewModelRequest <MvxNullViewModel>(null, null); var state = new MvxBundle(); var loader = new MvxViewModelLoader(null); var args = new MvxNavigateEventArgs(NavigationMode.Show); var viewModel = loader.LoadViewModel(request, state, args); Assert.IsType <MvxNullViewModel>(viewModel); }
public void Test_Round_Trip_Works_For_Normal_ViewModel_Requests() { _fixture.ClearAll(); var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(GetType().Assembly); Mvx.IoCProvider.RegisterSingleton <IMvxViewModelByNameLookup>(viewModelNameLookup); var parameterBundle = new MvxBundle(new Dictionary <string, string> { { "On'e", "1'\\" }, { "Two", "2" } }); var presentationBundle = new MvxBundle(new Dictionary <string, string> { { "Thre\"\'\\e", "3\"\'\\" }, { "Four", null } }); var request = new MvxViewModelRequest <Test1ViewModel>(parameterBundle, presentationBundle); var serializer = new MvxViewModelRequestCustomTextSerializer(); var output = serializer.SerializeObject(request); var deserializer = new MvxViewModelRequestCustomTextSerializer(); var deserialized = deserializer.DeserializeObject <MvxViewModelRequest>(output); Assert.Equal(typeof(Test1ViewModel), deserialized.ViewModelType); Assert.Equal(2, deserialized.PresentationValues.Count); Assert.Equal(2, deserialized.ParameterValues.Count); Assert.Equal("1'\\", deserialized.ParameterValues["On'e"]); Assert.Equal("2", deserialized.ParameterValues["Two"]); Assert.Equal("3\"\'\\", deserialized.PresentationValues["Thre\"\'\\e"]); Assert.Null(deserialized.PresentationValues["Four"]); }
public void Test_MvxViewModelViewTypeFinder() { _fixture.ClearAll(); var assembly = GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(assembly); var nameMapping = new MvxPostfixAwareViewToViewModelNameMapping("View", "Oddness"); var test = new MvxViewModelViewTypeFinder(viewModelNameLookup, nameMapping); // test for positives var result = test.FindTypeOrNull(typeof(Test1View)); Assert.Equal(typeof(Test1ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest2View)); Assert.Equal(typeof(Test2ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest3View)); Assert.Equal(typeof(Test3ViewModel), result); result = test.FindTypeOrNull(typeof(OddNameOddness)); Assert.Equal(typeof(OddNameViewModel), result); // test for negatives result = test.FindTypeOrNull(typeof(AbstractTest1View)); Assert.Null(result); result = test.FindTypeOrNull(typeof(NotReallyAView)); Assert.Null(result); }
public void Test_RaisePropertyChangedForExpression() { _fixture.ClearAll(); var dispatcher = new InlineMockMainThreadDispatcher(); _fixture.Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(dispatcher); var notified = new List <string>(); var t = new TestInpc(); t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName); t.RaisePropertyChanged(() => t.Foo); Assert.True(notified.Count == 1); Assert.True(notified[0] == "Foo"); }
public void Test_NoReloadState() { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxStringToTypeParser>(new MvxStringToTypeParser()); var testThing = new MockTestThing(); _fixture.Ioc.RegisterSingleton <ITestThing>(testThing); var testObject = new BundleObject { TheBool1 = false, TheBool2 = true, TheGuid1 = Guid.NewGuid(), TheGuid2 = new Guid(123, 10, 444, 1, 2, 3, 4, 5, 6, 7, 8), TheInt1 = 123, TheInt2 = 456, TheString1 = "Hello World", TheString2 = null }; var bundle = new MvxBundle(); bundle.Write(testObject); var navigationService = _fixture.Ioc.Resolve <IMvxNavigationService>(); var toTest = new MvxDefaultViewModelLocator(navigationService); var args = new MvxNavigateEventArgs(NavigationMode.Show); IMvxViewModel viewModel = toTest.Load(typeof(Test1ViewModel), bundle, null, args); Assert.NotNull(viewModel); var typedViewModel = (Test1ViewModel)viewModel; Assert.Equal(bundle, typedViewModel.BundleInit); Assert.Null(typedViewModel.BundleState); Assert.Equal(testThing, typedViewModel.Thing); Assert.Equal(testObject, typedViewModel.TheInitBundleSet); Assert.Null(typedViewModel.TheReloadBundleSet); Assert.Equal(testObject.TheGuid1, typedViewModel.TheInitGuid1Set); Assert.Equal(testObject.TheGuid2, typedViewModel.TheInitGuid2Set); Assert.Equal(testObject.TheString1, typedViewModel.TheInitString1Set); Assert.Equal(Guid.Empty, typedViewModel.TheReloadGuid1Set); Assert.Equal(Guid.Empty, typedViewModel.TheReloadGuid2Set); Assert.Null(typedViewModel.TheReloadString1Set); Assert.True(typedViewModel.StartCalled); }
public void TryResolve_CircularButSafeDynamicWithOptionOff_ReturnsTrue() { COdd.FirstTime = true; _fixture.ClearAll(new MvxIocOptions() { TryToDetectDynamicCircularReferences = false }); _fixture.Ioc.RegisterType <IA, A>(); _fixture.Ioc.RegisterType <IB, B>(); _fixture.Ioc.RegisterType <IC, COdd>(); var result = _fixture.Ioc.TryResolve(out IA a); Assert.True(result); Assert.NotNull(a); }
public void Test_Conventional_Command() { _fixture.ClearAll(); var testObject = new CommandTestClass(); var collection = new MvxCommandCollectionBuilder() .BuildCollectionFor(testObject); var myCommand = collection["My"]; Assert.NotNull(myCommand); CheckCounts(testObject); myCommand.Execute(); CheckCounts(testObject, 1, 1); myCommand.Execute(); myCommand.Execute(); myCommand.Execute(); CheckCounts(testObject, 4, 4); }
public RoutingServiceTests(NavigationTestFixture fixture) { _fixture = fixture; _fixture.ClearAll(); // ReSharper disable once AssignNullToNotNullAttribute Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AdditionalSetup(fixture); }
public void Test_RoundTrip() { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxStringToTypeParser>(new MvxStringToTypeParser()); var testObject = new BundleObject { TheBool1 = false, TheBool2 = true, TheGuid1 = Guid.NewGuid(), TheGuid2 = new Guid(123, 10, 444, 1, 2, 3, 4, 5, 6, 7, 8), TheInt1 = 123, TheInt2 = 456, TheString1 = "Hello World", TheString2 = null }; var bundle = new MvxBundle(); bundle.Write(testObject); var output = bundle.Read <BundleObject>(); Assert.Equal(testObject, output); }
public void TestIntValues() { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxAutoValueConverters>(new MockAutoValueConverters()); Assert.Equal(0, typeof(int).MakeSafeValue(0)); Assert.Equal(0, typeof(int).MakeSafeValue(null)); Assert.Equal(1, typeof(int).MakeSafeValue(1)); Assert.Equal(0, typeof(int?).MakeSafeValue(0)); Assert.Null(typeof(int?).MakeSafeValue(null)); Assert.Equal(1, typeof(int?).MakeSafeValue(1)); Assert.Equal(0, typeof(int?).MakeSafeValue(0.0)); Assert.Equal(1, typeof(int?).MakeSafeValue(1.0)); }
public void Test_Builder() { _fixture.ClearAll(); var assembly = GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(assembly); var nameMapping = new MvxPostfixAwareViewToViewModelNameMapping("View", "Oddness"); var finder = new MvxViewModelViewTypeFinder(viewModelNameLookup, nameMapping); _fixture.Ioc.RegisterSingleton <IMvxViewModelTypeFinder>(finder); var builder = new MvxViewModelViewLookupBuilder(); var result = builder.Build(new[] { assembly }); Assert.Equal(4, result.Count); Assert.Equal(typeof(Test1View), result[typeof(Test1ViewModel)]); Assert.Equal(typeof(NotTest2View), result[typeof(Test2ViewModel)]); Assert.Equal(typeof(NotTest3View), result[typeof(Test3ViewModel)]); Assert.Equal(typeof(OddNameOddness), result[typeof(OddNameViewModel)]); }
public void Test_ViewModelByName_Finds_Expected_ViewModel() { _fixture.ClearAll(); var assembly = GetType().Assembly; var finder = new MvxViewModelByNameLookup(); finder.AddAll(assembly); Type result; Assert.True(finder.TryLookupByName("Test1ViewModel", out result)); Assert.Equal(typeof(Test1ViewModel), result); Assert.True(finder.TryLookupByName("Test2ViewModel", out result)); Assert.Equal(typeof(Test2ViewModel), result); Assert.True(finder.TryLookupByName("Test3ViewModel", out result)); Assert.Equal(typeof(Test3ViewModel), result); Assert.False(finder.TryLookupByName("AbstractTest1ViewModel", out result)); Assert.Null(result); Assert.False(finder.TryLookupByName("NoWayTestViewModel", out result)); Assert.Null(result); Assert.True(finder.TryLookupByFullName("MvvmCross.UnitTest.Mocks.TestViewModels.Test1ViewModel", out result)); Assert.Equal(typeof(Test1ViewModel), result); Assert.True(finder.TryLookupByFullName("MvvmCross.UnitTest.Mocks.TestViewModels.Test2ViewModel", out result)); Assert.Equal(typeof(Test2ViewModel), result); Assert.True(finder.TryLookupByFullName("MvvmCross.UnitTest.Mocks.TestViewModels.Test3ViewModel", out result)); Assert.Equal(typeof(Test3ViewModel), result); Assert.False( finder.TryLookupByFullName("MvvmCross.UnitTest.Mocks.TestViewModels.AbstractTest1ViewModel", out result)); Assert.Null(result); Assert.False(finder.TryLookupByFullName( "MvvmCross.UnitTest.Mocks.TestViewModels.NoWayTestViewModel", out result)); Assert.Null(result); }
public MvxObservableCollectionTest(NavigationTestFixture fixture) { _fixture = fixture; _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxMainThreadAsyncDispatcher>(new DummyDispatcher()); }
private MvxFullBinding TestSetupCommon(MvxBindingMode mvxBindingMode, MvxBindingMode defaultMode, out MockSourceBinding mockSource, out MockTargetBinding mockTarget) { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher()); var mockSourceBindingFactory = new Mock <IMvxSourceBindingFactory>(); _fixture.Ioc.RegisterSingleton(mockSourceBindingFactory.Object); var mockTargetBindingFactory = new Mock <IMvxTargetBindingFactory>(); _fixture.Ioc.RegisterSingleton(mockTargetBindingFactory.Object); var realSourceStepFactory = new MvxSourceStepFactory(); realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory()); _fixture.Ioc.RegisterSingleton <IMvxSourceStepFactory>(realSourceStepFactory); var sourceText = "sourceText"; var targetName = "targetName"; var source = new { Value = 1 }; var target = new { Value = 2 }; var converterParameter = new { Value = 3 }; var fallbackValue = new { Value = 4 }; var bindingDescription = new MvxBindingDescription { Source = new MvxPathSourceStepDescription { Converter = null, ConverterParameter = converterParameter, FallbackValue = fallbackValue, SourcePropertyPath = sourceText, }, Mode = mvxBindingMode, TargetName = targetName }; mockSource = new MockSourceBinding(); mockTarget = new MockTargetBinding { DefaultMode = defaultMode }; var localSource = mockSource; mockSourceBindingFactory .Setup(x => x.CreateBinding(It.IsAny <object>(), It.Is <string>(s => s == sourceText))) .Returns((object a, string b) => localSource); var localTarget = mockTarget; mockTargetBindingFactory .Setup(x => x.CreateBinding(It.IsAny <object>(), It.Is <string>(s => s == targetName))) .Returns((object a, string b) => localTarget); mockSource.TryGetValueResult = true; mockSource.TryGetValueValue = "TryGetValueValue"; var request = new MvxBindingRequest(source, target, bindingDescription); var toTest = new MvxFullBinding(request); return(toTest); }
public NavigationServiceTests(NavigationTestFixture fixture) { _fixture = fixture; _fixture.ClearAll(); AdditionalSetup(fixture); }
private void TestCommon(MvxBindingMode bindingMode, bool expectSourceBinding, bool expectTargetBinding) { _fixture.ClearAll(); _fixture.Ioc.RegisterSingleton <IMvxMainThreadAsyncDispatcher>(new InlineMockMainThreadDispatcher()); var mockSourceBindingFactory = new Mock <IMvxSourceBindingFactory>(); _fixture.Ioc.RegisterSingleton(mockSourceBindingFactory.Object); var mockTargetBindingFactory = new Mock <IMvxTargetBindingFactory>(); _fixture.Ioc.RegisterSingleton(mockTargetBindingFactory.Object); var realSourceStepFactory = new MvxSourceStepFactory(); realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory()); _fixture.Ioc.RegisterSingleton <IMvxSourceStepFactory>(realSourceStepFactory); var sourceText = "sourceText"; var targetName = "targetName"; var source = new { Value = 1 }; var target = new { Value = 2 }; var converterParameter = new { Value = 3 }; var fallbackValue = new { Value = 4 }; var converter = new Mock <IMvxValueConverter>(); var bindingDescription = new MvxBindingDescription { Source = new MvxPathSourceStepDescription() { Converter = converter.Object, ConverterParameter = converterParameter, FallbackValue = fallbackValue, SourcePropertyPath = sourceText, }, Mode = bindingMode, TargetName = targetName }; var mockSourceBinding = new Mock <IMvxSourceBinding>(); var mockTargetBinding = new Mock <IMvxTargetBinding>(); mockSourceBindingFactory .Setup(x => x.CreateBinding(It.Is <object>(s => s == source), It.Is <string>(s => s == sourceText))) .Returns((object a, string b) => mockSourceBinding.Object); mockTargetBindingFactory .Setup(x => x.CreateBinding(It.Is <object>(s => s == target), It.Is <string>(s => s == targetName))) .Returns((object a, string b) => mockTargetBinding.Object); var request = new MvxBindingRequest(source, target, bindingDescription); var toTest = new MvxFullBinding(request); //var sourceBindingTimes = expectSourceBinding ? Times.Once() : Times.Never(); //mockSourceBinding.Verify(x => x.Changed += It.IsAny<EventHandler<MvxSourcePropertyBindingEventArgs>>(), sourceBindingTimes); mockSourceBindingFactory .Verify(x => x.CreateBinding(It.Is <object>(s => s == source), It.Is <string>(s => s == sourceText)), Times.Once()); //var targetBindingTimes = expectSourceBinding ? Times.Once() : Times.Never(); //mockTargetBinding.Verify(x => x.ValueChanged += It.IsAny<EventHandler<MvxTargetChangedEventArgs>>(), targetBindingTimes); mockTargetBindingFactory .Verify(x => x.CreateBinding(It.Is <object>(s => s == target), It.Is <string>(s => s == targetName)), Times.Once()); }
public MvxStringToTypeParserTest(NavigationTestFixture fixture) { _fixture = fixture; _fixture.ClearAll(); _fixture.SetInvariantCulture(); }
public MvxIocTest(NavigationTestFixture fixture) { _fixture = fixture; _fixture.ClearAll(); }
private void DoTest( Action <MockBindingContext> action, Func <MockBindingContext, object> findTargetObjectFunc, MvxBindingDescription expectedDescription) { _fixture.ClearAll(); var dataContext = new TestDataContext(); var bindingContext = new Mock <IMvxBindingContext>(); bindingContext.Setup(x => x.RegisterBinding(It.IsAny <object>(), It.IsAny <IMvxUpdateableBinding>())); bindingContext.SetupGet(x => x.DataContext).Returns(dataContext); var callbacksSeen = new List <Callback>(); var binder = new Mock <IMvxBinder>(); binder.Setup( b => b.Bind(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <IEnumerable <MvxBindingDescription> >())) .Callback((object source, object target, IEnumerable <MvxBindingDescription> descriptions) => { if (descriptions.Count() != 1) { throw new Exception("Unexpected description count"); } callbacksSeen.Add(new Callback { Source = source, Target = target, BindingDescription = descriptions.First() }); }); _fixture.Ioc.RegisterSingleton(binder.Object); _fixture.Ioc.RegisterSingleton <IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser()); var converterLookup = new MvxValueConverterRegistry(); converterLookup.AddOrOverwrite("SampleConv", new SampleValueConverter()); _fixture.Ioc.RegisterSingleton <IMvxValueConverterLookup>(converterLookup); var testTarget = new MockBindingContext { Target = new TestTarget(), BindingContext = bindingContext.Object }; action(testTarget); Assert.Single(callbacksSeen); var callback = callbacksSeen[0]; var expectedTarget = findTargetObjectFunc(testTarget); Assert.Equal(expectedTarget, callback.Target); Assert.Equal(dataContext, callback.Source); var desc = callback.BindingDescription; Assert.True(expectedDescription.Source is MvxPathSourceStepDescription); var path = desc.Source as MvxPathSourceStepDescription; Assert.True(desc.Source is MvxPathSourceStepDescription); var expectedPath = expectedDescription.Source as MvxPathSourceStepDescription; Assert.Equal(expectedPath.ConverterParameter, path.ConverterParameter); Assert.Equal(expectedPath.FallbackValue, path.FallbackValue); Assert.Equal(expectedPath.SourcePropertyPath, path.SourcePropertyPath); Assert.Equal(expectedDescription.Mode, desc.Mode); Assert.Equal(expectedDescription.TargetName, desc.TargetName); if (expectedPath.Converter == null) { Assert.Null(path.Converter); } else { Assert.Equal(expectedPath.Converter.GetType(), path.Converter.GetType()); } }