public async Task account_getallasync()
        {
            var client = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(client);
            }
            //
            var util      = new Utility();
            var accountid = await util.addAccount(client);

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

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

            var accounts = (ICollection <CompanyAccountViewModel>)JsonConvert.DeserializeObject <IEnumerable <CompanyAccountViewModel> >(jsonString);

            Assert.True(accounts.Count > 0);
            //clean
            await util.removeAccount(client, accountid);
        }
        public async Task user_getbyidasync()
        {
            var client = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(client);
            }
            //
            var util      = new Utility();
            var accountid = await util.addAccount(client);

            var userid = await util.addUser(client, accountid);

            //
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await client.GetAsync("/api/userasync/" + userid.ToString());

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

            var user = JsonConvert.DeserializeObject <UserViewModel>(jsonString);

            Assert.True(user.FirstName == "FirstName");
            //clean
            await util.removeUser(client, userid);

            await util.removeAccount(client, accountid);
        }
        public async Task LoadTest()
        {
            int loopmax = 10;
            var client  = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(client);
            }
            //
            var accountId = 0;
            var userId    = 0;
            var util      = new Utility();
            int i         = 1;

            while (i < loopmax)
            {
                accountId = await util.addAccount(client);

                userId = await util.addUser(client, accountId);

                await util.GetAccount(client, accountId);

                await util.GetUser(client, userId);

                await util.removeUser(client, userId);

                await util.removeAccount(client, accountId);

                i++;
            }
            //
            Assert.True(i == loopmax);
        }
Exemple #4
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
        }
Exemple #5
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
        }
        public async Task user_add_update_delete_async()
        {
            var client = fixture.Client;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(client);
            }
            //insert
            UserViewModel vmentity = new UserViewModel
            {
                UserName         = "******",
                FirstName        = "User 1",
                LastName         = "LastName",
                Email            = "*****@*****.**",
                Description      = "desc",
                IsAdminRole      = true,
                IsActive         = true,
                Password         = "******",
                CompanyAccountId = 1
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await client.PostAsync("/api/userasync", new StringContent(
                                                      JsonConvert.SerializeObject(vmentity), 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 Utility();

            vmentity = await util.GetUser(client, id);

            //update test
            vmentity.Description = "desc updated";
            response             = await client.PutAsync("/api/userasync/" + id.ToString(), new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json"));

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

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

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

            var oj   = JObject.Parse(jsonString);
            var desc = oj["description"].ToString();

            Assert.Equal(desc, vmentity.Description);

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

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

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

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
Exemple #7
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);
        }