저는 새로운 테스트와 테스트도 정말 새롭습니다.mvc4로 Ninject 테스트를 작성하십시오.
테스트를 시작할 mvc4 응용 프로그램이 있습니다. 내가 예를 들어 내 응용 프로그램 내에서 저장소의 모든 것을 쓴
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx =>() => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IConsumerRepository>().To<ConsumerRepository>();
}
내가
public interface IConsumerRepository
{
ConsumerModel GetConsumerByUserId(Guid userId);
}
public ConsumerModel GetConsumerByUserId(Guid userId)
{
if (HttpContext.Current.Session["ConsumerInfo"] == null)
{
var data = RestSharperHelper.GetById<ConsumerModel>("id", userId, ApiEndPointConstants.GetConsumerById);
LogMessage(data.UserName);
HttpContext.Current.Session["ConsumerInfo"] = data;
return data;
}
else
{
return (ConsumerModel)HttpContext.Current.Session["ConsumerInfo"];
}
}
을 내 NinjectWebCommon 내
를 (예 내가 아는 나는 :) 내가 가서 그들을 작성하는 의미입니다) ConsumerModel이 웹 응용 프로그램 저장소에서 반환되는지 확인하는 테스트를 작성하는 가장 좋은 방법은 무엇입니까? 시간이 지남에 따라 유연 해지기를 원합니다. 더 복잡한 테스트를 작성하고 모의 의사를 제공하고 싶습니다. 위와 같이 api를 매번 호출하는 대신 ConsumerModel을 사용합니다.
주셔서 감사합니다!
.GetById' 및'HttpContext.Current'. 단위 테스트를 원할 경우 추상화를 도입해야합니다. –