According to ISession Extensions source code GetString
and SetString
are extension methods
public static void SetString(this ISession session, string key, string value)
{
session.Set(key, Encoding.UTF8.GetBytes(value));
}
public static string GetString(this ISession session, string key)
{
var data = session.Get(key);
if (data == null)
{
return null;
}
return Encoding.UTF8.GetString(data);
}
public static byte[] Get(this ISession session, string key)
{
byte[] value = null;
session.TryGetValue(key, out value);
return value;
}
You will need to mock ISession.Set
and ISession.TryGetValue
in order to let the extension methods execute as expected.
//Arrange
var sessionMock = new Mock<ISession>();
var key = "userdata";
var value = new byte[0];
sessionMock.Setup(_ => _.Set(key, It.IsAny<byte[]>()))
.Callback<string, byte[]>((k,v) => value = v);
sessionMock.Setup(_ => _.TryGetValue(key, out value))
.Returns(true);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…