Inheritance: IMvxViewModelLocator
コード例 #1
0
        public void Test_NoReloadState()
        {
            ClearAll();

            Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());

            var testThing = new MockTestThing();
            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 toTest = new MvxDefaultViewModelLocator();

            IMvxViewModel viewModel = toTest.Load(typeof(Test1ViewModel), bundle, null);

            Assert.IsNotNull(viewModel);
            var typedViewModel = (Test1ViewModel)viewModel;
            Assert.AreSame(bundle, typedViewModel.BundleInit);
            Assert.IsNull(typedViewModel.BundleState);
            Assert.AreSame(testThing, typedViewModel.Thing);
            Assert.AreEqual(testObject, typedViewModel.TheInitBundleSet);
            Assert.IsNull(typedViewModel.TheReloadBundleSet);
            Assert.AreEqual(testObject.TheGuid1, typedViewModel.TheInitGuid1Set);
            Assert.AreEqual(testObject.TheGuid2, typedViewModel.TheInitGuid2Set);
            Assert.AreEqual(testObject.TheString1, typedViewModel.TheInitString1Set);
            Assert.AreEqual(Guid.Empty, typedViewModel.TheReloadGuid1Set);
            Assert.AreEqual(Guid.Empty, typedViewModel.TheReloadGuid2Set);
            Assert.AreEqual(null, typedViewModel.TheReloadString1Set);
            Assert.IsTrue(typedViewModel.StartCalled);
        }
コード例 #2
0
        public void Test_FailingDependency()
        {
            ClearAll();

            Ioc.RegisterSingleton<ITestThing>(() => new FailingMockTestThing());

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

            Assert.That(
                () => {
                    IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
                },
                Throws.TypeOf<MvxException>().With.Message.StartWith("Problem creating viewModel"));
        }
コード例 #3
0
        public void Test_FailingInitialisation()
        {
            ClearAll();

            var testThing = new MockTestThing();
            Ioc.RegisterSingleton<ITestThing>(testThing);

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

            Assert.That(
                () => {
                    IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
                },
                Throws.TypeOf<MvxException>().With.Message.StartWith("Problem running viewModel lifecycle"));
        }
コード例 #4
0
        public void Test_MissingDependency()
        {
            ClearAll();

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

            Assert.That(
                () => {
                    IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
                },
                Throws.TypeOf<MvxException>().With.Message.StartWith("Problem creating viewModel"));
        }