What you want to do is replace directly using a session in your adapters. You want to create an interface something like
public interface ISessionableObject
{
MyData Data { get; set; }
}
and then create 2 implementing classes similar to
public class HttpSessionedObject : ISessionableObject
{
public MyData Data {
get { return Session["mydata"]; }
set { Session["mydata"] = value; }
}
}
public class DictionaryObject : ISessionableObject
{
private readonly Dictionary<string, MyData> _dict =
new Dictionary<string, MyData>();
public MyData Data {
get { return dict ["mydata"]; }
set { dict ["mydata"] = value; }
}
}
Edit:
Just incase you have some confusion on what to do with this, I'm sure you have something like this:
public class Adapter
{
public void DoSomething()
{
var data = Session["mydata"];
...
}
}
Instead you'll want something like this
public class Adapter
{
private readonly ISessionableObject _session;
public Adapter(ISessionableObject session)
{
_session = session;
}
public void DoSomething()
{
var data = _session.Data;
...
}
}
I would recommend using a Dependency Injection Framework like StructureMap to handle the creation of your objects but that's a much larger topic unrelated to this so atleast going with poor mans dependency injection your code will be similar to
public class AdapterUser
{
public void UsingPhone()
{
var adapter = Adapter(new HttpSessionedObject());
...
}
}
And
[UnitTest]
public class AdapterUserTest
{
[Test]
public void UsingPhone()
{
var adapter = Adapter(new DictionaryObject());
...
}
}