Exemplo n.º 1
0
        private static HttpRequest CreateStubRequest(HttpMethod httpMethod, string requestScheme, string host, string path)
        {
            var request = new Mock <HttpRequest>();

            request.Setup(req => req.Method).Returns(httpMethod.ToString().ToUpper);
            request.Setup(req => req.Scheme).Returns(requestScheme);
            request.Setup(req => req.Host).Returns(new HostString(host));
            request.Setup(req => req.Path).Returns(path);

            return(request.Object);
        }
        public async Task InsertOrReplace(HttpMethod method, string url, object data)
        {
            var record = new JsonData
            {
                PartitionKey = _options.EnvironmentName,
                RowKey       = $"{method}_{Uri.EscapeDataString(url)}",
                Url          = Uri.UnescapeDataString(url),
                HttpMethod   = method.ToString(),
                Data         = JsonSerializer.Serialize(data)
            };

            var operation = TableOperation.InsertOrReplace(record);
            await _table.ExecuteAsync(operation);
        }
        public string GetData(HttpMethod method, string url)
        {
            var item = _table.ExecuteQuery(new TableQuery <JsonData>()).SingleOrDefault(x =>
                                                                                        x.Url == Uri.UnescapeDataString(url) && x.HttpMethod.Equals(method.ToString(), StringComparison.InvariantCultureIgnoreCase));

            return(item?.Data);
        }