コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 public StumpResponseFactory(ResponseFactoryBehavior behavior)
 {
     this.Behavior = behavior;
 }
コード例 #5
0
 public static IStumpResponseFactory RespondsWithMultipleOptions(this TcpStump stump, ResponseFactoryBehavior behavior)
 {
     stump.Responses = stump.Responses ?? new StumpResponseFactory(behavior);
     return(stump.Responses);
 }
コード例 #6
0
        public void HasResponse_GivenABehavior_WithResponsesAndFailureResponse_ReturnsTrue(ResponseFactoryBehavior behavior)
        {
            var factory = new StumpResponseFactory(behavior);

            factory.Add(new MockHttpResponse());

            Assert.IsTrue(factory.HasResponse);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void HasResponse_GivenABehavior_WithoutAnyResponses_ReturnsFalse(ResponseFactoryBehavior behavior)
        {
            var factory = new StumpResponseFactory(behavior);

            Assert.IsFalse(factory.HasResponse);
        }