/// <summary> /// Respondswithes the multiple. /// </summary> /// <param name="stump">The <see cref="Stump"/> intercepting incoming HTTP requests.</param> /// <param name="behavior">The behavior of the <see cref="StumpResponseFactory.CreateResponse(IStumpsHttpRequest)"/> method when retrieving the next <see cref="IStumpsHttpResponse"/>.</param> /// <returns>The calling <see cref="Stump"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="stump"/> is <c>null</c>.</exception> public static Stump ReturnsMultipleResponses(this Stump stump, ResponseFactoryBehavior behavior) { stump = stump ?? throw new ArgumentNullException(nameof(stump)); if (stump.Responses == null || stump.Responses.Behavior != behavior) { stump.Responses = new StumpResponseFactory(behavior); } return(stump); }
/// <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> /// Initializes a new instance of the <see cref="StumpResponseFactory"/> class that contains /// the responses copied from the specified collection. /// </summary> /// <param name="behavior">The The behavior of the <see cref="StumpResponseFactory.CreateResponse(IStumpsHttpRequest)"/> method when retrieving the next <see cref="IStumpsHttpResponse"/>.</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(ResponseFactoryBehavior behavior, IEnumerable <IStumpsHttpResponse> responses) : this(behavior) { responses = responses ?? throw new ArgumentNullException(nameof(responses)); _responses.AddRange(responses); }
public StumpResponseFactory(ResponseFactoryBehavior behavior) { this.Behavior = behavior; }
public static IStumpResponseFactory RespondsWithMultipleOptions(this TcpStump stump, ResponseFactoryBehavior behavior) { stump.Responses = stump.Responses ?? new StumpResponseFactory(behavior); return(stump.Responses); }
public void HasResponse_GivenABehavior_WithResponsesAndFailureResponse_ReturnsTrue(ResponseFactoryBehavior behavior) { var factory = new StumpResponseFactory(behavior); factory.Add(new MockHttpResponse()); Assert.IsTrue(factory.HasResponse); }
public void HasResponse_GivenABehavior_WhenFailureResponseIsNull_ReturnsCorrectResult(ResponseFactoryBehavior behavior, bool expectedResponse) { var factory = new StumpResponseFactory(behavior); factory.Add(new MockHttpResponse()); factory.FailureResponse = null; Assert.AreEqual(expectedResponse, factory.HasResponse); }
public void HasResponse_GivenABehavior_WithoutAnyResponses_ReturnsFalse(ResponseFactoryBehavior behavior) { var factory = new StumpResponseFactory(behavior); Assert.IsFalse(factory.HasResponse); }