From 447850e090fda865485ad34b3e6229f93a0bf422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BD=D1=8E=D1=82=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Fri, 8 Feb 2019 00:40:37 +0300 Subject: [PATCH] =?UTF-8?q?#697=20=D0=90=D0=B2=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Infrastructure/ImplicitFlowTests.cs | 34 +++++++++++++++++++ VkNet/Utils/ImplicitFlow.cs | 6 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) 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); } } }