public void Good_Url(string url)
                {
                    var data = new ApiKeyData
                        {
                            Ip = "",
                            UrlPattern = url,
                            AppStatus = ApiKey.ApplicationStatus.Production
                        };

                    var command = new ValidateAndGetKeyTypeCommand(data);
                    var type = CommandExecutor.ExecuteCommand(command);

                    Assert.That(type, Is.EqualTo(ApiKey.ApplicationType.Browser));
                    Assert.That(command.ErrorMessage, Is.Null);
                }
        public void Empty_Parameters_Returns_None_with_Message()
        {
            var data = new ApiKeyData
                {
                    Ip = "",
                    UrlPattern = "",
                    AppStatus = ApiKey.ApplicationStatus.Production
                };

            var command = new ValidateAndGetKeyTypeCommand(data);
            var type = CommandExecutor.ExecuteCommand(command);

            Assert.That(type, Is.EqualTo(ApiKey.ApplicationType.None));
            Assert.That(command.ErrorMessage, Is.Not.Null);
        }
            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) => { return TestHandler.Return200(); })
                    };

                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;
            }