Ejemplo n.º 1
0
    public void RequestUrlCombinedCorrectlyWithoutSlashInBase()
    {
        //arrange
        var config     = new ServerConfig(new Uri("http://localhost"), Guid.NewGuid().ToString());
        var httpClient = Substitute.For <HttpClient>();

        //act
        var agent = new StubAgent(config, httpClient);

        //assert
        Assert.Equal("http://localhost/requests", agent.RequestUrl.AbsoluteUri);
    }
Ejemplo n.º 2
0
    public void HttpClientIsDisposedOnDispose()
    {
        //arrange
        var config     = new ServerConfig(new Uri("http://localhost/"), Guid.NewGuid().ToString());
        var httpClient = Substitute.For <HttpClient>();
        var agent      = new StubAgent(config, httpClient);

        //act
        agent.Dispose();

        //assert
        httpClient.ReceivedWithAnyArgs().Dispose();
    }
Ejemplo n.º 3
0
    public void APIKeyAddedToAuthHeader()
    {
        //arrange
        var apiKey     = Guid.NewGuid();
        var config     = new ServerConfig(new Uri("http://localhost/"), apiKey.ToString());
        var httpClient = Substitute.For <HttpClient>();

        //act
        var agent = new StubAgent(config, httpClient);

        //assert
        var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(apiKey.ToString()));

        Assert.Contains(base64, agent.HttpClient.DefaultRequestHeaders.Authorization?.ToString() ?? string.Empty);
    }