diff --git a/Vonage.Test.Unit/VerifyV2/StartVerification/SerializationTest.cs b/Vonage.Test.Unit/VerifyV2/StartVerification/SerializationTest.cs index 9a6b4f0b1..a535f80da 100644 --- a/Vonage.Test.Unit/VerifyV2/StartVerification/SerializationTest.cs +++ b/Vonage.Test.Unit/VerifyV2/StartVerification/SerializationTest.cs @@ -84,12 +84,12 @@ public void ShouldSerializeSilentAuthWorkflow() => .GetStringContent() .Should() .BeSuccess(this.helper.GetRequestJson()); - + [Fact] public void ShouldSerializeSilentAuthWorkflowWithRedirectUrl() => StartVerificationRequest.Build() .WithBrand("ACME, Inc") - .WithWorkflow(SilentAuthWorkflow.Parse("447700900000", "https://acme-app.com/sa/redirect")) + .WithWorkflow(SilentAuthWorkflow.Parse("447700900000", new Uri("https://acme-app.com/sa/redirect"))) .Create() .GetStringContent() .Should() diff --git a/Vonage.Test.Unit/VerifyV2/StartVerification/Workflows/SilentAuthWorkflowTest.cs b/Vonage.Test.Unit/VerifyV2/StartVerification/Workflows/SilentAuthWorkflowTest.cs index df7520c4b..17162b89c 100644 --- a/Vonage.Test.Unit/VerifyV2/StartVerification/Workflows/SilentAuthWorkflowTest.cs +++ b/Vonage.Test.Unit/VerifyV2/StartVerification/Workflows/SilentAuthWorkflowTest.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System; +using FluentAssertions; using Vonage.Common.Failures; using Vonage.Common.Test.Extensions; using Vonage.VerifyV2.StartVerification.SilentAuth; @@ -32,12 +33,9 @@ public void Parse_ShouldReturnSuccess() => workflow.RedirectUrl.Should().BeNone(); }); - [Theory] - [InlineData("")] - [InlineData(" ")] - [InlineData(null)] - public void Parse_ShouldReturnSuccess_GivenRedirectIsNullOrWhitespace(string value) => - SilentAuthWorkflow.Parse(ValidNumber, value) + [Fact] + public void Parse_ShouldReturnSuccess_GivenRedirectIsNull() => + SilentAuthWorkflow.Parse(ValidNumber, null) .Should() .BeSuccess(workflow => { @@ -47,14 +45,14 @@ public void Parse_ShouldReturnSuccess_GivenRedirectIsNullOrWhitespace(string val }); [Fact] - public void Parse_ShouldreturnSuccessWithRedirect() => - SilentAuthWorkflow.Parse(ValidNumber, ValidRedirectUrl) + public void Parse_ShouldReturnSuccessWithRedirect() => + SilentAuthWorkflow.Parse(ValidNumber, new Uri(ValidRedirectUrl)) .Should() .BeSuccess(workflow => { workflow.Channel.Should().Be(ExpectedChannel); workflow.To.Number.Should().Be(ValidNumber); - workflow.RedirectUrl.Should().BeSome(ValidRedirectUrl); + workflow.RedirectUrl.Should().BeSome(new Uri(ValidRedirectUrl)); }); } } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs b/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs index a00196950..2550c0f2c 100644 --- a/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/SilentAuth/SilentAuthWorkflow.cs @@ -1,8 +1,8 @@ +using System; using System.Text.Json.Serialization; using Vonage.Common; using Vonage.Common.Monads; using Vonage.Common.Serialization; -using Vonage.Common.Validation; namespace Vonage.VerifyV2.StartVerification.SilentAuth; @@ -11,16 +11,24 @@ namespace Vonage.VerifyV2.StartVerification.SilentAuth; /// public readonly struct SilentAuthWorkflow : IVerificationWorkflow { - private SilentAuthWorkflow(PhoneNumber to, string redirectUrl = null) + private SilentAuthWorkflow(PhoneNumber to, Uri redirectUrl = null) { this.To = to; - this.RedirectUrl = string.IsNullOrWhiteSpace(redirectUrl) ? Maybe.None : redirectUrl; + this.RedirectUrl = redirectUrl ?? Maybe.None; } /// [JsonPropertyOrder(0)] public string Channel => "silent_auth"; + /// + /// Final redirect added at the end of the check_url request/response lifecycle. See the documentation for integrations. Will contain the request_id and code as a url fragment after the URL. + /// + [JsonPropertyOrder(2)] + [JsonConverter(typeof(MaybeJsonConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public Maybe RedirectUrl { get; } + /// /// The phone number to use for authentication, in the E.164 format. Don't use a leading + or 00 when entering a phone /// number, start with the country code, for example, 447700900000. @@ -29,14 +37,6 @@ private SilentAuthWorkflow(PhoneNumber to, string redirectUrl = null) [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } - /// - /// Final redirect added at the end of the check_url request/response lifecycle. See the documentation for integrations. Will contain the request_id and code as a url fragment after the URL. - /// - [JsonPropertyOrder(2)] - [JsonConverter(typeof(MaybeJsonConverter))] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public Maybe RedirectUrl { get; } - /// /// Parses the input into a SilentAuthWorkflow. /// @@ -51,9 +51,9 @@ public static Result Parse(string to) => /// The phone number to use for authentication. /// The final redirect added at the end of the check_url request/response lifecycle /// Success or failure. - public static Result Parse(string to, string redirectUrl) => + public static Result Parse(string to, Uri redirectUrl) => PhoneNumber.Parse(to).Map(phoneNumber => new SilentAuthWorkflow(phoneNumber, redirectUrl)); - + /// public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this); } \ No newline at end of file