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 ArgumentNullException(nameof(Json), @"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")); Api = new VkApi { Browser = browser.Object }; Api.Authorize(new ApiAuthParams { ApplicationId = 1, Login = "******", Password = "******", Settings = Settings.All }); Api.RequestsPerSecond = 10000; // Чтобы тесты быстрее выполнялись }
public AuthorizationResult Validate(string validateUrl, string phoneNumber) { var dlg = new AuthenticationView(); dlg.webBrowser.Navigate(validateUrl); dlg.webBrowser.Navigated += (sender, args) => { var result = VkAuthorization.From(args.Uri.AbsoluteUri); if (!result.IsAuthorized) { return; } dlg.Auth = new AuthorizationResult { AccessToken = result.AccessToken, ExpiresIn = result.ExpiresIn, UserId = result.UserId, State = result.State }; dlg.Close(); }; dlg.ShowDialog(); return(dlg.Auth); }
public AuthorizationResult Authorize() { var dlg = new AuthenticationView(); dlg.webBrowser.Navigate( CreateAuthorizeUrl(_authParams.ApplicationId, _authParams.Settings.ToUInt64(), Display.Mobile, "123456")); dlg.webBrowser.Navigated += (sender, args) => { var result = VkAuthorization.From(args.Uri.AbsoluteUri); if (!result.IsAuthorized) { return; } dlg.Auth = new AuthorizationResult { AccessToken = result.AccessToken, ExpiresIn = result.ExpiresIn, UserId = result.UserId, State = result.State }; dlg.Close(); }; dlg.ShowDialog(); return(dlg.Auth); }
public void Authorize_BadUserId_ThrowVkApiException() { const string urlWithBadUserId = "http://oauth.vk.com/blank.html#access_token=token&expires_in=86400&user_id=4793858sd"; var authorization = VkAuthorization.From(new Uri(urlWithBadUserId)); long userId = authorization.UserId; }
public void Authorize_InvalidLoginOrPassword_NotAuthorizedAndAuthorizationNotRequired() { const string urlWithBadLoginOrPassword = "******"; var authorization = VkAuthorization.From(new Uri(urlWithBadLoginOrPassword)); Assert.IsFalse(authorization.IsAuthorized); Assert.IsFalse(authorization.IsAuthorizationRequired); }
public void CorrectParseInputString() { var auth = VkAuthorization.From(Input); Assert.AreEqual(auth.AccessToken, "bf81b33c4f88f45c5e2fa3874054c3c7ae1cb0c632583ca3d9d0d949d4123d8c2c4d7069d9066eceaf815"); Assert.AreEqual(auth.ExpiresIn, 86400); Assert.AreEqual(auth.UserId, 32190123L); Assert.AreEqual(auth.Email, "*****@*****.**"); }
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(error.Message, "ExpiresIn is not integer value."); }
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 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 CorrectParseInputString() { var auth = VkAuthorization.From(uriFragment: Input); Assert.AreEqual(expected: "token" , 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 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)); }
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(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 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 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_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), 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; // Чтобы тесты быстрее выполнялись }
public void IsAuthorized_Success() { var auth = VkAuthorization.From(Input); Assert.IsTrue(auth.IsAuthorized); }
public void IsAuthorizationRequired_False() { var auth = VkAuthorization.From(uriFragment: Input); Assert.IsFalse(condition: auth.IsAuthorizationRequired); }
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 IsAuthorized_Failed() { var auth = VkAuthorization.From(Input.Replace("access_token", "qwe")); Assert.IsFalse(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); }