Beispiel #1
0
        public void Handle(IAsyncResult result)
        {
            try
            {
                if (!_listener.IsListening)
                    return;

                var httpListenerContext = _listener.EndGetContext(result);

                var identifier = new ResourceIdentifier(httpListenerContext.Request.HttpMethod,
                    httpListenerContext.Request.Url.AbsolutePath, Uri.UnescapeDataString(httpListenerContext.Request.Url.Query));

                if (_resources.ContainsKey(identifier))
                {
                    _resources[identifier].Handle(httpListenerContext);
                }
                else
                {
                    Debug.WriteLine("Could not handle request: {0} {1}", httpListenerContext.Request.HttpMethod, httpListenerContext.Request.Url);
                    httpListenerContext.Response.StatusCode = 500;

                    httpListenerContext.Response.Close(Encoding.UTF8.GetBytes("unknown mocked resource"), false);
                }
            }
            catch { }
            finally
            {
                try
                {
                    _listener.BeginGetContext(Handle, null);
                }
                catch
                { }
            }
        }
 protected bool Equals(ResourceIdentifier other)
 {
     return Equals(_httpMethod, other._httpMethod) && string.Equals(_path, other._path);
 }
Beispiel #3
0
 public MockResource(ResourceIdentifier identifier)
 {
     Identifier = identifier;
 }