示例#1
0
        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);
            GetWareHouseResponse getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;

            Assert.IsFalse(getWareHouseResponse.Success);
            Assert.IsTrue(getWareHouseResponse.ErrorCode.HasFlag(WareHouseError.InvalidId));
        }
示例#2
0
        public IHttpActionResult GetById(int id)
        {
            GetWareHouseResponse response = new GetWareHouseResponse();

            try
            {
                List <WareHouse> wareHouses = wareHouseBL.GetWareHouse(id);
                response.WareHouses = wareHouses;
                response.Success    = true;
            }
            catch (WareHouseException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Success      = false;
            }
            return(Ok(response));
        }
示例#3
0
 public void UpdateCurrentWareHouse()
 {
     if (rancherView.SelectedId == -1)
     {
         rancherView.CurrentWareHouse = new WareHouse();
     }
     else
     {
         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(string.Format("{0}?id={1}", getByIdAction, rancherView.SelectedId)).Result;
         if (response.IsSuccessStatusCode)
         {
             GetWareHouseResponse getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;
             if (getWareHouseResponse.Success)
             {
                 PropertyCopier.CopyProperties(getWareHouseResponse.WareHouses[0], rancherView.CurrentWareHouse);
                 rancherView.CurrentWareHouse.RaiseUpdateProperties();
             }
         }
     }
 }
示例#4
0
        public void TestInsertUpdateAndGetWareHouse()
        {
            //Get token
            Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3");
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            //Test insert
            WareHouse wareHouse  = WareHouseHelper.CreateDummyWareHouse();
            string    jsonTicket = javaScriptSerializer.Serialize(wareHouse);
            //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, wareHouse).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
            WareHouseResponse wareHouseResponse = response.Content.ReadAsAsync <WareHouseResponse>().Result;

            Assert.IsTrue(wareHouseResponse.Success);
            Assert.IsTrue(wareHouseResponse != null);
            Assert.IsTrue(wareHouseResponse.WareHouse.Id > 0);
            //get by id
            string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, wareHouseResponse.WareHouse.Id.ToString());

            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            GetWareHouseResponse getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;

            Assert.IsTrue(getWareHouseResponse.Success);
            Assert.IsTrue(getWareHouseResponse.WareHouses.Count == 1);
            Assert.IsTrue(getWareHouseResponse.WareHouses.ElementAt(0).Id == wareHouseResponse.WareHouse.Id);
            //get all
            response = client.GetAsync(getAllAction).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;
            Assert.IsTrue(getWareHouseResponse.Success);
            WareHouse wareHouseFound = (from produc in getWareHouseResponse.WareHouses where produc.Id == wareHouseResponse.WareHouse.Id select produc).FirstOrDefault();

            Assert.IsTrue(wareHouseFound != null);
            //test update
            wareHouse.Id      = wareHouseResponse.WareHouse.Id;
            wareHouse.Address = "UpdatedAddress";
            wareHouse.Name    = "UpdatedName";
            response          = client.PostAsJsonAsync(updateAction, wareHouse).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            wareHouseResponse = response.Content.ReadAsAsync <WareHouseResponse>().Result;
            Assert.IsTrue(wareHouseResponse.Success);
            //Get ticket again and check it was updated
            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;
            Assert.IsTrue(getWareHouseResponse.Success);
            Assert.IsTrue(getWareHouseResponse.WareHouses.Count == 1);
            Assert.IsTrue(getWareHouseResponse.WareHouses.ElementAt(0).Address == "UpdatedAddress");
            Assert.IsTrue(getWareHouseResponse.WareHouses.ElementAt(0).Name == "UpdatedName");
            //test delete
            response = client.PostAsJsonAsync(deleteAction, new IdModel(wareHouseResponse.WareHouse.Id)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            wareHouseResponse = response.Content.ReadAsAsync <WareHouseResponse>().Result;
            Assert.IsTrue(wareHouseResponse.Success);
            //Get ticket again and check it is not found
            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getWareHouseResponse = response.Content.ReadAsAsync <GetWareHouseResponse>().Result;
            Assert.IsTrue(getWareHouseResponse.Success);
            Assert.IsTrue(getWareHouseResponse.WareHouses.Count == 0);
        }