public void TestMessageAppendedEvent() { InitializeHttpContext(); var store = new FeedbackMessageStore(); var feedbackMessage = FeedbackMessage.Info("test raise appended event."); int countRaiseEvent = 0; EventHandler <MessageAppendedEventArgs> handler = (sender, args) => { Assert.AreEqual(store, sender); Assert.AreEqual(feedbackMessage, args.Message); countRaiseEvent++; }; // register store.OnMessageAppeded += handler; store.AddMessage(feedbackMessage); Assert.AreEqual(1, countRaiseEvent); // unregister store.OnMessageAppeded -= handler; store.AddMessage(FeedbackMessage.Warn("test unregister event")); Assert.AreEqual(1, countRaiseEvent); }
public void TestAddMessages() { InitializeHttpContext(); var store = new FeedbackMessageStore(); List <FeedbackMessage> messages = new List <FeedbackMessage>(); var info = FeedbackMessage.Info("Test info message."); var warn = FeedbackMessage.Warn("Test warn message."); messages.Add(info); messages.Add(warn); store.AddMessages(messages); IList <FeedbackMessage> infoMessages = store.GetFeedbackMessages(FeedbackMessageLevel.INFO); Assert.AreEqual(1, infoMessages.Count); Assert.IsTrue(infoMessages.Contains(info)); IList <FeedbackMessage> successMessages = store.GetFeedbackMessages(FeedbackMessageLevel.SUCCESS); Assert.AreEqual(0, successMessages.Count); IList <FeedbackMessage> warnMessages = store.GetFeedbackMessages(FeedbackMessageLevel.WARN); Assert.AreEqual(1, warnMessages.Count); Assert.IsTrue(warnMessages.Contains(warn)); IList <FeedbackMessage> errorMessages = store.GetFeedbackMessages(FeedbackMessageLevel.ERROR); Assert.AreEqual(0, errorMessages.Count); }
public void TestMarkRendered() { var message = FeedbackMessage.Info("test message"); Assert.IsFalse(message.IsRendered); message.MarkRendered(); Assert.IsTrue(message.IsRendered); }
public void TestSetFactory() { InitializeHttpContext(); Func <FeedbackMessage, string> func = msg => msg.ToString(); var builder = new FeedbackMessageScriptBuilder(func); var message = FeedbackMessage.Info("Info message"); Assert.IsNotNull(builder.ScriptFactory); Assert.AreEqual(func.Invoke(message), builder.ScriptFactory.Convert(message)); }
public void TestGetOnDomReadyScripts() { InitializeHttpContext(); var builder = new FeedbackMessageScriptBuilder(msg => msg.ToString()); FeedbackMessageStore.Current.AddMessage(FeedbackMessage.Info("Info message")); var str = builder.GetDomReadyScript(); Assert.IsTrue(str.Contains(builder.GetScripts())); }
public void TestClear() { var store = new FeedbackMessageStore(); var message = FeedbackMessage.Info("Test"); store.AddMessage(message); store.AddMessage(FeedbackMessage.Info("Test2")); Assert.AreEqual(2, store.Count); store.Clear(); Assert.AreEqual(0, store.Count); }
public void TestContains() { var store = new FeedbackMessageStore(); var message = FeedbackMessage.Info("Test"); store.AddMessage(message); store.AddMessage(FeedbackMessage.Info("Test2")); Assert.AreEqual(2, store.Count); Assert.IsTrue(store.Contains(message)); Assert.IsFalse(store.Contains(FeedbackMessage.Warn("Test"))); }
public void TestStringConverter() { var converter = new FeedbackMessageStringConverter(); Assert.IsNotNull(converter.StringFactory); var message = FeedbackMessage.Info("Convert test"); Assert.AreEqual("Convert test", converter.Convert(message)); converter.StringFactory = msg => "prefix-" + msg.ToString(); Assert.AreEqual("prefix-Convert test", converter.Convert(message)); }
public void TestEquals() { var messageA = FeedbackMessage.Info("test message."); var messageB = FeedbackMessage.Info("test message."); var messageC = FeedbackMessage.Error("test message."); var messageD = FeedbackMessage.Error("test message!!!"); // same level, same message Assert.AreEqual(messageA, messageB); // different levle, same message. Assert.AreNotEqual(messageA, messageC); Assert.AreNotEqual(messageB, messageC); // same level, different message Assert.AreNotEqual(messageC, messageD); }
public void TestClearLevel() { var store = new FeedbackMessageStore(); var message = FeedbackMessage.Info("Test"); store.AddMessage(message); store.AddMessage(FeedbackMessage.Info("Test2")); store.AddMessage(FeedbackMessage.Warn("Test2")); Assert.AreEqual(3, store.Count); store.Clear(FeedbackMessageLevel.INFO); Assert.AreEqual(1, store.Count); store.Clear(FeedbackMessageLevel.WARN); Assert.AreEqual(0, store.Count); }
public void TestSerializeAndDeserializeStore() { var store = new FeedbackMessageStore(); store.Add(FeedbackMessage.Info("情報メッセージ")); var serializer = new FeedbackMessageStoreSerializer(); var str = serializer.Serialize(store); var deserializeStore = serializer.Deserialize(str); Assert.IsTrue(deserializeStore.HasUnrenderedMessage()); Assert.AreEqual("情報メッセージ", deserializeStore.GetFeedbackMessages()[0].ToString()); Assert.AreEqual(1, deserializeStore.Count); }
public void TestFilterPageHandlerExecuted() { var httpContext = InitializeHttpContext(); var store = new FeedbackMessageStore(); store.AddMessage(FeedbackMessage.Info("test")); httpContext.Items[FeedbackMessageStoreHolder.ITEM_KEY] = store; // flashs message store to session var filter = new FeedbackMessageActionFilter(); filter.OnPageHandlerExecuted(null); var flashedStore = httpContext.Session.GetStore(FeedbackMessageStoreHolder.ITEM_KEY); Assert.IsNotNull(flashedStore); Assert.AreEqual(1, flashedStore.Count); }
public void TestAddDuplicaateMessages() { InitializeHttpContext(); var store = new FeedbackMessageStore(); var info1 = FeedbackMessage.Info("Test message."); var info2 = FeedbackMessage.Info("Test message."); store.AddMessage(info1); store.AddMessage(info2); Assert.AreEqual(1, store.Count); var warn = FeedbackMessage.Warn("Test message."); store.AddMessage(warn); Assert.AreEqual(2, store.Count); }
public void TestFilterPageHandlerExecuting() { var httpContext = InitializeHttpContext(); var store = new FeedbackMessageStore(); store.AddMessage(FeedbackMessage.Info("test")); httpContext.Session.SetStore(FeedbackMessageStoreHolder.ITEM_KEY, store); // loads message store from session var filter = new FeedbackMessageActionFilter(); filter.OnPageHandlerExecuting(null); var loadedStore = httpContext.Items[FeedbackMessageStoreHolder.ITEM_KEY] as FeedbackMessageStore; Assert.IsNotNull(loadedStore); Assert.AreEqual(1, loadedStore.Count); }
public void TestAddMessage() { InitializeHttpContext(); var store = new FeedbackMessageStore(); var feedbackMessage = FeedbackMessage.Info("Test info message."); store.AddMessage(feedbackMessage); IList <FeedbackMessage> infoMessages = store.GetFeedbackMessages(FeedbackMessageLevel.INFO); Assert.AreEqual(1, infoMessages.Count); Assert.IsTrue(infoMessages.Contains(feedbackMessage)); IList <FeedbackMessage> errorMessages = store.GetFeedbackMessages(FeedbackMessageLevel.ERROR); Assert.AreEqual(0, errorMessages.Count); }
public void TestGetScripts() { InitializeHttpContext(); var builder = new FeedbackMessageScriptBuilder(msg => msg.ToString()); FeedbackMessageStore.Current.AddMessage(FeedbackMessage.Info("Info message")); var str = builder.GetScripts(); Assert.IsTrue(str.Equals("Info message;")); FeedbackMessageStore.Current.AddMessage(FeedbackMessage.Info("Info message1")); FeedbackMessageStore.Current.AddMessage(FeedbackMessage.Info("Info message2")); var str2 = builder.GetScripts(); Assert.IsTrue(str2.Contains("Info message1;")); Assert.IsTrue(str2.Contains("Info message2;")); }
public void TestCleanRendered() { InitializeHttpContext(); var store = new FeedbackMessageStore(); Assert.IsFalse(store.HasUnrenderedMessage()); var infoMessage1 = FeedbackMessage.Info("Test warn message1"); store.AddMessage(infoMessage1); var infoMessage2 = FeedbackMessage.Info("Test warn message2"); store.AddMessage(infoMessage2); var infoMessage3 = FeedbackMessage.Info("Test warn message3"); store.AddMessage(infoMessage3); store.CleanRendered(); var infoMessages = store.GetFeedbackMessages(FeedbackMessageLevel.INFO); Assert.AreEqual(3, infoMessages.Count); infoMessage1.MarkRendered(); infoMessage2.MarkRendered(); store.CleanRendered(); var infoMessagesCleanedRendered = store.GetFeedbackMessages(FeedbackMessageLevel.INFO); Assert.AreEqual(1, infoMessagesCleanedRendered.Count); Assert.IsTrue(infoMessagesCleanedRendered.Contains(infoMessage3)); infoMessage3.MarkRendered(); store.CleanRendered(); Assert.IsFalse(store.HasUnrenderedMessage()); }
public void TestFlashExistsUnrenderedMessages() { var httpContext = InitializeHttpContext(); var store = new FeedbackMessageStore(); store.AddMessage(FeedbackMessage.Info("test message.")); httpContext.Items[FeedbackMessageStoreHolder.ITEM_KEY] = store; FeedbackMessageStore.Flash(); var flashedStore = httpContext.Session.GetStore(FeedbackMessageStoreHolder.ITEM_KEY); Assert.IsNotNull(flashedStore); Assert.AreEqual(1, flashedStore.Count); Assert.IsTrue(flashedStore.HasUnrenderedMessage()); var message = flashedStore.GetFeedbackMessages()[0]; Assert.AreEqual(FeedbackMessageLevel.INFO, message.Level); Assert.AreEqual("test message.", message.ToString()); }
public void InfoMessage(object message) { FeedbackMessageStore.Current.AddMessage(FeedbackMessage.Info(message)); }
/// <summary> /// Sets information message to <see cref="FeedbackMessageStore"/>. /// </summary> /// <param name="pageModel"></param> /// <param name="message"></param> public static void InfoMessage(this PageModel pageModel, Object message) { var feedbackMessage = FeedbackMessage.Info(message); FeedbackMessageStore.Current.AddMessage(feedbackMessage); }
/// <summary> /// Sets information message to <see cref="FeedbackMessageStore"/>. /// </summary> /// <param name="controller"></param> /// <param name="message"></param> public static void InfoMessage(this Controller controller, Object message) { var feedbackMessage = FeedbackMessage.Info(message); FeedbackMessageStore.Current.AddMessage(feedbackMessage); }
/// <summary> /// Sets information message to <see cref="FeedbackMessageStore"/>. /// </summary> /// <param name="component"></param> /// <param name="message"></param> public static void InfoMessage(this IComponent component, Object message) { var feedbackMessage = FeedbackMessage.Info(message); FeedbackMessageStore.Current.AddMessage(feedbackMessage); }