Skip to content

Commit

Permalink
✅ Implements some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardbr committed Dec 21, 2021
1 parent 217c0bf commit 947b46b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion test/unitario/DigestAuthenticator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<PackageId>RestSharp.Authenticators.Digest.Tests</PackageId>
<RootNamespace>RestSharp.Authenticators.Digest.Tests</RootNamespace>
<GenerateFullPaths>true</GenerateFullPaths>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down Expand Up @@ -36,6 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DigestAuthenticator\DigestAuthenticator.csproj" />
Expand Down
59 changes: 33 additions & 26 deletions test/unitario/DigestTest.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace RestSharp.Authenticators.Digest.Tests
namespace RestSharp.Authenticators.Digest.Tests;

/// <summary>
/// The integration tests for <see cref="DigestAuthenticator" />.
/// </summary>
[Trait("Category", "IntegrationTests")]
[Trait("Class", nameof(DigestAuthenticator))]
public class DigestTest
{
/// <summary>
/// The integration tests for <see cref="DigestAuthenticator"/>.
/// </summary>
[Trait("Category", "IntegrationTests")]
[Trait("Class", nameof(DigestAuthenticator))]
public class DigestTest
[SkippableFact]
public void Given_ADigestAuthEndpoint_When_ITryToGetInfo_Then_TheAuthMustBeResolved()
{
/// <summary>
/// Given an digest auth endpoint, When I try to get info, Then the auth must be resolved.
/// </summary>
[Fact]
public void Given_AnDigestAuthEndpoint_When_ITryToGetInfo_Then_TheAuthMustBeResolved()
Skip.IfNot(Debugger.IsAttached);

var client = new RestClient("http://localhost:49896/api")
{
var client = new RestClient("http://localhost:49896/api")
{
Authenticator = new DigestAuthenticator("eddie", "starwars123")
};
Authenticator = new DigestAuthenticator("eddie", "starwars123")
};

var request = new RestRequest("values", Method.GET);
request.AddHeader("Content-Type", "application/json");
var request = new RestRequest("values", Method.GET);
request.AddHeader("Content-Type", "application/json");

var response = client.Execute(request);
var response = client.Execute(request);

response.StatusCode.Should().Be(HttpStatusCode.OK);
}
response.StatusCode.Should().Be(HttpStatusCode.OK);
}

[Theory]
[InlineData(
"Digest realm=\"test - realm\", nonce=\"2021 - 12 - 21 13:40:54.513311Z f152e55bf3d14e28b90f47db5dbd8afb\", qop=\"auth\", algorithm=MD5")]
[InlineData(
"realm=\"test - realm\", nonce=\"2021 - 12 - 21 13:40:54.513311Z f152e55bf3d14e28b90f47db5dbd8afb\", qop=\"auth\", algorithm=MD5")]
public void Given_ADigestAuthenticateHeader_When_ITryCreateObject_Then_AllPropsMustBeFilled(string header)
{
var digestHeader = new DigestHeader(header);
digestHeader.Nonce.Should().Be("2021 - 12 - 21 13:40:54.513311Z f152e55bf3d14e28b90f47db5dbd8afb");
digestHeader.Qop.Should().Be("auth");
digestHeader.Realm.Should().Be("test - realm");
}
}

0 comments on commit 947b46b

Please sign in to comment.