public void AnErrorIsRaisedIfTheCreationOfTheViewFails()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooThatThrowsView(), typeof(IViewFor <IFooViewModel>));

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                var vm      = new FooViewModel();

                var ex = Assert.Throws <InvalidOperationException>(() => fixture.ResolveView(vm));
                Assert.Equal("This is a test failure.", ex.Message);
            }
        }
        public void NoErrorIsRaisedIfATypeCannotBeFound()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                fixture.ViewModelToViewFunc = viewModelName => "DoesNotExist";
                var vm = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.Null(result);
            }
        }
        public void TheRuntimeTypeOfTheViewModelIsUsedToResolveTheView()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooView(), typeof(FooView));

            using (resolver.WithResolver())
            {
                var    fixture = new DefaultViewLocator();
                object vm      = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.IsType <FooView>(result);
            }
        }
Exemplo n.º 4
0
        public void ViewModelToViewNamingConventionCanBeCustomized()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooWithWeirdConvention(), typeof(FooWithWeirdConvention));

            using (resolver.WithResolver()) {
                var fixture = new DefaultViewLocator();
                fixture.ViewModelToViewFunc = viewModelName => viewModelName.Replace("ViewModel", "WithWeirdConvention");
                FooViewModel vm = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.IsType <FooWithWeirdConvention>(result);
            }
        }
        public void ByDefaultViewModelIsReplacedWithViewWhenDeterminingTheServiceName()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooView(), typeof(IViewFor <FooViewModel>));

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                var vm      = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.IsType <FooView>(result);
            }
        }
        public void CanResolveViewFromViewModelClassUsingInterfaceRegistration()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooView(), typeof(IFooView));

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                var vm      = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.IsType <FooView>(result);
            }
        }
Exemplo n.º 7
0
        public void ResolveExplicitViewType()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new BazView(), typeof(IBazView));

            using (resolver.WithResolver()) {
                var fixture = new DefaultViewLocator();
                var vm      = new BazViewModel(null);

                var result = fixture.ResolveView(vm);
                this.Log().Info(result.GetType().FullName);
                Assert.True(result is BazView);
            }
        }
Exemplo n.º 8
0
        public void ResolveByConcreteViewFor()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new QuxView(), typeof(IViewFor <QuxViewModel>));

            using (resolver.WithResolver()) {
                var fixture = new DefaultViewLocator();
                var vm      = new QuxViewModel(null);

                var result = fixture.ResolveView(vm);
                this.Log().Info(result.GetType().FullName);
                Assert.IsType <QuxView>(result);
            }
        }
        public void CanResolveViewFromViewModelWithIRoutableViewModelType()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new RoutableFooView(), typeof(IViewFor <IRoutableFooViewModel>));

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                var vm      = new RoutableFooViewModel();

                var result = fixture.ResolveView <IRoutableViewModel>(vm);
                Assert.IsType <RoutableFooView>(result);
            }
        }
        public void NoErrorIsRaisedIfTheServiceDoesNotImplementIViewFor()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => "this string does not implement IViewFor", typeof(IViewFor <IFooViewModel>));

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                var vm      = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.Null(result);
            }
        }
Exemplo n.º 11
0
        public void CanOverrideNameResolutionFunc()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new RoutableFooCustomView());

            using (resolver.WithResolver())
            {
                var fixture = new DefaultViewLocator();
                fixture.ViewModelToViewFunc = x => x.Replace("ViewModel", "CustomView");
                var vm = new RoutableFooViewModel();

                var result = fixture.ResolveView <IRoutableViewModel>(vm);
                Assert.IsType <RoutableFooCustomView>(result);
            }
        }
Exemplo n.º 12
0
        public void Should_call_locateview_with_view_name_on_view_source_provider()
        {
            // Given
            const string viewname = "view name";

            var viewSourceProviders = new[] {
                A.Fake <IViewSourceProvider>()
            };

            A.CallTo(() => viewSourceProviders[0].LocateView(viewname, Enumerable.Empty <string>())).Returns(null);

            var locator = new DefaultViewLocator(viewSourceProviders);

            // When
            locator.GetViewLocation(viewname, new[] { "html" });

            // Then
            A.CallTo(() => viewSourceProviders[0].LocateView(viewname, A <IEnumerable <string> > .Ignored)).MustHaveHappened();
        }
        private ViewEngineStartupContext CreateContext(params ViewLocationResult[] results)
        {
            var viewLocationProvider = A.Fake <IViewLocationProvider>();

            A.CallTo(() => viewLocationProvider.GetLocatedViews(A <IEnumerable <string> > ._))
            .Returns(results);

            var viewEngine = A.Fake <IViewEngine>();

            A.CallTo(() => viewEngine.Extensions).Returns(new[] { "liquid" });

            var viewLocator = new DefaultViewLocator(viewLocationProvider, new[] { viewEngine });

            var startupContext = new ViewEngineStartupContext(
                this.cache,
                viewLocator);

            return(startupContext);
        }
Exemplo n.º 14
0
        public void Should_call_locateview_with_supported_view_engine_extensions_on_view_source_provider()
        {
            // Given
            const string viewname = "view name";

            var expectedViewEngineExtensions = new[] { "html" };

            var viewSourceProviders = new[] {
                A.Fake <IViewSourceProvider>()
            };

            A.CallTo(() => viewSourceProviders[0].LocateView(A <string> .Ignored, Enumerable.Empty <string>())).Returns(null);

            var locator = new DefaultViewLocator(viewSourceProviders);

            // When
            locator.GetViewLocation(viewname, new[] { "html" });

            // Then)
            A.CallTo(() => viewSourceProviders[0].LocateView(A <string> .Ignored,
                                                             A <IEnumerable <string> > .That.IsSameSequenceAs(expectedViewEngineExtensions))).MustHaveHappened();
        }
Exemplo n.º 15
0
        public void ContractIsUsedWhenResolvingView()
        {
            var resolver = new ModernDependencyResolver();

            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            resolver.Register(() => new FooView(), typeof(IViewFor <IFooViewModel>), "first");
            resolver.Register(() => new FooWithWeirdConvention(), typeof(IViewFor <IFooViewModel>), "second");

            using (resolver.WithResolver()) {
                var fixture = new DefaultViewLocator();
                var vm      = new FooViewModel();

                var result = fixture.ResolveView(vm);
                Assert.Null(result);

                result = fixture.ResolveView(vm, "first");
                Assert.True(result is FooView);

                result = fixture.ResolveView(vm, "second");
                Assert.True(result is FooWithWeirdConvention);
            }
        }
Exemplo n.º 16
0
        protected virtual void SetupRx(IMutableDependencyResolver dependencyResolver)
        {
            var viewLocator = new DefaultViewLocator();

            dependencyResolver.Register(() => viewLocator, typeof(IViewLocator));
        }
Exemplo n.º 17
0
 public DefaultViewLocatorFixture()
 {
     this.viewLocation      = new ViewLocationResult("location", "view", "html", null);
     this.viewLocationCache = new FakeViewLocationCache(this.viewLocation);
     this.viewLocator       = CreateViewLocator(this.viewLocationCache);
 }
        private LiquidNancyFileSystem CreateFileSystem(out Context context, params ViewLocationResult[] viewLocationResults)
        {
            var viewLocationProvider = A.Fake<IViewLocationProvider>();
            A.CallTo(() => viewLocationProvider.GetLocatedViews(A<IEnumerable<string>>._))
                                               .Returns(viewLocationResults);

            var viewEngine = A.Fake<IViewEngine>();
            A.CallTo(() => viewEngine.Extensions).Returns(new[] { "liquid" });

            var viewLocator = new DefaultViewLocator(viewLocationProvider, new[] { viewEngine });

            var startupContext = new ViewEngineStartupContext(
                null,
                viewLocator);

            var renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x => viewLocator.LocateView(x.Arguments.Get<string>(0), null));

            context = new Context(new List<Hash>(), new Hash(),
                Hash.FromAnonymousObject(new { nancy = renderContext }), false);

            return new LiquidNancyFileSystem(startupContext, new[] { "liquid" });
        }
Exemplo n.º 19
0
        private ViewEngineStartupContext CreateContext(params ViewLocationResult[] results)
        {
            var viewLocationProvider = A.Fake<IViewLocationProvider>();
            A.CallTo(() => viewLocationProvider.GetLocatedViews(A<IEnumerable<string>>._))
                                               .Returns(results);

            var viewEngine = A.Fake<IViewEngine>();
            A.CallTo(() => viewEngine.Extensions).Returns(new[] { "liquid" });

            var viewLocator = new DefaultViewLocator(viewLocationProvider, new[] { viewEngine });

            var startupContext = new ViewEngineStartupContext(
                this.cache,
                viewLocator);

            return startupContext;
        }
Exemplo n.º 20
0
 public DefaultViewLocatorFixture()
 {
     this.environment = new DefaultNancyEnvironment();
     this.environment.AddValue(ViewConfiguration.Default);
     this.viewLocator = this.CreateViewLocator();
 }