Beispiel #1
0
        public void TestInsertUpdateAndGetCicle()
        {
            CicleBL cicleBL = new CicleBL(connectionString);
            Cicle   cicle   = CicleHelper.CreateDummyCicle();

            cicle = cicleBL.InsertCicle(cicle);
            Assert.IsTrue(cicle.Id > 0);
            //Test get by Id
            List <Cicle> savedCicles = cicleBL.GetCicle(cicle.Id);

            Assert.IsTrue(savedCicles.Count() == 1);
            Cicle savedCicle = savedCicles[0];

            Assert.IsTrue(savedCicle.Id == cicle.Id); //Todo create custom validator to check all properties
            //Test get all
            savedCicles = cicleBL.GetCicle();
            savedCicle  = (from ticket in savedCicles where ticket.Id == savedCicle.Id select ticket).FirstOrDefault();
            Assert.IsTrue(savedCicle != null);
            //Test update
            cicle.Name   = "cicleUpdated";
            cicle.Closed = true; //Todo check other properties
            cicle        = cicleBL.UpdateCicle(cicle);
            savedCicles  = cicleBL.GetCicle(cicle.Id);
            Assert.IsTrue(savedCicles != null && savedCicles.Count() == 1);
            savedCicle = savedCicles[0];
            Assert.IsTrue(savedCicle.Name == "cicleUpdated");
            Assert.IsTrue(savedCicle.Closed);
            //Test delete
            bool result = cicleBL.DeleteCicle(savedCicle.Id);

            Assert.IsTrue(result);
            savedCicles = cicleBL.GetCicle(cicle.Id);
            Assert.IsTrue(savedCicles.Count() == 0);
        }
Beispiel #2
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);
        }