Inheritance: System.Web.HttpSessionStateBase
示例#1
0
        public void SetUp()
        {
            var mock = new Mock<HttpContextBase>();
            var sessionMock = new HttpSessionMock();

            mock.Setup(context => context.Items).Returns(new Dictionary<object, object>());
            mock.Setup(context => context.Session).Returns(sessionMock);

            FlashConfiguration.WithContext(() => mock.Object);
            FlashConfiguration.WithService(() => new SessionFlashMessageService(mock.Object));
        }
        public void Can_Push_A_Message()
        {
            var mock = new Mock<HttpContextBase>();
            var session = new HttpSessionMock();

            mock.Setup(m => m.Session).Returns(session);

            var message = new { type = "success", message = "Hooray!" };
            var service = new SessionFlashMessageService(mock.Object);

            service.Push(message);
        }
        public void Can_Clear_Messages()
        {
            var mock = new Mock<HttpContextBase>();
            var session = new HttpSessionMock();
            mock.Setup(m => m.Session).Returns(session);

            var message = new { type = "success", message = "Hooray!" };
            var service = new SessionFlashMessageService(mock.Object);

            service.Push(message);
            service.Clear();
            var popped = service.Pop();

            Assert.IsNotNull(popped);
            Assert.IsTrue(popped.Count == 0);
        }
        public void Can_Select_One_From_Other_Messages()
        {
            var mock = new Mock<HttpContextBase>();
            var session = new HttpSessionMock();

            mock.Setup(m => m.Session).Returns(session);

            var message1 = new { type = "success", message = "Hooray!" };
            var message2 = new { type = "success", message = "Hooray!" };
            var message3 = new { type = "different", message = "Different!" };

            var service = new SessionFlashMessageService(mock.Object);

            service.Push(message1);
            service.Push(message2);
            service.Push(message3);

            var popped = service.Select(x => x.type == "different");

            Assert.IsNotNull(popped);
            Assert.IsTrue(popped.Count == 1);
            Assert.IsTrue(popped.First().type == "different");

            var others = service.Pop();

            Assert.IsNotNull(others);
            Assert.IsTrue(others.Count == 2);
            Assert.IsTrue(others.First().type == "success");
        }