Example #1
0
        public void Should_ignore_case_when_locating_view_based_on_name_extension_and_location(string viewName)
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", "cshtml", () => null);
            var cache        = new FakeViewLocationCache(expectedView);
            var locator      = CreateViewLocator(cache);

            // When
            var result = locator.LocateView(viewName);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_ignore_case_when_locating_view_based_on_name(string viewName)
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache        = new FakeViewLocationCache(expectedView);
            var locator      = CreateViewLocator(cache);

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

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_be_able_to_locate_view_by_name_when_the_viewname_occures_in_the_location()
        {
            // Given
            var expectedView = new ViewLocationResult("views/hello", "hello", "cshtml", () => null);
            //var additionalView = new ViewLocationResult( "views", "index", "spark", () => null );
            var cache   = new FakeViewLocationCache(expectedView);
            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/hello/hello", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_throw_ambiguousviewsexception_when_locating_view_by_name_and_multiple_views_share_the_same_name_and_location_but_different_extensions()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", "spark", () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", "html", () => null);
            var cache         = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator       = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.ShouldBeOfType <AmbiguousViewsException>();
        }
        public void Should_be_able_to_locate_view_by_name_when_two_views_with_same_name_and_extension_exists_at_different_locations()
        {
            // Given
            var expectedView   = new ViewLocationResult("views/sub", "index", "cshtml", () => null);
            var additionalView = new ViewLocationResult("views", "index", "spark", () => null);
            var cache          = new FakeViewLocationCache(expectedView, additionalView);
            var locator        = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/sub/index.cshtml", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_locate_view_when_name_extension_and_location_are_provided()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", "cshtml", () => null);
            var cache        = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/sub/index.cshtml", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_return_null_when_view_cannot_be_located_using_name_extension_and_location()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", "spark", () => null);
            var cache        = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/feature/index.cshtml", null);

            // Then
            result.ShouldBeNull();
        }
        public void Should_throw_ambiguousviewsexception_when_locating_view_by_name_returns_multiple_results()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache         = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator       = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.ShouldBeOfType <AmbiguousViewsException>();
        }
        public void Should_return_null_when_view_cannot_be_located_using_name()
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache        = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("main", null);

            // Then
            result.ShouldBeNull();
        }
        public void Should_be_able_to_locate_view_by_name_when_two_views_with_same_name_exists_at_different_locations()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", string.Empty, () => null);
            var additionalView = new ViewLocationResult("views", "index", string.Empty, () => null);
            var cache = new FakeViewLocationCache(expectedView, additionalView);
            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/sub/index", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_be_able_to_locate_view_by_name_and_extension_when_two_view_with_same_name_but_different_extensions_exists_in_the_same_location()
        {
            // Given
            var expectedView = new ViewLocationResult("views", "index", "cshtml", () => null);
            var additionalView = new ViewLocationResult("views", "index", "spark", () => null);
            var cache = new FakeViewLocationCache(expectedView, additionalView);
            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/index.cshtml", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
Example #12
0
        public void Should_locate_view_when_only_name_is_provided()
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache        = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("index", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_throw_ambiguousviewsexception_when_more_than_one_located_view_matches_view_name()
        {
            // Given
            var cache = new FakeViewLocationCache(
                new ViewLocationResult("location", "view", "html", null),
                new ViewLocationResult("location", "view", "html", null));

            var locator = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("view.html"));

            // Then
            exception.ShouldBeOfType <AmbiguousViewsException>();
        }
Example #14
0
        public void Should_set_message_on_ambiguousviewexception()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", "spark", () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", "html", () => null);
            var cache         = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator       = CreateViewLocator(cache);

            const string expectedMessage = "This exception was thrown because multiple views were found. 2 view(s):\r\n\t/index.spark\r\n\t/index.html";

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.Message.ShouldEqual(expectedMessage);
        }
        private LiquidNancyFileSystem CreateFileSystem(out Context context, params ViewLocationResult[] viewLocationResults)
        {
            var startupContext = new ViewEngineStartupContext(
                null,
                viewLocationResults,
                new[] { "liquid" });

            var cache   = new FakeViewLocationCache(viewLocationResults);
            var locator = CreateViewLocator(cache);

            var renderContext = A.Fake <IRenderContext>();

            A.CallTo(() => renderContext.LocateView(A <string> .Ignored, A <object> .Ignored))
            .ReturnsLazily(x => locator.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));
        }
        public void Should_throw_ambiguousviewsexception_when_locating_view_by_name_and_multiple_views_share_the_same_name_and_location_but_different_extensions()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", "spark", () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", "html", () => null);
            var cache = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.ShouldBeOfType<AmbiguousViewsException>();
        }
        public void Should_locate_view_when_only_name_is_provided()
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("index", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_throw_ambiguousviewsexception_when_more_than_one_located_view_matches_view_name()
        {
            // Given
            var cache = new FakeViewLocationCache(
                new ViewLocationResult("location", "view", "html", null),
                new ViewLocationResult("location", "view", "html", null));

            var locator = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("view.html"));

            // Then
            exception.ShouldBeOfType<AmbiguousViewsException>();
        }
        public void Should_ignore_case_when_locating_view_based_on_name(string viewName)
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache = new FakeViewLocationCache(expectedView);
            var locator = CreateViewLocator(cache);

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

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_throw_ambiguousviewsexception_when_locating_view_by_name_returns_multiple_results()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator = CreateViewLocator(cache);

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.ShouldBeOfType<AmbiguousViewsException>();
        }
        public void Should_return_null_when_view_cannot_be_located_using_name()
        {
            // Given
            var expectedView = new ViewLocationResult(string.Empty, "index", string.Empty, () => null);
            var cache = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("main", null);

            // Then
            result.ShouldBeNull();
        }
        public void Should_return_null_when_view_cannot_be_located_using_name_extension_and_location()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", "spark", () => null);
            var cache = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/feature/index.cshtml", null);

            // Then
            result.ShouldBeNull();
        }
        public void Should_locate_view_when_name_extension_and_location_are_provided()
        {
            // Given
            var expectedView = new ViewLocationResult("views/sub", "index", "cshtml", () => null);
            var cache = new FakeViewLocationCache(expectedView);

            var locator = CreateViewLocator(cache);

            // When
            var result = locator.LocateView("views/sub/index.cshtml", null);

            // Then
            result.ShouldBeSameAs(expectedView);
        }
        public void Should_set_message_on_ambiguousviewexception()
        {
            // Given
            var expectedView1 = new ViewLocationResult(string.Empty, "index", "spark", () => null);
            var expectedView2 = new ViewLocationResult(string.Empty, "index", "html", () => null);
            var cache = new FakeViewLocationCache(expectedView1, expectedView2);
            var locator = CreateViewLocator(cache);

            const string expectedMessage = "This exception was thrown because multiple views were found. 2 view(s):\r\n\t/index.spark\r\n\t/index.html";

            // When
            var exception = Record.Exception(() => locator.LocateView("index", null));

            // Then
            exception.Message.ShouldEqual(expectedMessage);
        }