public void ParseMultipleForms() { // Arrange const string html = @" <html><body> <form action=""/testing"" name=""form1""> <input type=""hidden"" name=""test1"" value=""testvalue1""></input> <input type=""hidden"" name=""test2"" value=""testvalue2""/> <input type='hidden' name='test3' value='testvalue3'/> </form> <form action=""https://www.testing.test/testing""> <input type=""hidden"" name=""test4"" value=""testvalue4""></input> <input type=""hidden"" name=""test5"" value=""testvalue5""/> <input type='hidden' name='test6' value='testvalue6'/> </form> </body></html>"; var parser = new FormParser(); // Act var forms = parser.ParseForms(html); // Assert Assert.AreEqual(2, forms.Count); Assert.AreEqual(3, forms[0].Fields.Count); Assert.AreEqual(3, forms[1].Fields.Count); }
/// <summary> /// Login to google voice /// </summary> /// <param name="email">Google voice email</param> /// <param name="password">Google voice password</param> public void Login(string email, string password) { if (_isLoggedIn) throw new InvalidOperationException("Already logged in"); if (_isDisposed) throw new ObjectDisposedException(GetType().Name); var formParser = new FormParser(); var loginPageResponse = _webManager.RequestPage(LoginUri); var loginForms = formParser.ParseForms(loginPageResponse.Response); if (loginForms.Count > 1 || !loginForms[0].Fields.ContainsField(EMAIL_FIELD) || !loginForms[0].Fields.ContainsField(PASSWORD_FIELD)) { throw new Exception("Error logging in, expected token not found."); } loginForms[0].Fields[EMAIL_FIELD].Value = email; loginForms[0].Fields[PASSWORD_FIELD].Value = password; var loginPostAddress = WebUtility.Combine(loginForms[0].Action, loginPageResponse.ResponseUri); var loginPostResponse = _webManager.PerformPost(loginPostAddress, loginForms[0].Fields, FormFieldSerializationType.UrlEncoded); var voiceForms = formParser.ParseForms(loginPostResponse.Response); if (voiceForms[0].Fields.ContainsField(RNR_SE_FIELD)) _rnrSe = voiceForms[0].Fields[RNR_SE_FIELD].Value; else throw new Exception("Error logging in, expected token not found."); _isLoggedIn = true; }