public void TestInsertUpdateErrors() { Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Test insert Producer producer = new Producer(); string jsonTicket = javaScriptSerializer.Serialize(producer); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); //Test insert HttpResponseMessage response = client.PostAsJsonAsync(insertAction, producer).Result; Assert.IsTrue(response.IsSuccessStatusCode); ProducerResponse producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsFalse(producerResponse.Success); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidName)); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidCivilStatus)); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidGender)); //Test update response = client.PostAsJsonAsync(updateAction, producer).Result; Assert.IsTrue(response.IsSuccessStatusCode); producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsFalse(producerResponse.Success); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidName)); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidCivilStatus)); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidGender)); }
public void TestGetBasicModels() { Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); //get all HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.GetAsync(getSelectableModelsAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetSelectableModelResponse getSelectableModelResponse = response.Content.ReadAsAsync <GetSelectableModelResponse>().Result; Assert.IsTrue(getSelectableModelResponse.Success); Assert.IsTrue(getSelectableModelResponse.SelectableModels.Count > 0); }
public void TestDeleteErrors() { Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); //Test delete HttpResponseMessage response = client.PostAsJsonAsync(deleteAction, new IdModel(0)).Result; Assert.IsTrue(response.IsSuccessStatusCode); ProducerResponse producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsFalse(producerResponse.Success); Assert.IsTrue(producerResponse.ErrorCode.HasFlag(ProducerError.InvalidId)); }
public void TestGetErrors() { Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); //Test get by id string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, 0); HttpResponseMessage response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetProducerResponse getProducerResponse = response.Content.ReadAsAsync <GetProducerResponse>().Result; Assert.IsFalse(getProducerResponse.Success); Assert.IsTrue(getProducerResponse.ErrorCode.HasFlag(ProducerError.InvalidId)); }
public void TestGetWeightTicketsProducts() { //Get token Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.GetAsync(getGetWeightTicketProductsAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetProductResponse getProductResponse = response.Content.ReadAsAsync <GetProductResponse>().Result; Assert.IsTrue(getProductResponse.Success); Assert.IsTrue(getProductResponse.Products.Count > 0); }
public SettlementApiTest() { baseUrl = @"http://lasmargaritasdev.azurewebsites.net/"; if (ConfigurationManager.AppSettings["baseUrl"] != null) { baseUrl = ConfigurationManager.AppSettings["baseUrl"]; } insertAction = "Settlement/Add"; insertWeightTicketAction = "Settlement/Add"; insertPaymentAction = "Settlement/AddSettlementPayment"; removePaymentsAction = "Settlement/RemoveAllSettlementPayments"; getPaymentsAction = "Settlement/GetSettlementPayments"; updateAction = "Settlement/Update"; deleteAction = "Settlement/Delete"; getAllAction = "Settlement/GetAll"; getByIdAction = "Settlement/GetById"; getReportAction = "Settlement/GetWeightTicketsReport"; token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); }
public void TestInsertUpdateErrors() { Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Test insert Cicle cicle = new Cicle(); string jsonTicket = javaScriptSerializer.Serialize(cicle); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); //Test insert HttpResponseMessage response = client.PostAsJsonAsync(insertAction, cicle).Result; Assert.IsTrue(response.IsSuccessStatusCode); CicleResponse cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result; Assert.IsFalse(cicleResponse.Success); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidAmount)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone1)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone2)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidIsClosed)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidStartDate)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidName)); //Test update response = client.PostAsJsonAsync(updateAction, cicle).Result; Assert.IsTrue(response.IsSuccessStatusCode); cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result; Assert.IsFalse(cicleResponse.Success); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidAmount)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone1)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone2)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidIsClosed)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidStartDate)); Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidName)); }
public void TestGetWeightTicketReport() { //Test this one in prod baseUrl = @"http://lasmargaritas.azurewebsites.net/"; Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); WeightTicketReportFilterModel filter = new WeightTicketReportFilterModel(); filter.CicleId = 1; filter.WeightTicketType = (int)WeightTicketType.Producer; HttpResponseMessage response = client.GetAsync(string.Format("{0}?{1}", getReportAction, filter.GetUrlQuery())).Result; response.EnsureSuccessStatusCode(); GetReportDataResponse getReportDataResponse = response.Content.ReadAsAsync <GetReportDataResponse>().Result; Assert.IsTrue(getReportDataResponse.Success); Assert.IsTrue(getReportDataResponse.ReportData != null); // Assert.IsTrue(getReportDataResponse.ReportData.Count > 0); }
public void TestInsertUpdateAndGetProducer() { //Get token Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Test insert Producer producer = ProducerHelper.CreateDummyProducer(); string jsonTicket = javaScriptSerializer.Serialize(producer); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.PostAsJsonAsync(insertAction, producer).Result; Assert.IsTrue(response.IsSuccessStatusCode); ProducerResponse producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsTrue(producerResponse.Success); Assert.IsTrue(producerResponse != null); Assert.IsTrue(producerResponse.Producer.Id > 0); //get by id string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, producerResponse.Producer.Id.ToString()); response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetProducerResponse getProducerResponse = response.Content.ReadAsAsync <GetProducerResponse>().Result; Assert.IsTrue(getProducerResponse.Success); Assert.IsTrue(getProducerResponse.Producers.Count == 1); Assert.IsTrue(getProducerResponse.Producers.ElementAt(0).Id == producerResponse.Producer.Id); //get all response = client.GetAsync(getAllAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); getProducerResponse = response.Content.ReadAsAsync <GetProducerResponse>().Result; Assert.IsTrue(getProducerResponse.Success); Producer producerFound = (from produc in getProducerResponse.Producers where produc.Id == producerResponse.Producer.Id select produc).FirstOrDefault(); Assert.IsTrue(producerFound != null); //test update producer.Id = producerResponse.Producer.Id; producer.RFC = "UpdatedProducerRFC"; producer.GenderId = 2; response = client.PostAsJsonAsync(updateAction, producer).Result; Assert.IsTrue(response.IsSuccessStatusCode); producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsTrue(producerResponse.Success); //Get ticket again and check it was updated response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getProducerResponse = response.Content.ReadAsAsync <GetProducerResponse>().Result; Assert.IsTrue(getProducerResponse.Success); Assert.IsTrue(getProducerResponse.Producers.Count == 1); Assert.IsTrue(getProducerResponse.Producers.ElementAt(0).GenderId == 2); Assert.IsTrue(getProducerResponse.Producers.ElementAt(0).RFC == "UpdatedProducerRFC"); //test delete response = client.PostAsJsonAsync(deleteAction, new IdModel(producerResponse.Producer.Id)).Result; Assert.IsTrue(response.IsSuccessStatusCode); producerResponse = response.Content.ReadAsAsync <ProducerResponse>().Result; Assert.IsTrue(producerResponse.Success); //Get ticket again and check it is not found response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getProducerResponse = response.Content.ReadAsAsync <GetProducerResponse>().Result; Assert.IsTrue(getProducerResponse.Success); Assert.IsTrue(getProducerResponse.Producers.Count == 0); }
public void TestInsertUpdateAndGetWeightTicket() { //Get token Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Test insert WeightTicket weightTicket = WeightTicketHelper.CreateDummyTicket(); string jsonTicket = javaScriptSerializer.Serialize(weightTicket); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.PostAsJsonAsync(insertAction, weightTicket).Result; Assert.IsTrue(response.IsSuccessStatusCode); WeightTicketResponse weightTicketResponse = response.Content.ReadAsAsync <WeightTicketResponse>().Result; Assert.IsTrue(weightTicketResponse.Success); Assert.IsTrue(weightTicketResponse != null); Assert.IsTrue(weightTicketResponse.WeightTicket.Id > 0); //get by id string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, weightTicketResponse.WeightTicket.Id.ToString()); response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetWeightTicketResponse getWeightTicketResponse = response.Content.ReadAsAsync <GetWeightTicketResponse>().Result; Assert.IsTrue(getWeightTicketResponse.Success); Assert.IsTrue(getWeightTicketResponse.WeightTickets.Count == 1); Assert.IsTrue(getWeightTicketResponse.WeightTickets.ElementAt(0).Id == weightTicketResponse.WeightTicket.Id); //get all response = client.GetAsync(getAllAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); getWeightTicketResponse = response.Content.ReadAsAsync <GetWeightTicketResponse>().Result; Assert.IsTrue(getWeightTicketResponse.Success); WeightTicket ticketFound = (from ticket in getWeightTicketResponse.WeightTickets where ticket.Id == weightTicketResponse.WeightTicket.Id select ticket).FirstOrDefault(); Assert.IsTrue(ticketFound != null); //test update weightTicket.Id = weightTicketResponse.WeightTicket.Id; weightTicket.SubTotal = 20; weightTicket.ApplyDrying = false; //Todo check other properties response = client.PostAsJsonAsync(updateAction, weightTicket).Result; Assert.IsTrue(response.IsSuccessStatusCode); weightTicketResponse = response.Content.ReadAsAsync <WeightTicketResponse>().Result; Assert.IsTrue(weightTicketResponse.Success); //Get ticket again and check it was updated response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getWeightTicketResponse = response.Content.ReadAsAsync <GetWeightTicketResponse>().Result; Assert.IsTrue(getWeightTicketResponse.Success); Assert.IsTrue(getWeightTicketResponse.WeightTickets.Count == 1); Assert.IsTrue(getWeightTicketResponse.WeightTickets.ElementAt(0).SubTotal == 20); Assert.IsFalse(getWeightTicketResponse.WeightTickets.ElementAt(0).ApplyDrying); //test delete response = client.PostAsJsonAsync(deleteAction, new IdModel(weightTicketResponse.WeightTicket.Id)).Result; Assert.IsTrue(response.IsSuccessStatusCode); weightTicketResponse = response.Content.ReadAsAsync <WeightTicketResponse>().Result; Assert.IsTrue(weightTicketResponse.Success); //Get ticket again and check it is not found response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getWeightTicketResponse = response.Content.ReadAsAsync <GetWeightTicketResponse>().Result; Assert.IsTrue(getWeightTicketResponse.Success); Assert.IsTrue(getWeightTicketResponse.WeightTickets.Count == 0); }
public void TestInsertUpdateAndGetCicle() { //Get token Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3"); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); //Test insert Cicle cicle = CicleHelper.CreateDummyCicle(); string jsonTicket = javaScriptSerializer.Serialize(cicle); //Post add ticket HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.PostAsJsonAsync(insertAction, cicle).Result; Assert.IsTrue(response.IsSuccessStatusCode); CicleResponse cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result; Assert.IsTrue(cicleResponse.Success); Assert.IsTrue(cicleResponse != null); Assert.IsTrue(cicleResponse.Cicle.Id > 0); //get by id string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, cicleResponse.Cicle.Id.ToString()); response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); GetCicleResponse getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result; Assert.IsTrue(getCicleResponse.Success); Assert.IsTrue(getCicleResponse.Cicles.Count == 1); Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).Id == cicleResponse.Cicle.Id); //get all response = client.GetAsync(getAllAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result; Assert.IsTrue(getCicleResponse.Success); Cicle cicleFound = (from aCicle in getCicleResponse.Cicles where aCicle.Id == cicleResponse.Cicle.Id select aCicle).FirstOrDefault(); Assert.IsTrue(cicleFound != null); //test update cicle.Id = cicleResponse.Cicle.Id; cicle.Name = "CicleNameUpdated"; cicle.AmountPerHectarea = 2; response = client.PostAsJsonAsync(updateAction, cicle).Result; Assert.IsTrue(response.IsSuccessStatusCode); cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result; Assert.IsTrue(cicleResponse.Success); //Get ticket again and check it was updated response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result; Assert.IsTrue(getCicleResponse.Success); Assert.IsTrue(getCicleResponse.Cicles.Count == 1); Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).AmountPerHectarea == 2); Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).Name == "CicleNameUpdated"); //test delete response = client.PostAsJsonAsync(deleteAction, new IdModel(cicleResponse.Cicle.Id)).Result; Assert.IsTrue(response.IsSuccessStatusCode); cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result; Assert.IsTrue(cicleResponse.Success); //Get ticket again and check it is not found response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result; Assert.IsTrue(getCicleResponse.Success); Assert.IsTrue(getCicleResponse.Cicles.Count == 0); }