public void CorrectParseInputString() { var auth = VkAuthorization.From(uriFragment: Input); Assert.AreEqual(expected: "bf81b33c4f88f45c5e2fa3874054c3c7ae1cb0c632583ca3d9d0d949d4123d8c2c4d7069d9066eceaf815" , actual: auth.AccessToken); Assert.AreEqual(expected: 86400, actual: auth.ExpiresIn); Assert.AreEqual(expected: 32190123L, actual: auth.UserId); Assert.AreEqual(expected: "*****@*****.**", actual: auth.Email); }
public void GetUserId_Exception() { var auth = VkAuthorization.From(Input.Replace("32190123", "qwe")); var error = Assert.Throws <VkApiException>(() => { var authUserId = auth.UserId; Assert.NotZero(authUserId); }); Assert.AreEqual(error.Message, "UserId is not long value."); }
public void CorrectParseInputString() { var auth = VkAuthorization.From(Input); Assert.AreEqual("token" , auth.AccessToken); Assert.AreEqual(86400, auth.ExpiresIn); Assert.AreEqual(32190123L, auth.UserId); Assert.AreEqual("*****@*****.**", auth.Email); }
public void GetExpiresIn_Exception() { var auth = VkAuthorization.From(uriFragment: Input.Replace(oldValue: "86400", newValue: "qwe")); var error = Assert.Throws <VkApiException>(code: () => { var expiresIn = auth.ExpiresIn; Assert.NotZero(actual: expiresIn); }); Assert.AreEqual(expected: "ExpiresIn is not integer value.", actual: error.Message); }
public void GetUserId_Exception() { var auth = VkAuthorization.From(uriFragment: Input.Replace(oldValue: "32190123", newValue: "qwe")); var error = Assert.Throws <VkApiException>(code: () => { var authUserId = auth.UserId; Assert.NotZero(actual: authUserId); }); Assert.AreEqual(expected: "UserId is not long value.", actual: error.Message); }
public void GetExpiresIn_Exception() { var auth = VkAuthorization.From(Input.Replace("86400", "qwe")); var error = Assert.Throws <VkApiException>(() => { var expiresIn = auth.ExpiresIn; Assert.NotZero(expiresIn); }); Assert.AreEqual("ExpiresIn is not integer value.", error.Message); }
public void Authorize_RightInput_AccessToken() { const string returnUrl = "http://oauth.vk.com/blank.html#access_token=token&expires_in=86400&user_id=4793858"; var authorization = VkAuthorization.From(new Uri(returnUrl)); Assert.IsTrue(authorization.IsAuthorized); Assert.That(authorization.AccessToken, Is.EqualTo("token")); Assert.That(authorization.ExpiresIn, Is.EqualTo("86400")); Assert.That(authorization.UserId, Is.EqualTo(4793858)); }
private async void OnWebNavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { while (NotificationIds.Count > 0) { Context.HideProgress(NotificationIds[0]); NotificationIds.RemoveAt(0); } if (!args.Uri.ToString().StartsWith(VkAuthorization.GetRedirectUrl())) { return; } await TryFinishAuthorizationAsync(args.Uri); }
public void Authorize_BadUserId_ThrowVkApiException() { // TODO [ExpectedException(typeof(VkApiException), ExpectedMessage = "UserId is not integer value.")] const string urlWithBadUserId = "http://oauth.vk.com/blank.html#access_token=token&expires_in=86400&user_id=4793858sd"; var ex = Assert.Throws <VkApiException>(() => { var authorization = VkAuthorization.From(new Uri(urlWithBadUserId)); var userId = authorization.UserId; }); Assert.That(ex.Message, Is.EqualTo("UserId is not integer value.")); }
public void Setup_token_from_url() { var auth = new VkAuthorization(); var token = new AccessToken(); Assert.That(token.Token, Is.EqualTo(null).Or.EqualTo(string.Empty)); Assert.That(token.UserID, Is.EqualTo(0)); var response = auth.TryToSetupTokenFromUrl(token, exampleUrlCorrectAnswer); Assert.That(response.Successful, Is.True); Assert.That(token.Token, Is.EqualTo(EXAMPLE_TOKEN)); Assert.That(token.UserID, Is.EqualTo(EXAMPLE_USERID)); }
public void IsAuthorizationRequired_True() { const string uriQuery = "https://oauth.vk.com/authorize" + "?client_id=4268118" + "&redirect_uri=https:%2F%2Foauth.vk.com%2Fblank.html" + "&response_type=token" + "&scope=140426399" + "&v=" + "&state=" + "&display=page" + "&__q_hash=90f3ddf308ca69fca660e32b09e3617b"; var auth = VkAuthorization.From(uriQuery); Assert.IsTrue(auth.IsAuthorizationRequired); }
public void Authorize(bool clearCookies) { _eventAggregator.GetEvent <AuthBarEvents.AuthorizeRequest>().Publish(); //var accessToken = App.Container.GetInstance<AccessToken>(); //var authWindow = new AuthView(accessToken, clearCookies); if (clearCookies) { VkAuthorization.ClearCookies(); } var authWindow = new AuthView();//App.Container.GetInstance<AuthView>(); authWindow.Action = AuthAction.Authorize; authWindow.ShowDialog(); //_regionManager.RequestNavigate(RegionNames.MainRegion, $"VkAuthorization?clearcookies={clearCookies}"); }
public void Authorize_InvalidLoginOrPassword_NotAuthorizedAndAuthorizationNotRequired() { const string urlWithBadLoginOrPassword = "******" + "?client_id=1" + "&redirect_uri=http%3A%2F%2Foauth.vk.com%2Fblank.html" + "&response_type=token" + "&scope=2" + "&v=" + "&state=" + "&display=wap" + "&m=4" + "&email=mail"; var authorization = VkAuthorization.From(uriFragment: urlWithBadLoginOrPassword); Assert.IsFalse(condition: authorization.IsAuthorized); Assert.IsFalse(condition: authorization.IsAuthorizationRequired); }
public void Init() { var browser = new Mock <IBrowser>(); browser.Setup(m => m.GetJson(It.Is <string>(s => s == Url))) .Callback(Callback) .Returns(() => { if (string.IsNullOrWhiteSpace(Json)) { throw new ArgumentNullException(nameof(Json), @"Json не может быть равен null. Обновите значение поля Json"); } return(Json); }); browser.Setup(o => o.Authorize( It.IsAny <ulong>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Settings>(), It.IsAny <Func <string> >(), It.IsAny <long?>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <string>() ) ) .Returns(VkAuthorization.From(new Uri("https://vk.com/auth?__q_hash=qwerty&access_token=token&expires_in=1000&user_id=1"))); Api = new VkApi { Browser = browser.Object }; Api.Authorize(new ApiAuthParams { ApplicationId = 1, Login = "******", Password = "******", Settings = Settings.All }); Api.RequestsPerSecond = 10000; // Чтобы тесты быстрее выполнялись }
//todo: деавторизация не работает! public void Deauthorize() { _eventAggregator.GetEvent <AuthBarEvents.LogOutRequest>().Publish(); IsAuthorized = false; UserName = string.Empty; SetUpAvatar(DEFAULT_AVATAR); _vkApi.Token.Set(new AccessToken()); var authWindow = new AuthView();//App.Container.GetInstance<AuthView>(); authWindow.Action = AuthAction.Deauthorize; authWindow.ShowDialog(); VkAuthorization.ClearAllCookies(); //App.SuppressWininetBehavior(); _eventAggregator.GetEvent <AuthBarEvents.LogOutCompleted>().Publish(); }
public UserSongsGet(string login, string password) { var vkAuthorization = new VkAuthorization(login, password); _vkApi = vkAuthorization.Authorize(); }
private void NavigateToAuthorizationPage() { var destinationUrl = VkAuthorization.GetAuthorizationUri(); WebAdress = destinationUrl.ToString(); }
public VkAudioService() { var vkAuthorization = new VkAuthorization(); _vkApi = vkAuthorization.Authorize(); }
public void IsAuthorizationRequired_False() { var auth = VkAuthorization.From(uriFragment: Input); Assert.IsFalse(condition: auth.IsAuthorizationRequired); }
public VkAudioService(string login, string password) { var vkAuthorization = new VkAuthorization(login, password); _vkApi = vkAuthorization.Authorize(); }
public void IsAuthorized_Success() { var auth = VkAuthorization.From(Input); Assert.IsTrue(auth.IsAuthorized); }
public void IsAuthorized_Failed() { var auth = VkAuthorization.From(Input.Replace("access_token", "qwe")); Assert.IsFalse(auth.IsAuthorized); }
public void IsAuthorized_Success() { var auth = VkAuthorization.From(uriFragment: Input); Assert.IsTrue(condition: auth.IsAuthorized); }
public void IsAuthorized_Failed() { var auth = VkAuthorization.From(uriFragment: Input.Replace(oldValue: "access_token", newValue: "qwe")); Assert.IsFalse(condition: auth.IsAuthorized); }
public void IsAuthorizationRequired_False() { var auth = VkAuthorization.From(Input); Assert.IsFalse(auth.IsAuthorizationRequired); }
public void Authorize_BadLoginOrPasswrod_ThrowVkApiAuthorizationException() { const string urlWithBadLoginOrPassword = "******"; var browser = new Mock <IBrowser>(); browser.Setup(b => b.Authorize(AppId, Email, Password, Settings.Friends)).Returns(VkAuthorization.From(new Uri(urlWithBadLoginOrPassword))); _vk.Browser = browser.Object; var ex = This.Action(() => _vk.Authorize(AppId, Email, Password, Settings.Friends)).Throws <VkApiAuthorizationException>(); ex.Message.ShouldEqual(VkApi.InvalidAuthorization); }
public AuthViewModel(IEventAggregator eventAggregator, AccessToken token, VkAuthorization vkAuthorization) { _eventAggregator = eventAggregator; _token = token; _vkAuthorization = vkAuthorization; }
public void Init() { var browser = new Mock <IBrowser>(); browser.Setup(m => m.GetJson(It.Is <string>(s => s == Url), It.IsAny <IEnumerable <KeyValuePair <string, string> > >())) .Callback(Callback) .Returns(() => { if (string.IsNullOrWhiteSpace(Json)) { throw new NullReferenceException(@"Json не может быть равен null. Обновите значение поля Json"); } return(Json); }); browser.Setup(o => o.Authorize(It.IsAny <IApiAuthParams>())) .Returns(VkAuthorization.From("https://vk.com/auth?__q_hash=qwerty&access_token=token&expires_in=1000&user_id=1")); browser.Setup(m => m.Validate(It.IsAny <string>(), It.IsAny <string>())) .Returns(VkAuthorization.From("https://oauth.vk.com/blank.html#success=1&access_token=token&user_id=1")); var restClient = new Mock <IRestClient>(); restClient.Setup(x => x.PostAsync(It.Is <Uri>(s => s == new Uri(Url)), It.IsAny <IEnumerable <KeyValuePair <string, string> > >())) .Callback(Callback) .Returns(() => { if (string.IsNullOrWhiteSpace(Json)) { throw new NullReferenceException(@"Json не может быть равен null. Обновите значение поля Json"); } return(Task.FromResult(HttpResponse <string> .Success(HttpStatusCode.OK, Json, Url))); }); restClient.Setup(x => x.PostAsync(It.Is <Uri>(s => string.IsNullOrWhiteSpace(Url)), It.IsAny <IEnumerable <KeyValuePair <string, string> > >())) .Throws <ArgumentException>(); Api = new VkApi { Browser = browser.Object, RestClient = restClient.Object }; Api.Authorize(new ApiAuthParams { ApplicationId = 1, Login = "******", Password = "******", Settings = Settings.All }); Api.RequestsPerSecond = 100000; // Чтобы тесты быстрее выполнялись }
private SongInfo GetLyricsAndSongInfoByVK(File audioFile, string fileName) { var authorize = new VkAuthorization(); var api = authorize.Authorize(); var songLyricsAndInfoGetter = new SongLyricsAndInfoGetter(api); var titleEncoded = audioFile.Tag.Title.ToUtf8(); var artistEncoded = audioFile.Tag.Artists.ConvertStringArrayToString().ToUtf8(); if (string.IsNullOrEmpty(titleEncoded) == false) { var info = songLyricsAndInfoGetter.GetSongInfo(artistEncoded + " " + titleEncoded); if (info != null) { return info; } } if (string.IsNullOrEmpty(fileName) == false) { var info = songLyricsAndInfoGetter.GetSongInfo(fileName); if (info != null) { return info; } } return null; }