Moq: unidade testando um método que depende do HttpContext

Considere um método em um assembly .NET:

public static string GetSecurityContextUserName()
{             
 //extract the username from request              
 string sUser = HttpContext.Current.User.Identity.Name;
 //everything after the domain     
 sUser = sUser.Substring(sUser.IndexOf("\\") + 1).ToLower();

 return sUser;      
}

Eu gostaria de chamar esse método de um teste de unidade usando o framework Moq. Essa montagem faz parte de uma solução de formulários. O teste de unidade se parece com isso, mas estou perdendo o código Moq.

//arrange 
 string ADAccount = "BUGSBUNNY";
 string fullADName = "LOONEYTUNES\BUGSBUNNY"; 

 //act    
 //need to mock up the HttpContext here somehow -- using Moq.
 string foundUserName = MyIdentityBL.GetSecurityContextUserName();

 //assert
 Assert.AreEqual(foundUserName, ADAccount, true, "Should have been the same User Identity.");

Questão:

Como posso usar o Moq para organizar um objeto HttpContext falso com algum valor como 'MyDomain \ MyUser'?Como faço para associar esse falso com minha chamada ao meu método estático emMyIdentityBL.GetSecurityContextUserName()?Você tem alguma sugestão sobre como melhorar este código / arquitetura?

questionAnswers(6)

yourAnswerToTheQuestion