public void Test_Round_Trip_Works_For_Normal_ViewModel_Requests() { _fixture.ClearAll(); var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(GetType().Assembly); Mvx.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_MvxViewModelViewTypeFinder() { ClearAll(); var assembly = this.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.AreEqual(typeof(Test1ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest2View)); Assert.AreEqual(typeof(Test2ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest3View)); Assert.AreEqual(typeof(Test3ViewModel), result); result = test.FindTypeOrNull(typeof(OddNameOddness)); Assert.AreEqual(typeof(OddNameViewModel), result); // test for negatives result = test.FindTypeOrNull(typeof(AbstractTest1View)); Assert.IsNull(result); result = test.FindTypeOrNull(typeof(NotReallyAView)); Assert.IsNull(result); }
public void Test_Round_Trip_Works_For_Normal_ViewModel_Requests() { ClearAll(); var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(this.GetType().Assembly); Mvx.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, new MvxRequestedBy( MvxRequestedByType.AutomatedService, "HelloWorld")); var serializer = new MvxViewModelRequestCustomTextSerializer(); var output = serializer.SerializeObject(request); var deserializer = new MvxViewModelRequestCustomTextSerializer(); var deserialized = deserializer.DeserializeObject<MvxViewModelRequest>(output); Assert.AreEqual(typeof(Test1ViewModel), deserialized.ViewModelType); Assert.AreEqual(MvxRequestedByType.AutomatedService, deserialized.RequestedBy.Type); Assert.AreEqual("HelloWorld", deserialized.RequestedBy.AdditionalInfo); Assert.AreEqual(2, deserialized.PresentationValues.Count); Assert.AreEqual(2, deserialized.ParameterValues.Count); Assert.AreEqual("1'\\", deserialized.ParameterValues["On'e"]); Assert.AreEqual("2", deserialized.ParameterValues["Two"]); Assert.AreEqual("3\"\'\\", deserialized.PresentationValues["Thre\"\'\\e"]); Assert.AreEqual(null, deserialized.PresentationValues["Four"]); }
public void Test_ViewModelByName_Finds_Expected_ViewModel() { ClearAll(); var assembly = this.GetType().Assembly; var finder = new MvxViewModelByNameLookup(); finder.AddAll(assembly); Type result; Assert.IsTrue(finder.TryLookupByName("Test1ViewModel", out result)); Assert.AreEqual(typeof(Test1ViewModel), result); Assert.IsTrue(finder.TryLookupByName("Test2ViewModel", out result)); Assert.AreEqual(typeof(Test2ViewModel), result); Assert.IsTrue(finder.TryLookupByName("Test3ViewModel", out result)); Assert.AreEqual(typeof(Test3ViewModel), result); Assert.IsFalse(finder.TryLookupByName("AbstractTest1ViewModel", out result)); Assert.IsNull(result); Assert.IsFalse(finder.TryLookupByName("NoWayTestViewModel", out result)); Assert.IsNull(result); Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test1ViewModel", out result)); Assert.AreEqual(typeof(Test1ViewModel), result); Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test2ViewModel", out result)); Assert.AreEqual(typeof(Test2ViewModel), result); Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test3ViewModel", out result)); Assert.AreEqual(typeof(Test3ViewModel), result); Assert.IsFalse( finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.AbstractTest1ViewModel", out result)); Assert.IsNull(result); Assert.IsFalse(finder.TryLookupByFullName( "MvvmCross.Test.Mocks.TestViewModels.NoWayTestViewModel", out result)); Assert.IsNull(result); }
protected virtual void InitialiseViewModelTypeFinder() { var viewModelAssemblies = GetViewModelAssemblies(); var viewModelByNameLookup = new MvxViewModelByNameLookup(viewModelAssemblies); var finder = new MvxViewModelViewTypeFinder(viewModelByNameLookup); Mvx.RegisterSingleton <IMvxViewModelTypeFinder>(finder); }
public void IncludeMvvmcross64() { _ = new MvxSettings(); _ = new MvxStringToTypeParser(); //?? //_ = new MvxPluginManager(null); //should not be required _ = new MvxViewModelLoader(null); _ = new MvxNavigationService(null, null); _ = new MvxViewModelByNameLookup(); _ = new MvxViewModelViewTypeFinder(null, null); _ = new MvxViewModelViewLookupBuilder(); _ = new MvxCommandCollectionBuilder(); _ = new MvxStringDictionaryNavigationSerializer(); _ = new MvxChildViewModelCache(); _ = new MvxWeakCommandHelper(); }
public void Test_Builder() { ClearAll(); var assembly = this.GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(new[] { assembly }); var finder = new MvxViewModelViewTypeFinder(viewModelNameLookup); Ioc.RegisterSingleton <IMvxViewModelTypeFinder>(finder); var builder = new MvxViewModelViewLookupBuilder(); var result = builder.Build(new[] { assembly }); Assert.AreEqual(3, result.Count); Assert.AreEqual(typeof(Test1View), result[typeof(Test1ViewModel)]); Assert.AreEqual(typeof(NotTest2View), result[typeof(Test2ViewModel)]); Assert.AreEqual(typeof(NotTest3View), result[typeof(Test3ViewModel)]); }
public void Test_ViewModelByName_Finds_Expected_ViewModel() { ClearAll(); var assembly = this.GetType().Assembly; var finder = new MvxViewModelByNameLookup(new[] { assembly }); Type result; Assert.IsTrue(finder.TryLookup("Test1ViewModel", out result)); Assert.AreEqual(typeof(Test1ViewModel), result); Assert.IsTrue(finder.TryLookup("Test2ViewModel", out result)); Assert.AreEqual(typeof(Test2ViewModel), result); Assert.IsTrue(finder.TryLookup("Test3ViewModel", out result)); Assert.AreEqual(typeof(Test3ViewModel), result); Assert.IsFalse(finder.TryLookup("AbstractTest1ViewModel", out result)); Assert.IsNull(result); Assert.IsFalse(finder.TryLookup("NoWayTestViewModel", out result)); Assert.IsNull(result); }
protected virtual void InitializeViewModelTypeFinder() { var viewModelByNameLookup = new MvxViewModelByNameLookup(); var viewModelAssemblies = GetViewModelAssemblies(); foreach (var assembly in viewModelAssemblies) { viewModelByNameLookup.AddAll(assembly); } Mvx.RegisterSingleton <IMvxViewModelByNameLookup>(viewModelByNameLookup); Mvx.RegisterSingleton <IMvxViewModelByNameRegistry>(viewModelByNameLookup); var nameMappingStrategy = CreateViewToViewModelNaming(); var finder = new MvxViewModelViewTypeFinder(viewModelByNameLookup, nameMappingStrategy); Mvx.RegisterSingleton <IMvxViewModelTypeFinder>(finder); }
public void Test_Builder() { ClearAll(); var assembly = this.GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(assembly); var nameMapping = new MvxPostfixAwareViewToViewModelNameMapping("View", "Oddness"); var finder = new MvxViewModelViewTypeFinder(viewModelNameLookup, nameMapping); Ioc.RegisterSingleton<IMvxViewModelTypeFinder>(finder); var builder = new MvxViewModelViewLookupBuilder(); var result = builder.Build(new[] { assembly }); Assert.AreEqual(4, result.Count); Assert.AreEqual(typeof(Test1View), result[typeof(Test1ViewModel)]); Assert.AreEqual(typeof(NotTest2View), result[typeof(Test2ViewModel)]); Assert.AreEqual(typeof(NotTest3View), result[typeof(Test3ViewModel)]); Assert.AreEqual(typeof(OddNameOddness), result[typeof(OddNameViewModel)]); }
public void Test_Builder() { ClearAll(); var assembly = this.GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(); viewModelNameLookup.AddAll(assembly); var nameMapping = new MvxPostfixAwareViewToViewModelNameMapping("View", "Oddness"); var finder = new MvxViewModelViewTypeFinder(viewModelNameLookup, nameMapping); Ioc.RegisterSingleton <IMvxViewModelTypeFinder>(finder); var builder = new MvxViewModelViewLookupBuilder(); var result = builder.Build(new[] { assembly }); Assert.AreEqual(4, result.Count); Assert.AreEqual(typeof(Test1View), result[typeof(Test1ViewModel)]); Assert.AreEqual(typeof(NotTest2View), result[typeof(Test2ViewModel)]); Assert.AreEqual(typeof(NotTest3View), result[typeof(Test3ViewModel)]); Assert.AreEqual(typeof(OddNameOddness), result[typeof(OddNameViewModel)]); }
public void Test_MvxViewModelViewTypeFinder() { ClearAll(); var assembly = this.GetType().Assembly; var viewModelNameLookup = new MvxViewModelByNameLookup(new[] { assembly }); var test = new MvxViewModelViewTypeFinder(viewModelNameLookup); // test for positives var result = test.FindTypeOrNull(typeof(Test1View)); Assert.AreEqual(typeof(Test1ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest2View)); Assert.AreEqual(typeof(Test2ViewModel), result); result = test.FindTypeOrNull(typeof(NotTest3View)); Assert.AreEqual(typeof(Test3ViewModel), result); // test for negatives result = test.FindTypeOrNull(typeof(AbstractTest1View)); Assert.IsNull(result); result = test.FindTypeOrNull(typeof(NotReallyAView)); Assert.IsNull(result); }
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 void Test_ViewModelByName_Finds_Expected_ViewModel() { ClearAll(); var assembly = this.GetType().Assembly; var finder = new MvxViewModelByNameLookup(); finder.AddAll(assembly); Type result; Assert.IsTrue(finder.TryLookupByName("Test1ViewModel", out result)); Assert.AreEqual(typeof(Test1ViewModel), result); Assert.IsTrue(finder.TryLookupByName("Test2ViewModel", out result)); Assert.AreEqual(typeof(Test2ViewModel), result); Assert.IsTrue(finder.TryLookupByName("Test3ViewModel", out result)); Assert.AreEqual(typeof(Test3ViewModel), result); Assert.IsFalse(finder.TryLookupByName("AbstractTest1ViewModel", out result)); Assert.IsNull(result); Assert.IsFalse(finder.TryLookupByName("NoWayTestViewModel", out result)); Assert.IsNull(result); Assert.IsTrue(finder.TryLookupByFullName("Cirrious.MvvmCross.Test.Mocks.TestViewModels.Test1ViewModel", out result)); Assert.AreEqual(typeof(Test1ViewModel), result); Assert.IsTrue(finder.TryLookupByFullName("Cirrious.MvvmCross.Test.Mocks.TestViewModels.Test2ViewModel", out result)); Assert.AreEqual(typeof(Test2ViewModel), result); Assert.IsTrue(finder.TryLookupByFullName("Cirrious.MvvmCross.Test.Mocks.TestViewModels.Test3ViewModel", out result)); Assert.AreEqual(typeof(Test3ViewModel), result); Assert.IsFalse( finder.TryLookupByFullName("Cirrious.MvvmCross.Test.Mocks.TestViewModels.AbstractTest1ViewModel", out result)); Assert.IsNull(result); Assert.IsFalse(finder.TryLookupByFullName( "Cirrious.MvvmCross.Test.Mocks.TestViewModels.NoWayTestViewModel", out result)); Assert.IsNull(result); }
protected virtual void InitializeViewModelTypeFinder() { var viewModelByNameLookup = new MvxViewModelByNameLookup(); var viewModelAssemblies = this.GetViewModelAssemblies(); foreach (var assembly in viewModelAssemblies) { viewModelByNameLookup.AddAll(assembly); } Mvx.RegisterSingleton<IMvxViewModelByNameLookup>(viewModelByNameLookup); Mvx.RegisterSingleton<IMvxViewModelByNameRegistry>(viewModelByNameLookup); var nameMappingStrategy = this.CreateViewToViewModelNaming(); var finder = new MvxViewModelViewTypeFinder(viewModelByNameLookup, nameMappingStrategy); Mvx.RegisterSingleton<IMvxViewModelTypeFinder>(finder); }