Since we moved from version .54 to .60 in our Unit Tests the error started to appear
AppHost does not support accessing the current Request via a Singleton
But, works fine on production … so I just want to fix the unit tests…
from an old answer, it seems we should pass the request, but the error is thrown when converting the current session into a the session object:
public object Get(GetActivitiesInformation request)
{
var session = SessionAs<MitivoApiAuthSession>();
...
with the trace
System.NotImplementedException : This AppHost does not support accessing the current Request via a Singleton
at ServiceStack.HostContext.GetCurrentRequest()
at ServiceStack.SessionFeature.GetOrCreateSession[T](ICacheClient cache, IRequest httpReq, IResponse httpRes)
at ServiceStack.Service.SessionAs[TUserSession]()
at Mitivo.Services.Services.ActivityService.Get(GetActivitiesInformation request) in D:\Repositories\Mitivo_back_end\code\Mitivo.Services\Services\ActivityService.cs:line 48
at Mitivo.UnitTests.Services.ActivityServiceTest.CanGetActivities() in D:\Repositories\Mitivo_back_end\code\Mitivo.UnitTests\Services\ActivityServiceTest.cs:line 67
What do I have to do in my ServiceTEstBase
to avoid this exception?
current:
[TestFixtureSetUp]
protected void ServiceTestFixtureSetUp()
{
AppHost = new BasicAppHost(typeof(BoostService).Assembly)
{
ConfigureContainer = container =>
{
//Set JSON web services to return idiomatic JSON camelCase properties
// make servicestack use structure map as the adapter as we can the reuse the IoC container from Gko lib init
container.Adapter = new StructureMapContainerAdapter();
//Set JSON web services to return idiomatic JSON camelCase properties
JsConfig.EmitCamelCaseNames = true;
JsConfig.DateHandler = DateHandler.ISO8601;
JsConfig.IncludeNullValues = true;
// Memory cache
container.RegisterAs<MemoryCacheClient, ICacheClient>();
var userRep = new MitivoUserAuthRepository(container.Resolve<NHibernate.ISessionFactory>(), container.Resolve<IMitivoUserPasswordProvider>());
container.Register<IUserAuthRepository>(userRep);
container.Register<IRoleValidator>(new RoleValidator());
container.RegisterAutoWiredAs<RewardHelper, IRewardHelper>();
container.RegisterAutoWiredAs<LogActionLogger, ILogActionLogger>();
container.Register(A.Fake<ILoggerFactory>());
}
}
.Init();
Container = ServiceStackHost.Instance.Container;
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
AppHost.Dispose();
}