Exemplo n.º 1
0
        public void LogsCorrectAmountOfRequests()
        {
            var routeDataMoq = new Mock <RouteDataProvider>();

            routeDataMoq.Setup(x => x.GetRouteData(It.IsAny <HttpRequestMessage>()))
            .Returns(new RouteData
            {
                Controller = "GEOCODE",
                Action     = "GET"
            });

            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 ApiLoggingHandler
            {
                InnerHandler        = new TestHandler((r, c) => TestHandler.Return200()),
                RouteDataProvider   = routeDataMoq.Object,
                HttpContentProvider = contentMoq.Object,
                ApiKeyProvider      = new ApiKeyProvider()
            };

            var       client   = new HttpClient(handler);
            const int requests = 10;

            for (var i = 0; i < requests; i++)
            {
                var result = client.GetAsync("http://api.mapserv.utah.gov/api/v1/Geocode/326 east south temple/84111?apiKey=key")
                             .Result;

                Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            }

            int count;

            using (var s = DocumentStore.OpenSession())
            {
                count = s.Query <GeocodeStreetZoneUsage>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                        .Count();
            }
            Assert.That(count, Is.EqualTo(requests));
        }
Exemplo n.º 2
0
        public void MonthExpirationTimeSpan()
        {
            var span   = ApiLoggingHandler.CalculateTimeUntil(DateTime.Now, ApiLoggingHandler.Month);
            var actual = span.Days;

            Debug.WriteLine(actual);
            Debug.WriteLine(DateTime.Now.Add(span));
            Assert.That(actual, Is.GreaterThan(0));
            Assert.That(actual, Is.LessThan(31));
        }
Exemplo n.º 3
0
        public void TodayExpirationTimeSpan()
        {
            var span   = ApiLoggingHandler.CalculateTimeUntil(DateTime.Now, ApiLoggingHandler.Today);
            var actual = span.Hours;

            Debug.WriteLine(actual);
            Debug.WriteLine(DateTime.Now.Add(span));
            Assert.That(actual, Is.GreaterThan(0));
            Assert.That(actual, Is.LessThan(24));
        }