Skip to content

Commit

Permalink
#697 Авторизация валидация параметров
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Feb 7, 2019
1 parent 2d27306 commit 447850e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions VkNet.Tests/Infrastructure/ImplicitFlowTests.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,5 +45,36 @@ public void CreateAuthorizeUrl()

Assert.AreEqual(new Url(expected), authorizeUrl);
}

[Test]
public async Task Authorize()
{
var mocker = new AutoMocker();

mocker.Setup<IApiAuthParams, string>(x => x.Login).Returns("login");
mocker.Setup<IApiAuthParams, string>(x => x.Password).Returns("pass");
mocker.Setup<IApiAuthParams, ulong>(x => x.ApplicationId).Returns(4268118);
mocker.Setup<IApiAuthParams, Settings>(x => x.Settings).Returns(Settings.All);

mocker.Setup<IVkApiVersionManager, string>(x => x.Version).Returns("5.92");

var implicitFlow = mocker.CreateInstance<ImplicitFlow>();
var result = await implicitFlow.AuthorizeAsync().ConfigureAwait(false);

Assert.NotNull(result);
}

[Test]
public async Task Authorize_ValidateError()
{
var mocker = new AutoMocker();

mocker.Setup<IApiAuthParams, string>(x => x.Login).Returns("login");

mocker.Setup<IVkApiVersionManager, string>(x => x.Version).Returns("5.92");

var implicitFlow = mocker.CreateInstance<ImplicitFlow>();
Assert.ThrowsAsync<VkAuthorizationException>(() => implicitFlow.AuthorizeAsync());
}
}
}
6 changes: 3 additions & 3 deletions VkNet/Utils/ImplicitFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public async Task<AuthorizationResult> AuthorizeAsync()

if (!httpResponseMessage.IsSuccessStatusCode)
{
throw new VkAuthorizationException();
throw new VkAuthorizationException(httpResponseMessage.ReasonPhrase);
}

return null;
return new AuthorizationResult();
}

/// <inheritdoc />
Expand Down Expand Up @@ -111,7 +111,7 @@ private void ValidateAuthorizationParameters()

if (!string.IsNullOrWhiteSpace(errors))
{
throw new VkApiException(errors);
throw new VkAuthorizationException(errors);
}
}
}
Expand Down

0 comments on commit 447850e

Please sign in to comment.