public void Should_Have_An_Active_Session()
 {
     var context = CreateMockableContext();
     context.RequestCookies[SessionStateContext.AspNetSessionCookieName].Returns(Constants.SessionId);
     var sessionContext = new SessionStateContext(context);
     sessionContext.HasActiveSession().ShouldBeTrue();
 }
        public void Should_Create_A_New_Session()
        {
            var context = CreateMockableContext();
            var sessionContext = new SessionStateContext(context);
            sessionContext.CreateNewSession();

            sessionContext.SessionId.ShouldNotBeEmpty();
            context.ResponseCookies.Received()[SessionStateContext.AspNetSessionCookieName] = Arg.Any<string>();
        }
        public void Abandon(IHttpContext httpContext)
        {
            var sessionContext = SessionStateContext.Create(httpContext);

            httpContext.SessionState.Abandon();
            if (!sessionContext.HasActiveSession())
            {
                return;
            }
            _sessionProvider.Abandon(sessionContext);
        }
        public void Save(IHttpContext httpContext)
        {
            var sessionContext = SessionStateContext.Create(httpContext);
            var values         = ItemsWithCompatableDataTypes(httpContext.SessionState.ToDictionary(x => x.Key, x => x.Value));

            if (!sessionContext.HasActiveSession())
            {
                sessionContext.CreateNewSession();
            }
            _sessionProvider.Save(sessionContext, values);
        }
        public void Load(IHttpContext httpContext)
        {
            var sessionContext = SessionStateContext.Create(httpContext);

            if (!sessionContext.HasActiveSession())
            {
                return;
            }
            var values = ItemsWithCompatableDataTypes(_sessionProvider.Load(sessionContext));

            if (!values.Any())
            {
                httpContext.SessionState.RemoveAll();
                return;
            }
            values.Where(x => !httpContext.SessionState.Any(y => y.Key == x.Key) ||
                         httpContext.SessionState[x.Key] != x.Value).
            ToList().ForEach(x => httpContext.SessionState[x.Key] = x.Value);
            httpContext.SessionState.Where(x => !values.ContainsKey(x.Key)).ToList().
            ForEach(x => httpContext.SessionState.Remove(x.Key));
        }
 public void Should_Not_Have_An_Active_Session()
 {
     var context = CreateMockableContext();
     var sessionContext = new SessionStateContext(context);
     sessionContext.HasActiveSession().ShouldBeFalse();
 }