forked from thenoobsbr/RestSharp.Authenticators.Digest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigestIntegrationTest.cs
More file actions
67 lines (51 loc) · 2.07 KB
/
Copy pathDigestIntegrationTest.cs
File metadata and controls
67 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using NSubstitute;
using RestSharp.Authenticators.Digest.Tests.Fixtures;
using Xunit;
namespace RestSharp.Authenticators.Digest.Tests;
/// <summary>
/// The integration tests for <see cref="DigestAuthenticator" />.
/// </summary>
[Trait("Category", "IntegrationTests")]
[Trait("Class", nameof(DigestAuthenticator))]
public class DigestIntegrationTest : IClassFixture<DigestServerStub>
{
private readonly DigestServerStub _fixture;
public DigestIntegrationTest(DigestServerStub fixture)
{
_fixture = fixture;
}
[Fact]
public async Task Given_ADigestAuthEndpoint_When_ITryToGetInfo_Then_TheAuthMustBeResolved()
{
var loggerMock = Substitute.For<ILogger>();
loggerMock.BeginScope("DigestServerStub");
var request = new RestRequest("values");
request.AddHeader("Content-Type", "application/json");
var client = _fixture.CreateClient(loggerMock);
var response = await client.ExecuteAsync(request);
response.StatusCode.Should().Be(HttpStatusCode.OK);
loggerMock.ReceivedWithAnyArgs().LogDebug("NONONO");
}
[Fact]
public async Task Given_ADigestAuthEndpoint_When_ITryToInjectOwnClient_Then_TheAuthMustBeResolved()
{
bool proxyCalled = false;
var loggerMock = Substitute.For<ILogger>();
loggerMock.BeginScope("DigestServerStub");
var request = new RestRequest("values");
request.AddHeader("Content-Type", "application/json");
RestClientOptions options = new RestClientOptions()
{
Proxy = new TestProxy(() => proxyCalled = true)
};
var client = _fixture.CreateInjectedOptionClient(loggerMock, options);
var response = await client.ExecuteAsync(request);
response.StatusCode.Should().Be(HttpStatusCode.OK);
loggerMock.ReceivedWithAnyArgs().LogDebug("NONONO");
Assert.True(proxyCalled, "Injected RestClientOptions.Proxy should be used in digest handshake.");
}
}