public virtual void FromCookies(bool pHasCookie) { var cookies = (pHasCookie ? TOauthSession.CreateWorkingCookie() : new HttpCookieCollection()); var mockLogger = new Mock <IFabricLog>(MockBehavior.Strict); mockLogger.Setup(x => x.Info(It.IsAny <string>(), It.IsAny <string>())); vMockConfig.SetupGet(x => x.Logger).Returns(mockLogger.Object); IFabricSessionContainer sc = FabricSessionContainer.FromCookies(vMockClient.Object, cookies); if (pHasCookie) { Assert.NotNull(sc, "Container should be filled."); Assert.NotNull(sc.Person, "Container.Person should be filled."); Assert.AreEqual("sessId", sc.Person.SessionId, "Incorrect Person.SessionId."); } else { Assert.Null(sc, "Container should be null."); } }
/*--------------------------------------------------------------------------------------------*/ /// <summary /> //TEST: FabricSessionContainer.FromHttpContext() public static IFabricSessionContainer FromHttpContext(HttpContext pContext, string pConfigKey) { HttpSessionState sess = pContext.Session; if (sess == null) { return(null); } string key = "Fabric_" + pConfigKey; IFabricSessionContainer sc = (sess[key] as IFabricSessionContainer); if (sc != null) { return(sc); } sc = FromCookies(new FabricClient(pConfigKey), pContext.Request.Cookies); if (sc == null) { sc = new FabricSessionContainer(); } sess[key] = sc; return(sc); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public void Out(string pType, IFabricClientConfig pConfig, string pText) { IFabricSessionContainer sc = pConfig.GetSessionContainer(); IFabricPersonSession p = (sc != null ? sc.Person : null); string psId = (p == null ? Empty32 : p.SessionId); Console.WriteLine("Fabric | " + pType.PadRight(5) + " | " + psId + " | " + pText); }
public virtual void FromValues() { const string sessId = "sessId"; const string grant = "grant"; const string bearer = "bearer"; const string refresh = "refresh"; DateTime exp = DateTime.UtcNow.AddMinutes(30); IFabricSessionContainer sc = FabricSessionContainer.FromValues(vMockClient.Object, sessId, grant, bearer, refresh, exp); Assert.NotNull(sc, "Container should be filled."); Assert.NotNull(sc.Person, "Container.Person should be filled."); Assert.AreEqual(sessId, sc.Person.SessionId, "Incorrect Person.SessionId."); Assert.AreEqual(grant, sc.Person.GrantCode, "Incorrect Person.GrantCode."); Assert.AreEqual(bearer, sc.Person.BearerToken, "Incorrect Person.BearerToken."); Assert.AreEqual(refresh, sc.Person.RefreshToken, "Incorrect Person.RefreshToken."); Assert.AreEqual(exp, sc.Person.Expiration, "Incorrect Person.Expiration."); }