public void ViewLocatorBaseTest()
        {
            IViewLocator locator = new TestViewLocator2();
            Button       button1 = (Button)locator.ResolveView("Button");
            Button       button2 = (Button)locator.ResolveView("Button");

            Assert.IsNotNull(button1);
            Assert.IsNotNull(button2);
            Assert.AreNotEqual(button1, button2);

            DataController dc1 = (DataController)locator.ResolveView("DataController");
            DataController dc2 = (DataController)locator.ResolveView("DataController");

            Assert.IsNotNull(dc1);
            Assert.IsNotNull(dc2);
            Assert.AreNotEqual(dc1, dc2);

            locator = new ViewLocator(typeof(DataController).Assembly, typeof(Button).Assembly);
            button1 = (Button)locator.ResolveView("Button");
            button2 = (Button)locator.ResolveView("Button");
            Assert.IsNotNull(button1);
            Assert.IsNotNull(button2);
            Assert.AreNotEqual(button1, button2);

            dc1 = (DataController)locator.ResolveView("DataController");
            dc2 = (DataController)locator.ResolveView("DataController");
            Assert.IsNotNull(dc1);
            Assert.IsNotNull(dc2);
            Assert.AreNotEqual(dc1, dc2);
        }
示例#2
0
            public void RegistersNonExistingViewType()
            {
                var viewLocator = new ViewLocator();

                Assert.IsNull(viewLocator.ResolveView(typeof(FollowingNoNamingConventionView)));

                viewLocator.Register(typeof(FollowingNoNamingConventionView), typeof(NoNamingConventionViewModel));

                var resolvedView = viewLocator.ResolveView(typeof(FollowingNoNamingConventionView));

                Assert.AreEqual(typeof(NoNamingConventionViewModel), resolvedView);
            }
示例#3
0
            public void ResolvesViewFromCache()
            {
                var viewLocator  = new ViewLocator();
                var resolvedType = viewLocator.ResolveView(typeof(PersonViewModel));

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(typeof(PersonView), resolvedType);

                // Clear the naming conventions (so it *must* come from the cache)
                viewLocator.NamingConventions.Clear();

                resolvedType = viewLocator.ResolveView(typeof(PersonViewModel));

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(typeof(PersonView), resolvedType);
            }
示例#4
0
            public void ReturnsViewForViewEndingWithViewModel()
            {
                var viewLocator  = new ViewLocator();
                var resolvedType = viewLocator.ResolveView(typeof(PersonViewModel));

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(typeof(PersonView), resolvedType);
            }
示例#5
0
            public void ReturnsViewForNamingConventionWithUp()
            {
                var viewLocator = new ViewLocator();

                viewLocator.NamingConventions.Clear();
                viewLocator.NamingConventions.Add("[UP].Views.[VM]View");

                var resolvedType = viewLocator.ResolveView(typeof(PersonViewModel));

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(typeof(PersonView), resolvedType);
            }
示例#6
0
        private IViewFor LocateView(IViewModel viewModel, string contract)
        {
            var view = ViewLocator.ResolveView(viewModel, contract);

            if (view is null)
            {
                throw new InvalidOperationException(
                          $"No view could be located for type '{viewModel.GetType().FullName}', " +
                          $"contract '{contract}'. Be sure Splat has an appropriate registration.");
            }

            view.ViewModel = viewModel;
            return(view);
        }
示例#7
0
            public void ReturnsViewForViewModel(Type viewModelType, Type viewType, string convention)
            {
                var viewLocator = new ViewLocator();

                if (!string.IsNullOrEmpty(convention))
                {
                    viewLocator.NamingConventions.Clear();
                    viewLocator.NamingConventions.Add(convention);
                }

                var resolvedType = viewLocator.ResolveView(viewModelType);

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(viewType, resolvedType);
            }
示例#8
0
            public void ThrowsArgumentNullExceptionForNullViewType()
            {
                var viewLocator = new ViewLocator();

                ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => viewLocator.ResolveView(null));
            }