A class that represents the persisted form of an HTTP response.
Inheritance: HttpContextPartEntity
コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.Data.HttpResponseEntityReader"/> class.
        /// </summary>
        /// <param name="serverId">The unique identifier for the server.</param>
        /// <param name="responseEntity">The response entity.</param>
        /// <param name="dataAccess">The data access provider used by the instance.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="serverId"/> is <c>null</c>.
        /// or
        /// <paramref name="responseEntity"/> is <c>null</c>.
        /// or 
        /// <paramref name="dataAccess"/> is <c>null</c>.
        /// </exception>
        public HttpResponseEntityReader(string serverId, HttpResponseEntity responseEntity, IDataAccess dataAccess)
        {
            if (string.IsNullOrWhiteSpace(serverId))
            {
                throw new ArgumentNullException("serverId");
            }

            if (responseEntity == null)
            {
                throw new ArgumentNullException("responseEntity");

            }

            if (dataAccess == null)
            {
                throw new ArgumentNullException("dataAccess");
            }

            _entity = responseEntity;

            this.Headers = new HttpHeaders();
            foreach (var pair in _entity.Headers)
            {
                this.Headers[pair.Name] = pair.Value;
            }

            _body = dataAccess.ServerReadResource(serverId, responseEntity.BodyResourceName) ?? new byte[0];
        }
コード例 #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpResponseEntityReader"/> class.
        /// </summary>
        /// <param name="serverId">The unique identifier for the server.</param>
        /// <param name="responseEntity">The response entity.</param>
        /// <param name="dataAccess">The data access provider used by the instance.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="serverId"/> is <c>null</c>.
        /// or
        /// <paramref name="responseEntity"/> is <c>null</c>.
        /// or
        /// <paramref name="dataAccess"/> is <c>null</c>.
        /// </exception>
        public HttpResponseEntityReader(string serverId, HttpResponseEntity responseEntity, IDataAccess dataAccess)
        {
            if (string.IsNullOrWhiteSpace(serverId))
            {
                throw new ArgumentNullException(nameof(serverId));
            }

            dataAccess = dataAccess ?? throw new ArgumentNullException(nameof(dataAccess));

            _entity = responseEntity ?? throw new ArgumentNullException(nameof(responseEntity));

            this.Headers = new HttpHeaders();
            foreach (var pair in _entity.Headers)
            {
                this.Headers[pair.Name] = pair.Value;
            }

            _body = dataAccess.ServerReadResource(serverId, responseEntity.BodyResourceName) ?? new byte[0];
        }
コード例 #3
0
        public DataAccessTests()
        {
            _sampleProxyServer = new ServerEntity
            {
                AutoStart            = false,
                RemoteServerHostName = SampleHostName,
                Port     = 500,
                ServerId = "ABCD",
                UseSsl   = false
            };

            var originalRequest = new HttpRequestEntity()
            {
                HttpMethod       = "GET",
                BodyResourceName = null,
                Headers          = new List <NameValuePairEntity>(),
                ProtocolVersion  = "1.1",
                RawUrl           = "/"
            };

            var originalResponse = new HttpResponseEntity()
            {
                BodyResourceName = null,
                Headers          = new List <NameValuePairEntity>()
                {
                    new NameValuePairEntity
                    {
                        Name  = "Content-Type",
                        Value = "text/plain"
                    }
                },
                RedirectAddress   = null,
                StatusCode        = 200,
                StatusDescription = "OK"
            };

            var response = new HttpResponseEntity()
            {
                BodyResourceName = null,
                Headers          = new List <NameValuePairEntity>()
                {
                    new NameValuePairEntity
                    {
                        Name  = "Content-Type",
                        Value = "text/plain"
                    }
                },
                RedirectAddress   = null,
                StatusCode        = 200,
                StatusDescription = "OK"
            };

            _sampleStump = new StumpEntity
            {
                OriginalRequest  = originalRequest,
                OriginalResponse = originalResponse,
                Response         = response,
                Rules            = new List <RuleEntity>(),
                StumpCategory    = "Uncategorized",
                StumpId          = "ABCD",
                StumpName        = "MyStump"
            };

            _sampleBytes = new byte[]
            {
                1, 2, 3
            };
        }
コード例 #4
0
ファイル: DataAccessTests.cs プロジェクト: Cayan-LLC/stumps
        public DataAccessTests()
        {
            _sampleProxyServer = new ServerEntity
            {
                AutoStart = false,
                RemoteServerHostName = SampleHostName,
                Port = 500,
                ServerId = "ABCD",
                UseSsl = false
            };

            var originalRequest = new HttpRequestEntity()
            {
                HttpMethod = "GET",
                BodyResourceName = null,
                Headers = new List<NameValuePairEntity>(),
                ProtocolVersion = "1.1",
                RawUrl = "/"
            };

            var originalResponse = new HttpResponseEntity()
            {
                BodyResourceName = null,
                Headers = new List<NameValuePairEntity>()
                {
                    new NameValuePairEntity
                    {
                        Name = "Content-Type",
                        Value = "text/plain"
                    }
                },
                RedirectAddress = null,
                StatusCode = 200,
                StatusDescription = "OK"
            };

            var response = new HttpResponseEntity()
            {
                BodyResourceName = null,
                Headers = new List<NameValuePairEntity>()
                {
                    new NameValuePairEntity
                    {
                        Name = "Content-Type",
                        Value = "text/plain"
                    }
                },
                RedirectAddress = null,
                StatusCode = 200,
                StatusDescription = "OK"
            };

            _sampleStump = new StumpEntity
            {
                OriginalRequest = originalRequest,
                OriginalResponse = originalResponse,
                Response = response,
                Rules = new List<RuleEntity>(),
                StumpCategory = "Uncategorized",
                StumpId = "ABCD",
                StumpName = "MyStump"
            };

            _sampleBytes = new byte[]
            {
                1, 2, 3
            };
        }
コード例 #5
0
        /// <summary>
        ///     Creates a Stump data entity from a Stump contract.
        /// </summary>
        /// <param name="contract">The <see cref="T:Stumps.Server.StumpContract"/> used to create the entity.</param>
        /// <returns>
        ///     A <see cref="T:Stumps.Server.Data.StumpEntity"/> created from the specified <paramref name="contract"/>.
        /// </returns>
        public static StumpEntity CreateEntityFromContract(StumpContract contract)
        {
            var originalRequest = new HttpRequestEntity
            {
                BodyResourceName = string.Empty,
                Headers = CreateNameValuePairFromHeaders(contract.OriginalRequest.Headers),
                HttpMethod = contract.OriginalRequest.HttpMethod,
                LocalEndPoint = contract.OriginalRequest.LocalEndPoint.ToString(),
                ProtocolVersion = contract.OriginalRequest.ProtocolVersion,
                RawUrl = contract.OriginalRequest.RawUrl,
                RemoteEndPoint = contract.OriginalRequest.RemoteEndPoint.ToString()
            };

            var originalResponse = new HttpResponseEntity
            {
                BodyResourceName = string.Empty,
                Headers = CreateNameValuePairFromHeaders(contract.OriginalResponse.Headers),
                RedirectAddress = contract.OriginalResponse.RedirectAddress,
                StatusCode = contract.OriginalResponse.StatusCode,
                StatusDescription = contract.OriginalResponse.StatusDescription
            };

            var response = new HttpResponseEntity
            {
                BodyResourceName = string.Empty,
                Headers = CreateNameValuePairFromHeaders(contract.Response.Headers),
                RedirectAddress = contract.Response.RedirectAddress,
                StatusCode = contract.Response.StatusCode,
                StatusDescription = contract.Response.StatusDescription
            };

            var entity = new StumpEntity
            {
                OriginalRequest = originalRequest,
                OriginalResponse = originalResponse,
                Response = response,
                ResponseDelay = contract.ResponseDelay,
                Rules = new List<RuleEntity>(),
                StumpCategory = contract.StumpCategory,
                StumpId = contract.StumpId,
                StumpName = contract.StumpName,
                TerminateConnection = contract.TerminateConnection
            };

            foreach (var rule in contract.Rules)
            {
                var ruleEntity = new RuleEntity
                {
                    RuleName = rule.RuleName,
                    Settings = new List<NameValuePairEntity>()
                };

                var settings = rule.GetRuleSettings();
                foreach (var setting in settings)
                {
                    ruleEntity.Settings.Add(
                        new NameValuePairEntity
                        {
                            Name = setting.Name,
                            Value = setting.Value
                        });
                }

                entity.Rules.Add(ruleEntity);

            }

            return entity;
        }