Example #1
0
        public async Task drone_getbyidasync()
        {
            var httpclient = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(httpclient);
            }
            //
            var util = new UtilityExt();
            //MANUAL UPDATES REQUIRED!
            //todo - add if any parent of the entity
            //add entity
            var droneid = await util.addDrone(httpclient);

            //
            httpclient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await httpclient.GetAsync("/api/droneasync/" + droneid.ToString());

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var jsonString = await response.Content.ReadAsStringAsync();

            var vmenitity = JsonConvert.DeserializeObject <DroneViewModel>(jsonString);

            Assert.True(vmenitity.TestText == "tt updated");

            //clean
            await util.removeDrone(httpclient, droneid);

            //remove if any parent entity added
        }
Example #2
0
        public async Task drone_getall()
        {
            var httpclient = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(httpclient);
            }
            //
            var util = new UtilityExt();
            //MANUAL UPDATES REQUIRED!
            //todo - add if any parent of the entity
            //add entity
            var droneid = await util.addDrone(httpclient);

            //
            httpclient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await httpclient.GetAsync("/api/drone");

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var jsonString = await response.Content.ReadAsStringAsync();

            var vmenititys =
                (ICollection <UserViewModel>)JsonConvert.DeserializeObject <IEnumerable <UserViewModel> >(jsonString);

            Assert.True(vmenititys.Count > 0);
            // lazy-loading test if entity has children
            response = await httpclient.GetAsync("/api/drone/" + droneid.ToString());

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            jsonString = await response.Content.ReadAsStringAsync();

            var vmenitity = JsonConvert.DeserializeObject <DroneViewModel>(jsonString);
            //Assert.True(vmenitity.Kids.Count == 1);
            //clean
            await util.removeDrone(httpclient, droneid);

            //remove if any parent entity added
        }
Example #3
0
        public async Task drone_add_update_delete()
        {
            var httpclient = fixture.Client;

            ;
            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(httpclient);
            }

            DroneViewModel drone = new DroneViewModel
            {
                UserId           = 1,
                CompanyAccountId = 1,
                Name             = "drone test 1",
                Token            = "tt1223334444tt",
                StatusCode       = DroneStatusCode.Maintenance,
                TestText         = "tt test"
            };

            httpclient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await httpclient.PostAsync("/api/drone", new StringContent(
                                                          JsonConvert.SerializeObject(drone), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            var lastAddedId = await response.Content.ReadAsStringAsync();

            Assert.True(int.Parse(lastAddedId) > 1);
            int id = 0;

            int.TryParse(lastAddedId, out id);

            //get inserted
            var util     = new UtilityExt();
            var vmentity = await util.GetDrone(httpclient, id);

            //update test
            vmentity.TestText = "tt updated";
            response          = await httpclient.PutAsync("/api/drone/" + id.ToString(),
                                                          new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json"));

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

            //confirm update
            response = await httpclient.GetAsync("/api/drone/" + id.ToString());

            response.EnsureSuccessStatusCode();
            var jsonString = await response.Content.ReadAsStringAsync();

            var oj = JObject.Parse(jsonString);
            var tt = oj["testText"].ToString();

            Assert.Equal(tt, vmentity.TestText);

            //another update with same account - concurrency
            vmentity.TestText = "tt updated 2";
            response          = await httpclient.PutAsync("/api/drone/" + id.ToString(),
                                                          new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);

            //delete test
            response = await httpclient.DeleteAsync("/api/drone/" + id.ToString());

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }