diff --git a/VkNet.Tests/Infrastructure/ImplicitFlowTests.cs b/VkNet.Tests/Infrastructure/ImplicitFlowTests.cs index 0199d5653..9c6a2d167 100644 --- a/VkNet.Tests/Infrastructure/ImplicitFlowTests.cs +++ b/VkNet.Tests/Infrastructure/ImplicitFlowTests.cs @@ -1,10 +1,13 @@ using System.Text; +using System.Threading.Tasks; using Flurl; using Moq.AutoMock; using NUnit.Framework; using VkNet.Abstractions.Core; using VkNet.Enums.Filters; using VkNet.Enums.SafetyEnums; +using VkNet.Exception; +using VkNet.Model; using VkNet.Utils; namespace VkNet.Tests.Infrastructure @@ -42,5 +45,36 @@ public void CreateAuthorizeUrl() Assert.AreEqual(new Url(expected), authorizeUrl); } + + [Test] + public async Task Authorize() + { + var mocker = new AutoMocker(); + + mocker.Setup(x => x.Login).Returns("login"); + mocker.Setup(x => x.Password).Returns("pass"); + mocker.Setup(x => x.ApplicationId).Returns(4268118); + mocker.Setup(x => x.Settings).Returns(Settings.All); + + mocker.Setup(x => x.Version).Returns("5.92"); + + var implicitFlow = mocker.CreateInstance(); + var result = await implicitFlow.AuthorizeAsync().ConfigureAwait(false); + + Assert.NotNull(result); + } + + [Test] + public async Task Authorize_ValidateError() + { + var mocker = new AutoMocker(); + + mocker.Setup(x => x.Login).Returns("login"); + + mocker.Setup(x => x.Version).Returns("5.92"); + + var implicitFlow = mocker.CreateInstance(); + Assert.ThrowsAsync(() => implicitFlow.AuthorizeAsync()); + } } } \ No newline at end of file diff --git a/VkNet/Utils/ImplicitFlow.cs b/VkNet/Utils/ImplicitFlow.cs index 7bfe668bb..832a13a34 100644 --- a/VkNet/Utils/ImplicitFlow.cs +++ b/VkNet/Utils/ImplicitFlow.cs @@ -55,10 +55,10 @@ public async Task AuthorizeAsync() if (!httpResponseMessage.IsSuccessStatusCode) { - throw new VkAuthorizationException(); + throw new VkAuthorizationException(httpResponseMessage.ReasonPhrase); } - return null; + return new AuthorizationResult(); } /// @@ -111,7 +111,7 @@ private void ValidateAuthorizationParameters() if (!string.IsNullOrWhiteSpace(errors)) { - throw new VkApiException(errors); + throw new VkAuthorizationException(errors); } } }