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();
        }
        public void Should_return_view_location_result_from_source_provider_when_view_could_be_found()
        {
            // Given
            var viewSourceProvider = A.Fake<IViewSourceProvider>();
            var viewLocationResult = new ViewLocationResult(null, string.Empty, null);
            var locator = new DefaultViewLocator(new[] { viewSourceProvider });

            A.CallTo(() => viewSourceProvider.LocateView(A<string>.Ignored, A<IEnumerable<string>>.Ignored)).Returns(viewLocationResult);

            // When
            var result = locator.GetViewLocation("view name", new[] { "html" });

            // Then
            result.ShouldBeSameAs(viewLocationResult);
        }
        public void Should_suppress_exceptions_thrown_by_view_source_provider()
        {
            // Given
            var viewSourceProvider = A.Fake<IViewSourceProvider>();
            A.CallTo(() => viewSourceProvider.LocateView(A<string>.Ignored, A<IEnumerable<string>>.Ignored)).Throws(new Exception());

            var locator = new DefaultViewLocator(new[] { viewSourceProvider });

            // When
            var result = locator.GetViewLocation("view name", new[] { "html" });

            // Then
            result.ShouldBeNull();
        }
        public void Should_return_null_when_getting_view_location_with_null_supported_view_engine_extensions()
        {
            // Given
            var locator = new DefaultViewLocator(new[] { A.Fake<IViewSourceProvider>() });

            // When
            var result = locator.GetViewLocation("viewName", null);

            // Then
            result.ShouldBeNull();
        }
        public void Should_return_null_when_getting_view_location_with_null_view_null()
        {
            // Given
            var locator = new DefaultViewLocator(new[] { A.Fake<IViewSourceProvider>() });

            // When
            var result = locator.GetViewLocation(null, Enumerable.Empty<string>());

            // Then
            result.ShouldBeNull();
        }
        public void Should_return_null_when_getting_view_location_with_no_view_source_provider()
        {
            // Given
            var locator = new DefaultViewLocator(new IViewSourceProvider[] { });

            // When
            var result = locator.GetViewLocation("viewName", Enumerable.Empty<string>());

            // Then
            result.ShouldBeNull();
        }
        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 static DefaultViewLocator CreateViewLocator(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 });

            return viewLocator;
        }
 public DefaultViewLocatorFixture()
 {
     this.viewLocation = new ViewLocationResult("location", "view", "html", null);
     this.viewLocator = CreateViewLocator();
 }
 public DefaultViewLocatorFixture()
 {
     this.environment = new DefaultNancyEnvironment();
     this.environment.AddValue(ViewConfiguration.Default);
     this.viewLocator = this.CreateViewLocator();
 }