示例#1
1
            public void ReturnsViewForViewEndingWithViewModel()
            {
                var viewLocator = new ViewLocator();
                var resolvedType = viewLocator.ResolveView(typeof(PersonViewModel));

                Assert.IsNotNull(resolvedType);
                Assert.AreEqual(typeof(PersonView), resolvedType);
            }
示例#2
0
            public void OverwritesExistingViewType()
            {
                var viewLocator = new ViewLocator();
                viewLocator.Register(typeof(FollowingNoNamingConventionView), typeof(NoNamingConventionViewModel));
                viewLocator.Register(typeof(FollowingNoNamingConventionView), typeof(NoNamingConventionViewModel2));

                var resolvedView = viewLocator.ResolveView(typeof(FollowingNoNamingConventionView));
                Assert.AreEqual(typeof(NoNamingConventionViewModel2), resolvedView);
            }
示例#3
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);
            }
示例#4
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);
            }
示例#5
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);
            }
示例#6
0
 public void ThrowsArgumentNullExceptionForNullViewType()
 {
     var viewLocator = new ViewLocator();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => viewLocator.ResolveView(null));
 }
示例#7
0
 public void ThrowsArgumentNullExceptionForNullResolvedType()
 {
     var viewLocator = new ViewLocator();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => viewLocator.Register(typeof(NoNamingConventionViewModel), null));
 }
示例#8
0
 public void ThrowsArgumentNullExceptionForNullTypeToResolve()
 {
     var viewLocator = new ViewLocator();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => viewLocator.Register(null, typeof(FollowingNoNamingConventionView)));
 }
示例#9
0
            public void ThrowsArgumentExceptionForWrongServiceType()
            {
                var serviceLocator = new ServiceLocator();
                var serviceType = typeof(IViewModelLocator);
                var serviceInstance = new ViewLocator();

                ExceptionTester.CallMethodAndExpectException<ArgumentException>(() => serviceLocator.RegisterInstance(serviceType, serviceInstance));
            }