public int ProductionKey_IsValid(string pattern, string url)
            {
                //arrange
                const ApiKey.ApplicationType applicationType = ApiKey.ApplicationType.Browser;
                var data = new ApiKeyData
                {
                    AppStatus  = ApiKey.ApplicationStatus.Production,
                    UrlPattern = pattern
                };

                using (var s = DocumentStore.OpenSession())
                {
                    s.Store(new ApiKey("key")
                    {
                        AccountId      = "testaccount",
                        CreatedAtTicks = 634940675825121039,
                        ApiKeyStatus   = ApiKey.KeyStatus.Active,
                        Type           = applicationType,
                        AppStatus      = ApiKey.ApplicationStatus.Production,
                        RegexPattern   =
                            CommandExecutor.ExecuteCommand(new FormatKeyPatternCommand(applicationType, data)),
                        Pattern       = null,
                        IsMachineName = false,
                        Deleted       = false
                    }, "testkey");

                    s.SaveChanges();
                }

                var content =
                    new ObjectContent <ResultContainer <GeocodeAddressResult> >(new ResultContainer <GeocodeAddressResult>
                {
                    Result = new GeocodeAddressResult
                    {
                        InputAddress = "tESTING",
                        Score        = 100
                    }
                }, new JsonMediaTypeFormatter());

                content.Headers.Add("X-Type", typeof(ResultContainer <GeocodeAddressResult>).ToString());

                var contentMoq = new Mock <HttpContentProvider>();

                contentMoq.Setup(x => x.GetResponseContent(It.IsAny <HttpResponseMessage>()))
                .Returns(content);

                var handler = new AuthorizeRequestHandler
                {
                    DocumentStore  = DocumentStore,
                    InnerHandler   = new TestHandler((r, c) => TestHandler.Return200()),
                    ApiKeyProvider = new ApiKeyProvider()
                };

                var client = new HttpClient(handler);

                client.DefaultRequestHeaders.Add("Referrer", new[] { url });
                client.DefaultRequestHeaders.Add("Referer", new[] { url });

                var result =
                    client.GetAsync("http://webapi/v1/Geocode/326 east south temple/84111?apiKey=key")
                    .Result;

                return((int)result.StatusCode);
            }
Esempio n. 2
0
 public FormatKeyPatternCommand(ApiKey.ApplicationType type, ApiKeyData data)
 {
     Type     = type;
     Data     = data;
     _hasHttp = new Regex(Https, RegexOptions.IgnoreCase);
 }