From 947b46b91880d7de7682811b07702e6b1aa04473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardo=20Esb=C3=A9rard?= Date: Tue, 21 Dec 2021 12:28:22 -0300 Subject: [PATCH] :white_check_mark: Implements some tests. --- .../unitario/DigestAuthenticator.Tests.csproj | 2 +- test/unitario/DigestTest.cs | 59 +++++++++++-------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/test/unitario/DigestAuthenticator.Tests.csproj b/test/unitario/DigestAuthenticator.Tests.csproj index ad479d7..13f32d7 100644 --- a/test/unitario/DigestAuthenticator.Tests.csproj +++ b/test/unitario/DigestAuthenticator.Tests.csproj @@ -5,7 +5,6 @@ RestSharp.Authenticators.Digest.Tests RestSharp.Authenticators.Digest.Tests true - bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml Exe @@ -36,6 +35,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + diff --git a/test/unitario/DigestTest.cs b/test/unitario/DigestTest.cs index 2675b27..9b23162 100644 --- a/test/unitario/DigestTest.cs +++ b/test/unitario/DigestTest.cs @@ -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; + +/// +/// The integration tests for . +/// +[Trait("Category", "IntegrationTests")] +[Trait("Class", nameof(DigestAuthenticator))] +public class DigestTest { - /// - /// The integration tests for . - /// - [Trait("Category", "IntegrationTests")] - [Trait("Class", nameof(DigestAuthenticator))] - public class DigestTest + [SkippableFact] + public void Given_ADigestAuthEndpoint_When_ITryToGetInfo_Then_TheAuthMustBeResolved() { - /// - /// Given an digest auth endpoint, When I try to get info, Then the auth must be resolved. - /// - [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"); } }