PageRenderTime 243ms CodeModel.GetById 239ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Manos/Manos.Http.Testing/MockHttpTransaction.cs

http://github.com/jacksonh/manos
C# | 119 lines | 74 code | 21 blank | 24 comment | 2 complexity | 23e90ba2c9c2d3cd9beea7a3c6aaa0dd MD5 | raw file
  1//
  2// Copyright (C) 2010 Jackson Harper (jackson@manosdemono.com)
  3//
  4// Permission is hereby granted, free of charge, to any person obtaining
  5// a copy of this software and associated documentation files (the
  6// "Software"), to deal in the Software without restriction, including
  7// without limitation the rights to use, copy, modify, merge, publish,
  8// distribute, sublicense, and/or sell copies of the Software, and to
  9// permit persons to whom the Software is furnished to do so, subject to
 10// the following conditions:
 11// 
 12// The above copyright notice and this permission notice shall be
 13// included in all copies or substantial portions of the Software.
 14// 
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 16// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 17// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 18// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 19// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 20// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 21// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 22//
 23//
 24
 25
 26using System;
 27using System.Text;
 28using System.Collections;
 29using System.Collections.Generic;
 30
 31
 32namespace Manos.Http.Testing
 33{
 34	public class MockHttpTransaction : IHttpTransaction
 35	{
 36		private bool aborted;
 37
 38		public MockHttpTransaction (IHttpRequest request, IHttpResponse response)
 39		{
 40			if (request == null)
 41			   throw new ArgumentNullException ("request");
 42
 43			Request = request;
 44
 45			Response = response;
 46		}
 47		
 48		public String ResponseString{
 49			get{
 50				return (Response as MockHttpResponse).ResponseString();
 51			}
 52		}
 53		
 54		// TODO: I guess we need a mock server?
 55		public HttpServer Server {
 56			get { return null; }
 57		}
 58		
 59		public Manos.IO.Context Context {
 60			get;
 61			private set;
 62		}
 63				
 64		public IHttpRequest Request {
 65			get;
 66			private set;
 67		}
 68
 69		public IHttpResponse Response {
 70			get;
 71			private set;
 72		}
 73
 74		public bool Aborted {
 75			get;
 76			private set;
 77		}
 78
 79		public bool ResponseReady {
 80			get;
 81			private set;
 82		}
 83
 84		public int AbortedStatusCode {
 85		       get;
 86		       private set;
 87		}
 88
 89		public string AbortedMessage {
 90		       get;
 91		       private set;
 92		}
 93
 94		public bool Finished {
 95		       get;
 96		       private set;
 97		}
 98
 99		public void Finish ()
100		{
101			Finished = true;
102		}
103		
104		public void Abort (int status, string message, params object [] p)
105		{
106			Aborted = true;
107			AbortedStatusCode = status;
108			AbortedMessage = String.Format (message, p);
109		}
110
111		public void OnRequestReady()
112		{
113		}
114
115		public void OnResponseFinished ()
116		{
117		}
118	}
119}