public TestHttpListenerWebRequest GetHttpListenerWebRequestObject() { Assembly resourceAssembly = Assembly.LoadFrom(Path.Combine(DestinationFolder, _serviceName + this.WebDataServicePrefixName) + ".dll"); BaseTestWebRequest request = BaseTestWebRequest.CreateForHttpListener(); request.ServiceType = resourceAssembly.GetType(_serviceName + "." + Workspace.ServiceClassName); request.StartService(); return((TestHttpListenerWebRequest)request); }
/// <summary>Sends the current request to the server.</summary> public override void SendRequest() { if (this.ServiceType == null) { throw new InvalidOperationException("DataServiceType or ServiceType property should be set for in-process requests."); } // Set up an in-process host. host = new TestServiceHost2(); host.RequestAcceptCharSet = this.AcceptCharset; host.RequestHttpMethod = this.HttpMethod; host.RequestPathInfo = this.RequestUriString; host.RequestStream = this.RequestStream; host.RequestContentType = this.RequestContentType; host.RequestContentLength = this.RequestContentLength; host.RequestIfMatch = this.IfMatch; host.RequestIfNoneMatch = this.IfNoneMatch; host.RequestMaxVersion = this.RequestMaxVersion; foreach (var header in this.RequestHeaders) { host.RequestHeaders.Add(header.Key, header.Value); } host.RequestVersion = this.RequestVersion; if (this.Accept != null) { host.RequestAccept = this.Accept; } // An important side-effect of the following line of code is to // clean the TestArguments static for tests which don't use it. BaseTestWebRequest.LoadSerializedTestArguments(ArgumentsToString(this.TestArguments)); try { // Create a data service instance and hook into the processing directly - only GET supported right now. Type serviceType = this.ServiceType; try { object serviceInstance = Activator.CreateInstance(serviceType); MethodInfo attachMethod = serviceType.GetMethod("AttachHost"); attachMethod.Invoke(serviceInstance, new object[] { host }); MethodInfo method = serviceType.GetMethod("ProcessRequest", Type.EmptyTypes); method.Invoke(serviceInstance, null); this.responseStream = GetResponseStream(host); } catch (TargetInvocationException invocationException) { this.responseStream = GetResponseStream(host); if (invocationException.InnerException != null) { if (BaseTestWebRequest.SaveOriginalStackTrace && invocationException.InnerException.Data != null) { invocationException.InnerException.Data["OriginalStackTrace"] = invocationException.InnerException.StackTrace; } throw invocationException.InnerException; } else { throw; } } finally { if (this.RequestStream != null) { AstoriaTestLog.IsTrue(this.RequestStream.CanRead, "request stream must be open"); } if (this.responseStream != null) { AstoriaTestLog.IsTrue(this.responseStream.CanRead, "response stream must be open"); } } } finally { LoadSerializedTestArguments(null); } }