Пример #1
0
        public void TestInsertUpdateAndGetWareHouse()
        {
            WareHouseBL wareHouseBL = new WareHouseBL(connectionString);
            WareHouse   wareHouse   = WareHouseHelper.CreateDummyWareHouse();

            wareHouse = wareHouseBL.InsertWareHouse(wareHouse);
            Assert.IsTrue(wareHouse.Id > 0);
            //Test get by Id
            List <WareHouse> savedWareHouses = wareHouseBL.GetWareHouse(wareHouse.Id);

            Assert.IsTrue(savedWareHouses.Count() == 1);
            WareHouse savedWareHouse = savedWareHouses[0];

            Assert.IsTrue(savedWareHouse.Id == wareHouse.Id); //Todo create custom validator to check all properties
            //Test get all
            savedWareHouses = wareHouseBL.GetWareHouse();
            savedWareHouse  = (from ticket in savedWareHouses where ticket.Id == savedWareHouse.Id select ticket).FirstOrDefault();
            Assert.IsTrue(savedWareHouse != null);
            //Test update
            wareHouse.Name    = "WareHouse Updated";
            wareHouse.Address = "Address Updated"; //Todo check other properties
            wareHouse         = wareHouseBL.UpdateWareHouse(wareHouse);
            savedWareHouses   = wareHouseBL.GetWareHouse(wareHouse.Id);
            Assert.IsTrue(savedWareHouses != null && savedWareHouses.Count() == 1);
            savedWareHouse = savedWareHouses[0];
            Assert.IsTrue(savedWareHouse.Name == "wareHouseUpdated");
            Assert.IsTrue(savedWareHouse.Address == "Address Updated");
            //Test delete
            bool result = wareHouseBL.DeleteWareHouse(savedWareHouse.Id);

            Assert.IsTrue(result);
            savedWareHouses = wareHouseBL.GetWareHouse(wareHouse.Id);
            Assert.IsTrue(savedWareHouses.Count() == 0);
        }
Пример #2
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);
        }