Пример #1
0
        public async Task QueryListingsWithTuin_OK_WholeListReturned()
        {
            // Arrange
            var fundaClient = new FundaClient(mockedHttpClient);

            // Act
            var listings = await fundaClient.Query("koop", "amsterdam", "tuin");

            // Assert
            var expectedUri = new Uri($"http://partnerapi.funda.nl/feeds/Aanbod.svc/json/ac1b0b1572524640a0ecc54de453ea9f/");

            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(34),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get &&
                                               req.RequestUri.AbsolutePath == expectedUri.AbsolutePath &&
                                               HttpUtility.ParseQueryString(req.RequestUri.Query).Get("type") == "koop" &&
                                               HttpUtility.ParseQueryString(req.RequestUri.Query).Get("zo") == "/amsterdam/tuin/"
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );

            // The response says 849, but we aren't changing the last page to return 24 items, so the total is greater.
            // In the real API this count would be right.
            Assert.Equal(850, listings.Count());
        }
Пример #2
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddLogging();
     // We use a singleton rate limiter for shared rate limiting across all clients within
     // the process.
     services.AddSingleton(FundaClient.ConstructRateLimiter());
     services.AddHttpClient <FundaClient>(client =>
     {
         client.BaseAddress = FundaClient.ConstructBaseUri(
             Configuration.GetValue <string>("token")
             ?? throw new ArgumentNullException("Please configure Funda token."));
     });
     services.AddTransient <IAgentRepository, FundaAgentRepository>();
     services.AddSingleton <IMemoryCache, MemoryCache>();
     services.AddControllers();
 }
 public FundaAgentRepository(FundaClient client, ILogger <FundaAgentRepository> logger)
 {
     this.client = client;
     this.logger = logger;
 }