/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. using System;
  25. using System.Text;
  26. using System.Collections;
  27. using System.Collections.Generic;
  28. namespace Manos.Http.Testing
  29. {
  30. public class MockHttpTransaction : IHttpTransaction
  31. {
  32. private bool aborted;
  33. public MockHttpTransaction (IHttpRequest request, IHttpResponse response)
  34. {
  35. if (request == null)
  36. throw new ArgumentNullException ("request");
  37. Request = request;
  38. Response = response;
  39. }
  40. public String ResponseString{
  41. get{
  42. return (Response as MockHttpResponse).ResponseString();
  43. }
  44. }
  45. // TODO: I guess we need a mock server?
  46. public HttpServer Server {
  47. get { return null; }
  48. }
  49. public Manos.IO.Context Context {
  50. get;
  51. private set;
  52. }
  53. public IHttpRequest Request {
  54. get;
  55. private set;
  56. }
  57. public IHttpResponse Response {
  58. get;
  59. private set;
  60. }
  61. public bool Aborted {
  62. get;
  63. private set;
  64. }
  65. public bool ResponseReady {
  66. get;
  67. private set;
  68. }
  69. public int AbortedStatusCode {
  70. get;
  71. private set;
  72. }
  73. public string AbortedMessage {
  74. get;
  75. private set;
  76. }
  77. public bool Finished {
  78. get;
  79. private set;
  80. }
  81. public void Finish ()
  82. {
  83. Finished = true;
  84. }
  85. public void Abort (int status, string message, params object [] p)
  86. {
  87. Aborted = true;
  88. AbortedStatusCode = status;
  89. AbortedMessage = String.Format (message, p);
  90. }
  91. public void OnRequestReady()
  92. {
  93. }
  94. public void OnResponseFinished ()
  95. {
  96. }
  97. }
  98. }