public static void FlashMessageSet(Controller controller, string flashMessageType, string message) { FlashMessageCollection flashMessages = new FlashMessageCollection(controller.TempData); bool flashMessageSet = flashMessages.Any(x => x.Key == flashMessageType && x.Message == message); Assert.IsTrue(flashMessageSet); }
public void GetFlashMessages_returns_a_collection() { TempDataDictionary tempData = new TempDataDictionary(); var original = new FlashMessageCollection(tempData); original.Add(new FlashMessage("info", "Hello, World!")); var flashMessages = tempData.GetFlashMessages(); Assert.AreEqual(1, flashMessages.Count()); }
public void Before_each_test() { ViewPage viewPage = new ViewPage(); ViewContext viewContext = new ViewContext(); viewContext.TempData = new TempDataDictionary(); htmlHelper = new HtmlHelper(viewContext, viewPage); flashMessageCollection = new FlashMessageCollection(viewContext.TempData); }
/// <summary> /// Add a new message to the flash with the given key. /// </summary> /// <param name="controller">Controller.</param> /// <param name="key">Flash key.</param> /// <param name="message">Flash message.</param> public static void Flash(this Controller controller, string key, string message) { Contract.Requires<ArgumentNullException>(controller != null); Contract.Requires<NullReferenceException>(controller.TempData != null); Contract.Requires<ArgumentNullException>(key != null); Contract.Requires<ArgumentNullException>(message != null); Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(key)); FlashMessageCollection flashMessageCollection = new FlashMessageCollection(controller.TempData); FlashMessage flashMessage = new FlashMessage(key, message); flashMessageCollection.Add(flashMessage); }
/// <summary> /// Renders the HTML containing the flash messages. /// </summary> /// <param name="htmlHelper"></param> /// <returns>HTML string</returns> public static IHtmlString RenderFlash(this HtmlHelper htmlHelper) { Contract.Requires<ArgumentNullException>(htmlHelper != null); var outerDiv = CreateOuterDiv(); FlashMessageCollection flashMessageCollection = new FlashMessageCollection(htmlHelper.ViewContext.TempData); foreach (FlashMessage flashMessage in flashMessageCollection) { AddFlashMessageToOuterDiv(flashMessage, outerDiv); } return MvcHtmlString.Create(outerDiv.ToString(TagRenderMode.Normal)); }
public void Before_each_test() { controller = new FakeController(); flashMessageCollection = new FlashMessageCollection(controller.TempData); }
public void Before_each_test() { tempData = new TempDataDictionary(); collection = new FlashMessageCollection(tempData); }