public void TestInsertUpdateAndGetWeightTicket() { WeightTicketsBL weightTicketBL = new WeightTicketsBL(connectionString); WeightTicket weightTicket = WeightTicketHelper.CreateDummyTicket(); weightTicket = weightTicketBL.InsertWeightTicket(weightTicket); Assert.IsTrue(weightTicket.Id > 0); //Test get by Id List <WeightTicket> savedTickets = weightTicketBL.GetWeightTicket(weightTicket.Id); Assert.IsTrue(savedTickets.Count() == 1); WeightTicket savedTicket = savedTickets[0]; Assert.IsTrue(savedTicket.Id == weightTicket.Id); //Todo create custom validator to check all properties //Test get all savedTickets = weightTicketBL.GetWeightTicket(); savedTicket = (from ticket in savedTickets where ticket.Id == savedTicket.Id select ticket).FirstOrDefault(); Assert.IsTrue(savedTicket != null); //Test update weightTicket.SubTotal = 20; weightTicket.ApplyDrying = false; //Todo check other properties weightTicket = weightTicketBL.UpdateWeightTicket(weightTicket); savedTickets = weightTicketBL.GetWeightTicket(weightTicket.Id); Assert.IsTrue(savedTickets != null && savedTickets.Count() == 1); savedTicket = savedTickets[0]; Assert.IsTrue(savedTicket.SubTotal == 20); Assert.IsTrue(!savedTicket.ApplyDrying); //Test delete bool result = weightTicketBL.DeleteWeightTicket(savedTicket.Id); Assert.IsTrue(result); savedTickets = weightTicketBL.GetWeightTicket(weightTicket.Id); Assert.IsTrue(savedTickets.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); }