// Take HttpContextBase for mock/testability. public void ProcessRequestBase(HttpContextBase context) { using (_tracer.Step("CustomGitServerController.ProcessRequest")) { GitServerRequestType requestType; string repoRelFilePath; _tracer.Trace("Parsing request uri {0}", context.Request.Url.AbsoluteUri); if (!TryParseUri(context.Request.Url, out repoRelFilePath, out requestType)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; context.Response.End(); return; } IEnvironment env = GetInstance <IEnvironment>(); var repoFullPath = Path.GetFullPath(Path.Combine(env.RootPath, repoRelFilePath)); env.RepositoryPath = repoFullPath; _tracer.Trace("Using repository path: {0}", repoFullPath); switch (requestType) { case GitServerRequestType.AdvertiseUploadPack: using (_tracer.Step("CustomGitServerController.AdvertiseUploadPack")) { if (RepositoryExists(context)) { var gitServer = GetInstance <IGitServer>(); GitServerHttpHandler.UpdateNoCacheForResponse(context.Response); context.Response.ContentType = "application/x-git-upload-pack-advertisement"; context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.OutputStream.PktWrite("# service=git-upload-pack\n"); context.Response.OutputStream.PktFlush(); gitServer.AdvertiseUploadPack(context.Response.OutputStream); context.Response.End(); } } break; case GitServerRequestType.UploadPack: if (RepositoryExists(context)) { UploadPackHandler uploadPackHandler = GetInstance <UploadPackHandler>(); context.Response.StatusCode = (int)HttpStatusCode.OK; uploadPackHandler.ProcessRequestBase(context); context.Response.End(); } break; default: context.Response.StatusCode = (int)HttpStatusCode.NotImplemented; context.Response.End(); break; } return; } }
private CustomGitRepositoryHandler CreateHandler( IGitServer gitServer = null, UploadPackHandler uploadPackHandler = null, IRepositoryFactory repositoryFactory = null, IEnvironment environment = null) { return new CustomGitRepositoryHandler(t => { if (t == typeof(ITracer)) { return Mock.Of<ITracer>(); } else if (t == typeof(IGitServer)) { return gitServer ?? Mock.Of<IGitServer>(); } else if (t == typeof(UploadPackHandler)) { return new UploadPackHandler( Mock.Of<ITracer>(), Mock.Of<IGitServer>(), Mock.Of<IOperationLock>(), Mock.Of<IDeploymentManager>()); } else if (t == typeof(IRepositoryFactory)) { return repositoryFactory ?? Mock.Of<IRepositoryFactory>(); } else if (t == typeof(IEnvironment)) { return environment ?? Mock.Of<IEnvironment>(); } throw new NotImplementedException("type " + t.Name + " is not implemented!"); }); }