private PersistentSessionHttpClient LoginToPizzaProvider(string username, string password) { var client = new PersistentSessionHttpClient(); var loginPostForm = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("email", username), new KeyValuePair <string, string>("passwd", password), new KeyValuePair <string, string>("back", "identity"), new KeyValuePair <string, string>("SubmitLogin", "") }; var response = client.Post(loginPage, loginPostForm); var content = response.Content.ReadAsStringAsync().Result; // Failed to login - page was not redirected to identity page if (!content.Contains("<title>Identity - CarusoPizza</title>")) { throw new PizzaProviderException($"Failed to login user '{username}'. Check that password is correct, try to log via web on {loginPage}"); } DebugContent.WriteToHtmlFile(content); return(client); }
public void OrderPizza(string username, string password, List <string> pizzaNames) { email = username; httpClient = LoginToPizzaProvider(username, password); pizzaNames.ForEach(AddToCart); sessionToken = GetToken(); var orderData = GetOrderData(); if (orderData.Summary.products.Count != pizzaNames.Count) { throw new PizzaProviderException($"Failed to order. Incorrect count of products. Cart items: {string.Join(", ",orderData.Summary.products.Select(p => p.legend))}. Expected items: {string.Join(", ", pizzaNames)}"); } ConfirmOrder(orderData.Summary.Delivery); }