/// <inheritdoc/>
 public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
 {
     if (viewPath == null)
     {
         throw new ArgumentNullException(nameof(viewPath));
     }
     if (!_views.TryGetValue(viewPath, out var value))
     {
         return(ViewEngineResult.NotFound(viewPath, new[] { "EightyCompiledViews/" + viewPath }));
     }
     return(ViewEngineResult.Found(viewPath, value(_serviceProvider)));
 }
 public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
 {
     if (viewName == "CustomView")
     {
         return(ViewEngineResult.Found(viewName, new CustomView()));
     }
     else
     {
         return(ViewEngineResult.NotFound(viewName,
                                          new string[] { "(Debug View Engine - FindView)" }));
     }
 }
Esempio n. 3
0
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            var applicationRelativePath = GetAbsolutePath(executingFilePath, viewPath);

            if (!(IsApplicationRelativePath(viewPath) || IsRelativePath(viewPath)))
            {
                // Not a path this method can handle.
                return(ViewEngineResult.NotFound(applicationRelativePath, Enumerable.Empty <string>()));
            }

            return(ViewEngineResult.Found("Default", new FluidView(applicationRelativePath, _fluidRendering)));
        }
Esempio n. 4
0
        public void Editor_AppliesNonDefaultEditFormat(string dataTypeName, Html5DateRenderingMode renderingMode)
        {
            // Arrange
            // Mono issue - https://github.com/aspnet/External/issues/19
            var expectedInput = PlatformNormalizer.NormalizeContent(
                "<input class=\"HtmlEncode[[text-box single-line]]\" data-val=\"HtmlEncode[[true]]\" " +
                "data-val-required=\"HtmlEncode[[The DateTimeOffset field is required.]]\" id=\"HtmlEncode[[FieldPrefix]]\" " +
                "name=\"HtmlEncode[[FieldPrefix]]\" type=\"HtmlEncode[[" +
                dataTypeName +
                "]]\" value=\"HtmlEncode[[Formatted as 2000-01-02T03:04:05.0600000+00:00]]\" />");

            var offset = TimeSpan.FromHours(0);
            var model  = new DateTimeOffset(
                year: 2000,
                month: 1,
                day: 2,
                hour: 3,
                minute: 4,
                second: 5,
                millisecond: 60,
                offset: offset);
            var viewEngine = new Mock <ICompositeViewEngine>();

            viewEngine
            .Setup(v => v.FindPartialView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound("", Enumerable.Empty <string>()));


            var provider = new TestModelMetadataProvider();

            provider.ForType <DateTimeOffset>().DisplayDetails(dd =>
            {
                dd.DataTypeName            = dataTypeName;
                dd.EditFormatString        = "Formatted as {0:O}"; // What [DataType] does for given type.
                dd.HasNonDefaultEditFormat = true;
            });

            var helper = DefaultTemplatesUtilities.GetHtmlHelper(
                model,
                null,
                viewEngine.Object,
                provider);

            helper.Html5DateRenderingMode = renderingMode; // Ignored due to HasNonDefaultEditFormat.
            helper.ViewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";

            // Act
            var result = helper.Editor("");

            // Assert
            Assert.Equal(expectedInput, result.ToString());
        }
Esempio n. 5
0
        public async Task ProcessAsync_IfHasFallback_Throws_When_MainPartialAndFallback_AreNotFound()
        {
            // Arrange
            var bufferScope  = new TestViewBufferScope();
            var partialName  = "_Partial";
            var fallbackName = "_Fallback";
            var expected     = string.Join(
                Environment.NewLine,
                $"The partial view '{partialName}' was not found. The following locations were searched:",
                "PartialNotFound1",
                "PartialNotFound2",
                "PartialNotFound3",
                "PartialNotFound4",
                $"The fallback partial view '{fallbackName}' was not found. The following locations were searched:",
                "FallbackNotFound1",
                "FallbackNotFound2",
                "FallbackNotFound3",
                "FallbackNotFound4");
            var viewData    = new ViewDataDictionary(new TestModelMetadataProvider(), new ModelStateDictionary());
            var viewContext = GetViewContext();

            var view       = Mock.Of <IView>();
            var viewEngine = new Mock <ICompositeViewEngine>();

            viewEngine.Setup(v => v.GetView(It.IsAny <string>(), partialName, false))
            .Returns(ViewEngineResult.NotFound(partialName, new[] { "PartialNotFound1", "PartialNotFound2" }));

            viewEngine.Setup(v => v.FindView(viewContext, partialName, false))
            .Returns(ViewEngineResult.NotFound(partialName, new[] { $"PartialNotFound3", $"PartialNotFound4" }));

            viewEngine.Setup(v => v.GetView(It.IsAny <string>(), fallbackName, false))
            .Returns(ViewEngineResult.NotFound(partialName, new[] { "FallbackNotFound1", "FallbackNotFound2" }));

            viewEngine.Setup(v => v.FindView(viewContext, fallbackName, false))
            .Returns(ViewEngineResult.NotFound(partialName, new[] { $"FallbackNotFound3", $"FallbackNotFound4" }));

            var tagHelper = new PartialTagHelper(viewEngine.Object, bufferScope)
            {
                Name         = partialName,
                ViewContext  = viewContext,
                ViewData     = viewData,
                FallbackName = fallbackName
            };
            var tagHelperContext = GetTagHelperContext();
            var output           = GetTagHelperOutput();

            // Act & Assert
            var exception = await Assert.ThrowsAsync <InvalidOperationException>(
                () => tagHelper.ProcessAsync(tagHelperContext, output));

            Assert.Equal(expected, exception.Message);
        }
Esempio n. 6
0
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            var applicationRelativePath = PathHelper.GetAbsolutePath(executingFilePath, viewPath);

            if (!PathHelper.IsAbsolutePath(viewPath))
            {
                // Not a path this method can handle.
                return(ViewEngineResult.NotFound(applicationRelativePath, Enumerable.Empty <string>()));
            }

            // ReSharper disable once Mvc.ViewNotResolved
            return(ViewEngineResult.Found("Default", new PugzorView(applicationRelativePath, _pugRendering)));
        }
Esempio n. 7
0
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            var applicationRelativePath = GetAbsolutePath(executingFilePath, viewPath);

            if (File.Exists(applicationRelativePath))
            {
                return(ViewEngineResult.Found(viewPath, new FileSystemRazorView(applicationRelativePath, razorEngine)));
            }
            else
            {
                return(ViewEngineResult.NotFound(viewPath, new string[] { executingFilePath }));
            }
        }
Esempio n. 8
0
        private ViewEngineResult CreateViewEngineResult(RazorPageResult result,
                                                        IRazorViewFactory razorViewFactory,
                                                        bool isPartial)
        {
            if (result.SearchedLocations != null)
            {
                return(ViewEngineResult.NotFound(result.Name, result.SearchedLocations));
            }

            var view = razorViewFactory.GetView(this, result.Page, isPartial);

            return(ViewEngineResult.Found(result.Name, view));
        }
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            var applicationRelativePath = PathHelper.GetAbsolutePath(executingFilePath, viewPath);

            if (!PathHelper.IsAbsolutePath(viewPath))
            {
                // Not a path this method can handle.
                return(ViewEngineResult.NotFound(applicationRelativePath, Enumerable.Empty <string>()));
            }

            var layoutPath = _options.DefaultLayout;

            return(ViewEngineResult.Found("Default", new HandlebarsView(layoutPath, applicationRelativePath)));
        }
Esempio n. 10
0
        ///
        /// Attempts to find the  associated with .
        ///
        /// The  associated with the current request.
        /// The .
        /// A .
        ViewEngineResult FindView(ActionContext actionContext, ViewResult viewResult)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            if (viewResult == null)
            {
                throw new ArgumentNullException(nameof(viewResult));
            }

            var viewEngine = viewResult.ViewEngine ?? ViewEngine;

            var viewName = viewResult.ViewName ?? GetActionName(actionContext);

            var result         = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
            var originalResult = result;

            if (!result.Success)
            {
                result = viewEngine.FindView(actionContext, viewName, isMainPage: true);
            }

            if (!result.Success)
            {
                if (originalResult.SearchedLocations.Any())
                {
                    if (result.SearchedLocations.Any())
                    {
                        // Return a new ViewEngineResult listing all searched locations.
                        var locations = new List <string>(originalResult.SearchedLocations);
                        locations.AddRange(result.SearchedLocations);
                        result = ViewEngineResult.NotFound(viewName, locations);
                    }
                    else
                    {
                        // GetView() searched locations but FindView() did not. Use first ViewEngineResult.
                        result = originalResult;
                    }
                }
            }

            if (!result.Success)
            {
                throw new InvalidOperationException(string.Format("Couldn't find view '{0}'", viewName));
            }

            return(result);
        }
Esempio n. 11
0
    public ViewEngineResult GetView(string?executingFilePath, string viewPath, bool isMainPage)
    {
        if (string.IsNullOrEmpty(viewPath))
        {
            throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(viewPath));
        }

        if (ViewEngines.Count == 0)
        {
            throw new InvalidOperationException(Resources.FormatViewEnginesAreRequired(
                                                    typeof(MvcViewOptions).FullName,
                                                    nameof(MvcViewOptions.ViewEngines),
                                                    typeof(IViewEngine).FullName));
        }

        // Do not allocate in the common cases: ViewEngines contains one entry or initial attempt is successful.
        IEnumerable <string>?searchedLocations = null;
        List <string>?       searchedList      = null;

        for (var i = 0; i < ViewEngines.Count; i++)
        {
            var result = ViewEngines[i].GetView(executingFilePath, viewPath, isMainPage);
            if (result.Success)
            {
                return(result);
            }

            if (searchedLocations == null)
            {
                // First failure.
                searchedLocations = result.SearchedLocations;
            }
            else
            {
                if (searchedList == null)
                {
                    // Second failure.
                    searchedList      = new List <string>(searchedLocations);
                    searchedLocations = searchedList;
                }

                if (result.SearchedLocations is not null)
                {
                    searchedList.AddRange(result.SearchedLocations);
                }
            }
        }

        return(ViewEngineResult.NotFound(viewPath, searchedLocations ?? Enumerable.Empty <string>()));
    }
Esempio n. 12
0
        public async Task ExecuteResultAsync_FindsAndExecutesView()
        {
            // Arrange
            var viewName      = "MyView";
            var actionContext = GetActionContext();

            var view = new Mock <IView>(MockBehavior.Strict);

            view
            .Setup(v => v.RenderAsync(It.IsAny <ViewContext>()))
            .Returns(Task.FromResult(0))
            .Verifiable();

            view
            .As <IDisposable>()
            .Setup(v => v.Dispose())
            .Verifiable();

            // Used by logging
            view
            .SetupGet(v => v.Path)
            .Returns($"{viewName}.cshtml");

            var viewEngine = new Mock <IViewEngine>(MockBehavior.Strict);

            viewEngine
            .Setup(v => v.GetView(/*executingFilePath*/ null, viewName, /*isMainPage*/ false))
            .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty <string>()))
            .Verifiable();

            viewEngine
            .Setup(v => v.FindView(It.IsAny <ActionContext>(), viewName, /*isMainPage*/ false))
            .Returns(ViewEngineResult.Found(viewName, view.Object))
            .Verifiable();

            var viewResult = new PartialViewResult
            {
                ViewName   = viewName,
                ViewEngine = viewEngine.Object,
                ViewData   = new ViewDataDictionary(new EmptyModelMetadataProvider()),
                TempData   = Mock.Of <ITempDataDictionary>(),
            };

            // Act
            await viewResult.ExecuteResultAsync(actionContext);

            // Assert
            view.Verify();
            viewEngine.Verify();
        }
Esempio n. 13
0
 public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
 {
     if (context.HttpContext.Items["Views"] is Dictionary <string, int> views)
     {
         if (!views.ContainsKey(viewName))
         {
             views.Add(viewName, 0);
         }
         views[viewName]++;
     }
     return(ViewEngineResult.NotFound(viewName, new List <string> {
         "too long, did not search"
     }));
 }
        public void Editor_AppliesRfc3339(string dataTypeName, string editFormatString, string expected)
        {
            // Arrange
            var expectedInput =
                "<input class=\"HtmlEncode[[text-box single-line]]\" data-val=\"HtmlEncode[[true]]\" " +
                "data-val-required=\"HtmlEncode[[The DateTimeOffset field is required.]]\" id=\"HtmlEncode[[FieldPrefix]]\" " +
                "name=\"HtmlEncode[[FieldPrefix]]\" type=\"HtmlEncode[[" +
                dataTypeName +
                "]]\" value=\"HtmlEncode[[" + expected + "]]\" />";

            // Place DateTime-local value in current timezone.
            var offset = string.Equals("", dataTypeName) ? DateTimeOffset.Now.Offset : TimeSpan.FromHours(0);
            var model  = new DateTimeOffset(
                year: 2000,
                month: 1,
                day: 2,
                hour: 3,
                minute: 4,
                second: 5,
                millisecond: 60,
                offset: offset);
            var viewEngine = new Mock <ICompositeViewEngine>();

            viewEngine
            .Setup(v => v.FindPartialView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound("", Enumerable.Empty <string>()));

            var provider = new TestModelMetadataProvider();

            provider.ForType <DateTimeOffset>().DisplayDetails(dd =>
            {
                dd.DataTypeName     = dataTypeName;
                dd.EditFormatString = editFormatString; // What [DataType] does for given type.
            });

            var helper = DefaultTemplatesUtilities.GetHtmlHelper(
                model,
                null,
                viewEngine.Object,
                provider);

            helper.Html5DateRenderingMode = Html5DateRenderingMode.Rfc3339;
            helper.ViewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";

            // Act
            var result = helper.Editor("");

            // Assert
            Assert.Equal(expectedInput, result.ToString());
        }
        public async Task Render_throws_exception_when_email_view_not_found()
        {
            var viewEngine = new Mock <IRazorViewEngine>();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.NotFound("Test", new[] { "Test" }));
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            await Assert.ThrowsAsync <TemplateServiceException>(() => renderer.RenderAsync(new Email("Test")));

            viewEngine.Verify();
        }
Esempio n. 16
0
        public async Task ExecuteResultAsync_FindsAndExecutesView()
        {
            // Arrange
            var viewName = "myview";
            var context  = GetActionContext();

            var view = new Mock <IView>(MockBehavior.Strict);

            view
            .Setup(v => v.RenderAsync(It.IsAny <ViewContext>()))
            .Returns(Task.FromResult(0))
            .Verifiable();

            view
            .As <IDisposable>()
            .Setup(v => v.Dispose())
            .Verifiable();

            view
            .Setup(v => v.Path)
            .Returns("//location");

            var viewEngine = new Mock <IViewEngine>(MockBehavior.Strict);

            viewEngine
            .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true))
            .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty <string>()))
            .Verifiable();
            viewEngine
            .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true))
            .Returns(ViewEngineResult.Found("myview", view.Object))
            .Verifiable();

            var viewResult = new ViewResult
            {
                ViewName   = viewName,
                ViewEngine = viewEngine.Object,
                ViewData   = new ViewDataDictionary(new EmptyModelMetadataProvider()),
                TempData   = Mock.Of <ITempDataDictionary>(),
            };

            // Act
            await viewResult.ExecuteResultAsync(context);

            // Assert
            view.Verify();
            viewEngine.Verify();
        }
        ViewEngineResult FindView(ActionContext actionContext, ViewResult viewResult)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            if (viewResult == null)
            {
                throw new ArgumentNullException(nameof(viewResult));
            }

            var viewEngine = viewResult.ViewEngine ?? ViewEngine;

            var viewName = viewResult.ViewName ?? GetActionName(actionContext);

            var result         = viewEngine.GetView(viewName, viewName, false);
            var originalResult = result;

            if (!result.Success)
            {
                result = viewEngine.FindView(actionContext, viewName, false);
            }

            if (!result.Success)
            {
                if (originalResult.SearchedLocations.Any())
                {
                    if (result.SearchedLocations.Any())
                    {
                        var locations = new List <string>(originalResult.SearchedLocations);
                        locations.AddRange(result.SearchedLocations);
                        result = ViewEngineResult.NotFound(viewName, locations);
                    }
                    else
                    {
                        result = originalResult;
                    }
                }
            }

            if (!result.Success)
            {
                throw new InvalidOperationException(string.Format("Couldn't find view '{0}'", viewName));
            }

            return(result);
        }
Esempio n. 18
0
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            if (!string.IsNullOrEmpty(_options.ViewNamePrefix))
            {
                if (!viewName.StartsWith(_options.ViewNamePrefix))
                {
                    return(ViewEngineResult.NotFound(viewName, new string[] { viewName }));
                }
            }

            return(ViewEngineResult.Found(viewName, new JsView
            {
                Path = !string.IsNullOrEmpty(_options.ViewNamePrefix) ? viewName.Substring(_options.ViewNamePrefix.Length) : viewName,
                ViewType = ViewType.Full
            }));
        }
Esempio n. 19
0
        /// <inheritdoc />
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            if (string.IsNullOrEmpty(viewPath))
            {
                throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(viewPath));
            }

            if (!(IsApplicationRelativePath(viewPath) || IsRelativePath(viewPath)))
            {
                // Not a path this method can handle.
                return ViewEngineResult.NotFound(viewPath, Enumerable.Empty<string>());
            }

            var cacheResult = LocatePageFromPath(executingFilePath, viewPath, isMainPage);
            return CreateViewEngineResult(cacheResult, viewPath);
        }
Esempio n. 20
0
        protected ViewEngineResult InnerGetView(string view, bool isMainPage)
        {
            var searchedLocations = Enumerable.Empty <string>();

            //Do not handle without a set WorkContext
            if (_workContextAccessor.WorkContext != null)
            {
                var path = _themeEngine.ResolveTemplatePath(view);
                if (!string.IsNullOrEmpty(path))
                {
                    return(ViewEngineResult.Found(view, new DotLiquidThemedView(_workContextAccessor, _urlBuilder, _themeEngine, view, path, isMainPage)));
                }
                searchedLocations = _themeEngine.DiscoveryPaths.ToArray();
            }
            return(ViewEngineResult.NotFound(view, searchedLocations));
        }
Esempio n. 21
0
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            if (!string.IsNullOrEmpty(_options.ViewNamePrefix))
            {
                if (!viewPath.StartsWith(_options.ViewNamePrefix))
                {
                    return(ViewEngineResult.NotFound(viewPath, new string[] { viewPath }));
                }
            }

            return(ViewEngineResult.Found(viewPath, new JsView
            {
                Path = !string.IsNullOrEmpty(_options.ViewNamePrefix) ? viewPath.Substring(_options.ViewNamePrefix.Length) : viewPath,
                ViewType = ViewType.Full
            }));
        }
Esempio n. 22
0
        public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
        {
            if (string.IsNullOrEmpty(viewPath) || !viewPath.EndsWith(ViewExtension, StringComparison.OrdinalIgnoreCase))
            {
                return(ViewEngineResult.NotFound(viewPath, Enumerable.Empty <string>()));
            }
            var appRelativePath = GetAbsolutePath(executingFilePath, viewPath);

            if (File.Exists(appRelativePath))
            {
                return(ViewEngineResult.Found(viewPath, new ClassicAspView(appRelativePath)));
            }
            return(ViewEngineResult.NotFound(viewPath, new List <string> {
                appRelativePath
            }));
        }
Esempio n. 23
0
        public async Task ProcessAsync_RendersFallbackView_If_MainIsNotFound_AndFindViewReturnsView()
        {
            // Arrange
            var expected     = "Hello from fallback!";
            var bufferScope  = new TestViewBufferScope();
            var partialName  = "_Partial";
            var fallbackName = "_Fallback";
            var model        = new object();
            var viewContext  = GetViewContext();

            var view = new Mock <IView>();

            view.Setup(v => v.RenderAsync(It.IsAny <ViewContext>()))
            .Callback((ViewContext v) =>
            {
                v.Writer.Write(expected);
            })
            .Returns(Task.CompletedTask);

            var viewEngine = new Mock <ICompositeViewEngine>();

            viewEngine.Setup(v => v.GetView(It.IsAny <string>(), partialName, false))
            .Returns(ViewEngineResult.NotFound(partialName, Array.Empty <string>()));
            viewEngine.Setup(v => v.FindView(viewContext, partialName, false))
            .Returns(ViewEngineResult.NotFound(partialName, Array.Empty <string>()));
            viewEngine.Setup(v => v.GetView(It.IsAny <string>(), fallbackName, false))
            .Returns(ViewEngineResult.NotFound(fallbackName, Array.Empty <string>()));
            viewEngine.Setup(v => v.FindView(viewContext, fallbackName, false))
            .Returns(ViewEngineResult.Found(fallbackName, view.Object));

            var tagHelper = new PartialTagHelper(viewEngine.Object, bufferScope)
            {
                Name         = partialName,
                ViewContext  = viewContext,
                FallbackName = fallbackName
            };
            var tagHelperContext = GetTagHelperContext();
            var output           = GetTagHelperOutput();

            // Act
            await tagHelper.ProcessAsync(tagHelperContext, output);

            // Assert
            var content = HtmlContentUtilities.HtmlContentToString(output.Content, new HtmlTestEncoder());

            Assert.Equal(expected, content);
        }
Esempio n. 24
0
        public ViewEngineResult GetModuleView(string executingFilePath, string viewPath)
        {
            if (string.IsNullOrEmpty(viewPath))
            {
                throw new ArgumentNullException(nameof(viewPath));
            }

            if (!(IsApplicationRelativePath(viewPath) || IsRelativePath(viewPath)))
            {
                // Not a path this method can handle.
                return(ViewEngineResult.NotFound(viewPath, Enumerable.Empty <string>()));
            }

            var cacheResult = LocatePageFromPath(executingFilePath, viewPath);

            return(CreateViewEngineResult(cacheResult, viewPath));
        }
Esempio n. 25
0
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            string viewPath = viewPath = $"Views/{viewName}.html";

            if (String.IsNullOrEmpty(viewName))
            {
                viewPath = $"Views/{context.RouteData.Values["action"]}.html";
            }
            if (File.Exists(viewPath))
            {
                return(ViewEngineResult.Found(viewPath, new CustomView(viewPath)));
            }
            else
            {
                return(ViewEngineResult.NotFound(viewName, new string[] { viewPath }));
            }
        }
Esempio n. 26
0
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            var controllerName = context.GetNormalizedRouteValue(Constants.CONTROLLER_KEY);

            var searchedLocations = new List <string>();

            foreach (var location in _options.ViewLocationFormats)
            {
                var viewPath = string.Format(location.Invoke(), viewName, controllerName);
                if (File.Exists(viewPath))
                {
                    return(ViewEngineResult.Found($"FindView viewName:{viewName}", new HandlebarsView(viewPath, _renderer)));
                }
                searchedLocations.Add(viewPath);
            }

            return(ViewEngineResult.NotFound(viewName, searchedLocations));
        }
Esempio n. 27
0
        public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
        {
            var controllerName = GetNormalizedRouteValue(context, "controller");

            var checkedLocations = new List <string>();

            foreach (var locationFormat in _viewLocationFormats)
            {
                var location = string.Format(locationFormat, viewName, controllerName);

                if (File.Exists(location))
                {
                    return(ViewEngineResult.Found("Default", new NVue(location, _viewLocationFormats, controllerName)));
                }
                checkedLocations.Add(location);
            }
            return(ViewEngineResult.NotFound(viewName, checkedLocations));
        }
Esempio n. 28
0
        public async Task Render_throws_exception_when_email_view_retrievepath_not_found()
        {
            var viewEngine = new Mock <IRazorViewEngine>();

            viewEngine.Setup(e => e.GetView(It.IsAny <string>(), "~/Views/TestFolder/Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.NotFound("~/Views/TestFolder/Test", new[] { "Test" })).Verifiable();

            var logger                       = new Mock <ILogger <TemplateService> >();
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            var hostingEnvironment           = new Mock <IWebHostEnvironment>();
            ITemplateService templateService = new TemplateService(logger.Object, viewEngine.Object, serviceProvider.Object, tempDataProvider.Object, hostingEnvironment.Object);
            var renderer                     = new EmailViewRender(templateService);

            await Assert.ThrowsAsync <TemplateServiceException>(() => renderer.RenderAsync(new Email("~/Views/TestFolder/Test")));

            viewEngine.Verify();
        }
Esempio n. 29
0
        // -----------

        ViewEngineResult FindView(string partialName)
        {
            var viewEngineResult = _viewEngine.GetView(ViewContext.ExecutingFilePath, partialName, isMainPage: false);
            var getViewLocations = viewEngineResult.SearchedLocations;

            if (!viewEngineResult.Success)
            {
                viewEngineResult = _viewEngine.FindView(ViewContext, partialName, isMainPage: false);
            }

            if (!viewEngineResult.Success)
            {
                var searchedLocations = Enumerable.Concat(getViewLocations, viewEngineResult.SearchedLocations);
                return(ViewEngineResult.NotFound(partialName, searchedLocations));
            }

            return(viewEngineResult);
        }
        public void Display_CallsFindView_WithExpectedPath()
        {
            // Arrange
            var viewEngine = new Mock <ICompositeViewEngine>(MockBehavior.Strict);

            viewEngine
            .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny <string>(), /*isMainPage*/ false))
            .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty <string>()));
            viewEngine
            .Setup(v => v.FindView(It.IsAny <ActionContext>(), "DisplayTemplates/String", /*isMainPage*/ false))
            .Returns(ViewEngineResult.Found(string.Empty, new Mock <IView>().Object))
            .Verifiable();
            var html = DefaultTemplatesUtilities.GetHtmlHelper(new object(), viewEngine: viewEngine.Object);

            // Act & Assert
            html.Display(expression: string.Empty, templateName: null, htmlFieldName: null, additionalViewData: null);
            viewEngine.Verify();
        }