Esempio n. 1
0
        public void Test_WithReloadState()
        {
            _fixture.ClearAll();

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

            var testThing = new MockTestThing();

            _fixture.Ioc.RegisterSingleton <ITestThing>(testThing);

            var initBundleObject = 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 initBundle = new MvxBundle();

            initBundle.Write(initBundleObject);

            var reloadBundleObject = new BundleObject
            {
                TheBool1   = true,
                TheBool2   = true,
                TheGuid1   = Guid.NewGuid(),
                TheGuid2   = new Guid(1123, 10, 444, 1, 2, 3, 4, 5, 6, 7, 8),
                TheInt1    = 1234,
                TheInt2    = 4567,
                TheString1 = "Foo Bar",
                TheString2 = null
            };
            var reloadBundle = new MvxBundle();

            reloadBundle.Write(reloadBundleObject);

            var           toTest    = new MvxDefaultViewModelLocator();
            var           args      = new MvxNavigateEventArgs(NavigationMode.Show);
            IMvxViewModel viewModel = toTest.Load(typeof(Test1ViewModel), initBundle, reloadBundle, args);

            Assert.NotNull(viewModel);
            var typedViewModel = (Test1ViewModel)viewModel;

            Assert.Equal(initBundle, typedViewModel.BundleInit);
            Assert.Equal(reloadBundle, typedViewModel.BundleState);
            Assert.Equal(testThing, typedViewModel.Thing);
            Assert.Equal(initBundleObject, typedViewModel.TheInitBundleSet);
            Assert.Equal(reloadBundleObject, typedViewModel.TheReloadBundleSet);
            Assert.Equal(initBundleObject.TheGuid1, typedViewModel.TheInitGuid1Set);
            Assert.Equal(initBundleObject.TheGuid2, typedViewModel.TheInitGuid2Set);
            Assert.Equal(initBundleObject.TheString1, typedViewModel.TheInitString1Set);
            Assert.Equal(reloadBundleObject.TheGuid1, typedViewModel.TheReloadGuid1Set);
            Assert.Equal(reloadBundleObject.TheGuid2, typedViewModel.TheReloadGuid2Set);
            Assert.Equal(reloadBundleObject.TheString1, typedViewModel.TheReloadString1Set);
            Assert.True(typedViewModel.StartCalled);
        }
        public void Test_WithReloadState()
        {
            ClearAll();

            var testThing = new MockTestThing();

            Ioc.RegisterSingleton <ITestThing>(testThing);

            var initBundleObject = 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 initBundle = new MvxBundle();

            initBundle.Write(initBundleObject);

            var reloadBundleObject = new BundleObject
            {
                TheBool1   = true,
                TheBool2   = true,
                TheGuid1   = Guid.NewGuid(),
                TheGuid2   = new Guid(1123, 10, 444, 1, 2, 3, 4, 5, 6, 7, 8),
                TheInt1    = 1234,
                TheInt2    = 4567,
                TheString1 = "Foo Bar",
                TheString2 = null
            };
            var reloadBundle = new MvxBundle();

            reloadBundle.Write(reloadBundleObject);

            var           toTest = new MvxDefaultViewModelLocator();
            IMvxViewModel viewModel;
            var           result = toTest.TryLoad(typeof(Test1ViewModel), initBundle, reloadBundle, out viewModel);

            Assert.IsTrue(result);
            var typedViewModel = (Test1ViewModel)viewModel;

            Assert.AreSame(initBundle, typedViewModel.BundleInit);
            Assert.AreSame(reloadBundle, typedViewModel.BundleState);
            Assert.AreSame(testThing, typedViewModel.Thing);
            Assert.AreEqual(initBundleObject, typedViewModel.TheInitBundleSet);
            Assert.AreEqual(reloadBundleObject, typedViewModel.TheReloadBundleSet);
            Assert.AreEqual(initBundleObject.TheGuid1, typedViewModel.TheInitGuid1Set);
            Assert.AreEqual(initBundleObject.TheGuid2, typedViewModel.TheInitGuid2Set);
            Assert.AreEqual(initBundleObject.TheString1, typedViewModel.TheInitString1Set);
            Assert.AreEqual(reloadBundleObject.TheGuid1, typedViewModel.TheReloadGuid1Set);
            Assert.AreEqual(reloadBundleObject.TheGuid2, typedViewModel.TheReloadGuid2Set);
            Assert.AreEqual(reloadBundleObject.TheString1, typedViewModel.TheReloadString1Set);
            Assert.IsTrue(typedViewModel.StartCalled);
        }
        public void Test_MissingDependency()
        {
            ClearAll();

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

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

            Assert.Fail("We should never reach this line");
        }
        public void Test_MissingDependency()
        {
            _fixture.ClearAll();

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

            Assert.Throws <MvxException>(() => {
                IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
            });
        }
        public void Test_FailingDependency()
        {
            ClearAll();

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

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

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

            Assert.Fail("We should never reach this line");
        }
        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"));
        }
        public void Test_FailingDependency()
        {
            _fixture.ClearAll();

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

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();

            Assert.Throws <MvxException>(() => {
                IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
            });
        }
        public void Test_MissingDependency()
        {
            _fixture.ClearAll();

            var bundle = new MvxBundle();

            var navigationService = _fixture.Ioc.Resolve <IMvxNavigationService>();
            var toTest            = new MvxDefaultViewModelLocator(navigationService);
            var args = new MvxNavigateEventArgs(NavigationMode.Show);

            Assert.Throws <MvxException>(() =>
            {
                IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null, args);
            });
        }
        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"));
        }
Esempio n. 10
0
        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);

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

            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);
        }
Esempio n. 11
0
        public void Test_FailingInitialisation()
        {
            _fixture.ClearAll();

            var testThing = new MockTestThing();

            _fixture.Ioc.RegisterSingleton <ITestThing>(testThing);

            var bundle = new MvxBundle();

            var navigationService = _fixture.Ioc.Resolve <IMvxNavigationService>();
            var toTest            = new MvxDefaultViewModelLocator(navigationService);

            Assert.Throws <MvxException>(() => {
                IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
            });
        }
Esempio n. 12
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"));
        }
Esempio n. 13
0
        public void Test_FailingInitialisation()
        {
            _fixture.ClearAll();

            var testThing = new MockTestThing();

            _fixture.Ioc.RegisterSingleton <ITestThing>(testThing);

            var bundle = new MvxBundle();

            var toTest = new MvxDefaultViewModelLocator();
            var args   = new MvxNavigateEventArgs(NavigationMode.Show);

            Assert.Throws <MvxException>(() =>
            {
                IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null, args);
            });
        }