/// <summary> /// Initializes a new instance of the <see cref="RecordedResponse" /> class. /// </summary> /// <param name="response">The <see cref="IStumpsHttpResponse" /> used to initialize the instance.</param> /// <param name="decoderHandling">The <see cref="ContentDecoderHandling" /> requirements for the HTTP body.</param> /// <exception cref="ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception> public RecordedResponse(IStumpsHttpResponse response, ContentDecoderHandling decoderHandling) : base(response, decoderHandling) { response = response ?? throw new ArgumentNullException(nameof(response)); this.RedirectAddress = response.RedirectAddress; this.StatusCode = response.StatusCode; this.StatusDescription = response.StatusDescription; }
public void Constructor_WithNullDefaultResponse_ThrowsException() { Assert.That( () => { IStumpsHttpResponse nullResponse = null; var factory = new StumpResponseFactory(nullResponse); }, Throws.Exception.TypeOf <ArgumentNullException>().With.Property("ParamName").EqualTo("failureResponse")); }
/// <summary> /// Initializes a new instance of the <see cref="T:Stumps.Server.RecordedResponse" /> class. /// </summary> /// <param name="response">The <see cref="T:Stumps.IStumpsHttpResponse" /> used to initialize the instance.</param> /// <param name="decoderHandling">The <see cref="T:Stumps.Server.ContentDecoderHandling" /> requirements for the HTTP body.</param> /// <exception cref="System.ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception> public RecordedResponse(IStumpsHttpResponse response, ContentDecoderHandling decoderHandling) : base(response, decoderHandling) { if (response == null) { throw new ArgumentNullException("response"); } this.RedirectAddress = response.RedirectAddress; this.StatusCode = response.StatusCode; this.StatusDescription = response.StatusDescription; }
/// <summary> /// Initializes a new instance of the <see cref="T:Stumps.Stump" /> class. /// </summary> /// <param name="stumpId">The unique identifier for the stump.</param> /// <exception cref="System.ArgumentNullException"><paramref name="stumpId"/> is <c>null</c>, an empty string, or only contains white space.</exception> public Stump(string stumpId) { if (string.IsNullOrWhiteSpace(stumpId)) { throw new ArgumentNullException("stumpId"); } this.StumpId = stumpId; _ruleList = new List<IStumpRule>(); _response = null; }
/// <summary> /// Initializes a new instance of the <see cref="StumpResponseFactory"/> class that does not contain /// any responses and will, by default, return an HTTP 501 (Not Implemented) error. /// </summary> /// <param name="behavior">The The behavior of the <see cref="StumpResponseFactory.CreateResponse(IStumpsHttpRequest)"/> method when retrieving the next <see cref="IStumpsHttpResponse"/>.</param> public StumpResponseFactory(ResponseFactoryBehavior behavior) { _listLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); _positionLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); _position = -1; _responses = new List <IStumpsHttpResponse>(); _random = new Random(Environment.TickCount); this.Behavior = behavior; _failureResponse = HttpErrorResponses.HttpNotImplemented; }
/// <summary> /// Adds the specified response to the <see cref="IStumpResponseFactory" />. /// </summary> /// <param name="response">The <see cref="IStumpsHttpResponse" /> to add to the <see cref="IStumpResponseFactory" />.</param> /// <returns>The <see cref="IStumpsHttpResponse"/> added to the object.</returns> /// <exception cref="ArgumentNullException"><paramref name="response" /> is <c>null</c>.</exception> /// <exception cref="ObjectDisposedException">The <see cref="StumpResponseFactory" /> object has been disposed.</exception> public IStumpsHttpResponse Add(IStumpsHttpResponse response) { ThrowExceptionIfDisposed(); response = response ?? throw new ArgumentNullException(nameof(response)); _listLock.EnterWriteLock(); _positionLock.EnterWriteLock(); _responses.Add(response); Interlocked.Exchange(ref _position, -1); _listLock.ExitWriteLock(); _positionLock.ExitWriteLock(); return(response); }
/// <summary> /// Initializes a new instance of the <see cref="StumpResponseFactory"/> class that contains /// the responses copied from the specified collection while specifying the default response when there /// are no other responses left in a sequence, or the instance does not contain any responses. /// </summary> /// <param name="failureResponse">The <see cref="IStumpsHttpResponse"/> returned when there are no responses left in a sequence.</param> /// <param name="responses">The collection of <see cref="IStumpsHttpResponse"/> whose elements are copied to the new instance.</param> /// <exception cref="ArgumentNullException"><paramref name="responses"/> is <c>null</c>.</exception> public StumpResponseFactory(IStumpsHttpResponse failureResponse, IEnumerable <IStumpsHttpResponse> responses) : this(failureResponse) { responses = responses ?? throw new ArgumentNullException(nameof(responses)); _responses.AddRange(responses); }
/// <summary> /// Initializes a new instance of the <see cref="StumpResponseFactory"/> class that does not contain /// any responses while specifying the default response when there are no other responses left in a sequence, /// or the instance does not contain any responses. /// </summary> /// <param name="failureResponse">The <see cref="IStumpsHttpResponse"/> returned when there are no responses left in a sequence.</param> /// <exception cref="ArgumentNullException"><paramref name="failureResponse"/> is <c>null</c>.</exception> /// <remarks>This will set the behavior to <see cref="ResponseFactoryBehavior.OrderedThenFailure"/>.</remarks> public StumpResponseFactory(IStumpsHttpResponse failureResponse) : this(ResponseFactoryBehavior.OrderedThenFailure) { _failureResponse = failureResponse ?? throw new ArgumentNullException(nameof(failureResponse)); }
public MockHttpContext(IStumpsHttpRequest request, IStumpsHttpResponse response) { this.Request = request ?? new MockHttpRequest(); this.Response = response ?? new MockHttpResponse(); }