나는 이것이 알고 이전 질문, 그리고 다른 곳에서 답변을 얻을 수도 있지만, 우리가 작업하고있는 프로젝트에서 Linqpad로 Controller Actions를 디버깅 할 수 있습니다. 반환 된 값을 가져옵니다.
var result = homeController.Index();
result.Dump();
당신은 또한 당신의 상황을 조롱하고 디버거로 비주얼 스튜디오를 연결해야 할 수도 있습니다
간단히 말해서, 당신은 뭔가를 반환하는 Linqpad 말할 필요가있다.
전체 코드는 :
void Main()
{
using(var svc = new CrmOrganizationServiceContext(new CrmConnection("Xrm")))
{
DummyIdentity User = new DummyIdentity();
using (var context = new XrmDataContext(svc))
{
// Attach the Visual Studio debugger
System.Diagnostics.Debugger.Launch();
// Instantiate the Controller to be tested
var controller = new HomeController(svc);
// Instantiate the Context, this is needed for IPrincipal User
var controllerContext = new ControllerContext();
controllerContext.HttpContext = new DummyHttpContext();
controller.ControllerContext = controllerContext;
// Test the action
var result = controller.Index();
result.Dump();
}
}
}
// Below is the Mocking classes used to sub in Context, User, etc.
public class DummyHttpContext:HttpContextBase {
public override IPrincipal User {get {return new DummyPrincipal();}}
}
public class DummyPrincipal : IPrincipal
{
public bool IsInRole(string role) {return role == "User";}
public IIdentity Identity {get {return new DummyIdentity();}}
}
public class DummyIdentity : IIdentity
{
public string AuthenticationType { get {return "?";} }
public bool IsAuthenticated { get {return true;}}
public string Name { get {return "[email protected]";} }
}
당신은 디버거를 선택 내장 앱을 비주얼 스튜디오의 인스턴스를 선택하라는 메시지가 받아야합니다.
MVC-CRM에 대한 특정 설정이 있으므로 모든 사용자에게 적용되지는 않습니다.하지만 다른 사용자에게 도움이되기를 바랍니다.
그런 위업의 목표가 무엇인지 물어봐도 될까요? –
@Kenneth K 주요 목적은 테스트 및 버그 수정을보다 쉽게하는 것입니다. Ofcourse 단위 테스트를 사용할 수 있지만 그들은 Linqpad에서 덤프 같은 강력한 출력 방법을 havent. – Neir0
@ 케네스 케이 또 다른 이유는 asp.net mvc 응용 프로그램이 실제로 어떻게 작동하는지 이해하는 것입니다. 당신이 당신의 자신의 손으로 그것을 시도 할 때 그것은 다만 더 나은 어떤 기사든지 다만 읽는다. – Neir0