예제 #1
0
        public void ExistingTempDataIsntModified() {
            var sink = new Notifier();
            var filter = new NotifyFilter(sink);

            var executedContext = BuildContext();
            executedContext.Controller.TempData.Add("messages", "dont-destroy");
            filter.OnActionExecuted(executedContext);
            Assert.That(executedContext.Controller.TempData["messages"], Is.EqualTo("dont-destroy"));
        }
예제 #2
0
        public void NewMessagesAreConcatinated() {
            var sink = new Notifier();
            var filter = new NotifyFilter(sink);
            sink.Error("Boom");

            var executedContext = BuildContext();
            executedContext.Controller.TempData.Add("messages", "dont-destroy");
            filter.OnActionExecuted(executedContext);
            Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("dont-destroy"));
            Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("dont-destroy"));
        }
예제 #3
0
        public void AfterActionExecutedMessagesShouldAppearInTempData() {
            var sink = new Notifier();
            var filter = new NotifyFilter(sink);
            sink.Information("Hello world");

            var executedContext = BuildContext();
            filter.OnActionExecuted(executedContext);

            Assert.That(executedContext.Controller.TempData.ContainsKey("messages"));
            Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("Hello world"));
        }
예제 #4
0
        public void MessageServiceCanAccumulateWarningsAndErrorsToReturn() {
            INotifier notifier = new Notifier();
            Localizer T = NullLocalizer.Instance;

            notifier.Warning(T("Hello world"));
            notifier.Information(T("More Info"));
            notifier.Error(T("Boom"));

            Assert.That(notifier.List(), Has.Count.EqualTo(3));
            Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("Hello world")));
            Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("More Info")));
            Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("Boom")));
        }
예제 #5
0
        public void TempDataBuildsMessagesWhenResultExecutingIsBaseViewModel() {
            var sink = new Notifier();
            var filter = new NotifyFilter(sink);
            sink.Information("Working");

            var model = new BaseViewModel();

            var context = BuildContext();
            context.Controller.TempData.Add("messages", "dont-destroy" + System.Environment.NewLine + "-" + System.Environment.NewLine);
            context.Result = new ViewResult {
                ViewData = new ViewDataDictionary<BaseViewModel>(model),
                TempData = context.Controller.TempData
            };

            filter.OnActionExecuted(context);
            filter.OnResultExecuting(new ResultExecutingContext(context, context.Result));

            var T = NullLocalizer.Instance;

            Assert.That(model.Messages, Is.Not.Null);
            Assert.That(model.Messages, Has.Count.EqualTo(2));
            Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("dont-destroy")));
            Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("Working")));
        }