/// <summary>Tries to look at a thing.</summary> /// <param name="thingToLookAt">The thing to look at.</param> /// <param name="sender">The sender.</param> /// <returns>Returns the rendered view.</returns> private string TryLookAtThing(string thingToLookAt, Thing sender) { // @@@ TODO: Refactor ViewEngine to remove NVelicoty: https://wheelmud.codeplex.com/workitem/13348 var viewEngine = new ViewEngine(); // Look for target in the current room Thing thing = sender.Parent.FindChild(thingToLookAt); if (thing != null && this.sensesBehavior.CanPerceiveThing(thing)) { return(viewEngine.RenderView(thing)); } // If no target found, see if it matches any of the room's visuals. var room = sender.Parent.FindBehavior <RoomBehavior>(); if (room != null) { string visual = room.FindVisual(thingToLookAt); if (!string.IsNullOrEmpty(visual)) { return(viewEngine.RenderView(visual)); } } // At this point, target was not found. return(string.Empty); }
public void CollectionWithComplexTypeThrowsDuringRenderingTest(Type complexType) { ViewEngine engine = ViewEngineSetup.SetupViewEngine("<ul>@Model.Collection.Collection(<li>@Item</li>)</ul>"); object[] complexObjectCollection = { Activator.CreateInstance(complexType) }; Dictionary <string, object> propertyBag = new Dictionary <string, object> { ["Collection"] = complexObjectCollection }; Assert.That(() => engine.RenderView(string.Empty, string.Empty, propertyBag), Throws.ArgumentException); }
public void CollectionRenderingTest(params object[] collection) { ViewEngine engine = ViewEngineSetup.SetupViewEngine("<ul>@Model.Collection.Collection(<li>@Item</li>)</ul>"); Dictionary <string, object> propertyBag = new Dictionary <string, object> { ["Collection"] = collection }; string renderedView = engine.RenderView(string.Empty, string.Empty, propertyBag); Assert.That(renderedView, Is.EqualTo($"<ul>{string.Concat(collection.Select(item => $"<li>{item}</li>"))}</ul>")); }
public void NullPrimitiveValueRenderingTest() { ViewEngine viewEngine = ViewEngineSetup.SetupViewEngine("<h1>@Model.Value</h1>"); Dictionary <string, object> propertyBag = new Dictionary <string, object> { ["Value"] = null }; string renderedHtml = viewEngine.RenderView(string.Empty, string.Empty, propertyBag); Assert.That(renderedHtml, Is.EqualTo("<h1>null</h1>")); }
protected virtual IViewable View([CallerMemberName] string actionName = default) { string controllerName = GetType().Name.Replace(MvcContext.ControllersSuffix, string.Empty); string viewContent; try { viewContent = ViewEngine.RenderView(controllerName, actionName, PropertyBag); } catch (Exception e) { viewContent = ViewEngine.RenderError(e.Message, PropertyBag["role"].ToString()); } return(new ViewResult(new View(viewContent))); }
public void CorrectBodyReplacementRenderingTest(string value) { ViewEngine engine = ViewEngineSetup.SetupViewEngine(viewPath => { if (viewPath.EndsWith("_Layout.html")) { return("<html><head></head><body>@Body()</body>"); } return("<h1>@Model.Value</h1>"); }); Dictionary <string, object> propertyBag = new Dictionary <string, object> { ["Value"] = value }; string renderedHtml = engine.RenderView(string.Empty, string.Empty, propertyBag); Assert.That(renderedHtml, Is.EqualTo($"<html><head></head><body><h1>{value}</h1></body>")); }
public void ComplexTypeRenderingTest(string title, string type, int count) { ViewEngine engine = ViewEngineSetup.SetupViewEngine(viewPath => { if (viewPath.EndsWith("DisplayTemplate.html")) { return("<div><h1>@Model.Title</h1><hr/><hr/><h2>@Model.Type</h2><h2>@Model.Count</h2><div>@Model.SomeOtherProperty</div></div>"); } return("<section>@Model.Value</section>"); }); Dictionary <string, object> propertyBag = new Dictionary <string, object> { ["Value"] = new ComplexType(title, type, count) }; string renderedHtml = engine.RenderView(string.Empty, string.Empty, propertyBag); Assert.That(renderedHtml, Is.EqualTo($"<section><div><h1>{title}</h1><hr/><hr/><h2>{type}</h2><h2>{count}</h2><div>null</div></div></section>")); }
/// <summary> /// Tries the look at thing. /// </summary> /// <param name="thingToLookAt">The thing to look at.</param> /// <param name="sender">The sender.</param> /// <returns>Returns the rendered view.</returns> private string TryLookAtThing(string thingToLookAt, Thing sender) { // @@@ TODO: Refactor ViewEngine to remove NVelicoty: https://wheelmud.codeplex.com/workitem/13348 var viewEngine = new ViewEngine(); // Look for target in the current room Thing thing = sender.Parent.FindChild(thingToLookAt); if (thing != null && this.sensesBehavior.CanPerceiveThing(thing)) { return viewEngine.RenderView(thing); } // If no target found, see if it matches any of the room's visuals. var room = sender.Parent.FindBehavior<RoomBehavior>(); if (room != null) { string visual = room.FindVisual(thingToLookAt); if (!string.IsNullOrEmpty(visual)) { return viewEngine.RenderView(visual); } } // At this point, target was not found. return string.Empty; }
private void LoadSplashScreens() { string name = Configuration.GetDataStoragePath(); string path = Path.Combine(Path.GetDirectoryName(name), "Files"); path = Path.Combine(path, "SplashScreens"); var viewEngine = new ViewEngine(); viewEngine.AddContext("MudAttributes", MudEngineAttributes.Instance); var dirInfo = new DirectoryInfo(path); var files = new List<FileInfo>(dirInfo.GetFiles()); foreach (var fileInfo in files) { var sr = new StreamReader(fileInfo.FullName); string splashContent = sr.ReadToEnd(); sr.Close(); string renderedScreen = viewEngine.RenderView(splashContent); splashScreens.Add(renderedScreen); this.SystemHost.UpdateSystemHost(this, string.Format("{0} has been loaded.", fileInfo.Name)); } }