private dynamic SetupController(IResearchItemRepository mockResearchItemRepository, IProjectRepository mockProjectRepository, string userName, HttpMethod method, string version)
        {
            dynamic projectResearchItemsController = null;

            if (version == "V1")
            {
                projectResearchItemsController = new ResearchLinks.Controllers.Version1.ProjectResearchItemsController(mockResearchItemRepository, mockProjectRepository);
            }
            else if (version == "V2")
            {
                projectResearchItemsController = new ResearchLinks.Controllers.Version2.ProjectResearchItemsController(mockResearchItemRepository, mockProjectRepository);
            }

            var user     = new Mock <IPrincipal>();
            var identity = new Mock <IIdentity>();

            user.Setup(x => x.Identity).Returns(identity.Object);
            identity.Setup(x => x.Name).Returns(userName);
            Thread.CurrentPrincipal = user.Object;

            var config    = new HttpConfiguration();
            var request   = new HttpRequestMessage(method, "http://localhost/api/projects/1/researchItems");
            var route     = config.Routes.MapHttpRoute("ProjectResearchItemsApi", "api/projects/{projectId}/researchItems/{researchItemId}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {
                { "controller", "projectResearchItems" }
            });

            projectResearchItemsController.ControllerContext = new HttpControllerContext(config, routeData, request);
            projectResearchItemsController.Request           = request;
            projectResearchItemsController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            projectResearchItemsController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey]     = routeData;

            return(projectResearchItemsController);
        }
예제 #2
0
 // Constructor here to inject dependencies in concrete class.
 public ProjectResearchItemsController(IResearchItemRepository researchItemRepository, IProjectRepository projectRepository)
 {
     _researchItemRepository = researchItemRepository;
     _projectRepository      = projectRepository;
 }
 // Constructor here to inject dependencies in concrete class.
 public ProjectResearchItemsController(IResearchItemRepository researchItemRepository, IProjectRepository projectRepository)
 {
     _researchItemRepository = researchItemRepository;
     _projectRepository = projectRepository;
 }
        private dynamic SetupController(IResearchItemRepository mockResearchItemRepository, IProjectRepository mockProjectRepository, string userName, HttpMethod method, string version)
        {
            dynamic projectResearchItemsController = null;

            if (version == "V1") {
                projectResearchItemsController = new ResearchLinks.Controllers.Version1.ProjectResearchItemsController(mockResearchItemRepository, mockProjectRepository);
            } else if (version == "V2") {
                projectResearchItemsController = new ResearchLinks.Controllers.Version2.ProjectResearchItemsController(mockResearchItemRepository, mockProjectRepository);
            }
            
            var user = new Mock<IPrincipal>();
            var identity = new Mock<IIdentity>();
            user.Setup(x => x.Identity).Returns(identity.Object);
            identity.Setup(x => x.Name).Returns(userName);
            Thread.CurrentPrincipal = user.Object;

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(method, "http://localhost/api/projects/1/researchItems");
            var route = config.Routes.MapHttpRoute("ProjectResearchItemsApi", "api/projects/{projectId}/researchItems/{researchItemId}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "projectResearchItems" } });

            projectResearchItemsController.ControllerContext = new HttpControllerContext(config, routeData, request);
            projectResearchItemsController.Request = request;
            projectResearchItemsController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            projectResearchItemsController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;

            return projectResearchItemsController;
        }