Exemplo n.º 1
0
        public async Task taxaccountnumber_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 taxaccountnumberid = await util.addTaxAccountNumber(httpclient);

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

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

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

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

            //clean
            await util.removeTaxAccountNumber(httpclient, taxaccountnumberid);

            //remove if any parent entity added
        }
Exemplo n.º 2
0
        public async Task taxaccountnumber_add_update_delete()
        {
            var httpclient = fixture.Client;;

            if (String.IsNullOrEmpty(TokenTest.TokenValue))
            {
                await TokenTest.token_get(httpclient);
            }
            //
            TaxAccountNumberViewModel taxaccountnumber = new TaxAccountNumberViewModel
            {
                //MANUAL UPDATES REQUIRED!
                TestText = "tt updated"
            };

            httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue);
            var response = await httpclient.PostAsync("/api/taxaccountnumber", new StringContent(
                                                          JsonConvert.SerializeObject(taxaccountnumber), 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.GetTaxAccountNumber(httpclient, id);

            //update test
            vmentity.TestText = "tt updated";
            response          = await httpclient.PutAsync("/api/taxaccountnumber/" + 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/taxaccountnumber/" + 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/taxaccountnumber/" + id.ToString(), new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json"));

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

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

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
        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 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 <AccountViewModel>)JsonConvert.DeserializeObject <IEnumerable <AccountViewModel> >(jsonString);

            Assert.True(accounts.Count > 0);
            //clean
            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);
        }
        public async Task user_updateemailbyusername_sp()
        {
            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);
            //get by id
            var response = await client.GetAsync("/api/user/" + userid.ToString());

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

            var user = JsonConvert.DeserializeObject <UserViewModel>(jsonString);
            //
            string updatedEmail = "*****@*****.**";

            response = await client.GetAsync("/api/user/UpdateEmailbyUsername/" + user.UserName + "/" + updatedEmail);

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

            Assert.True(records != "0");
            //get by id to confirm update
            response = await client.GetAsync("/api/user/" + userid.ToString());

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

            user = JsonConvert.DeserializeObject <UserViewModel>(jsonString);
            Assert.True(user.Email == updatedEmail);
            //clean
            await util.removeUser(client, userid);

            await util.removeAccount(client, accountid);
        }
Exemplo n.º 7
0
        public async Task taxaccountnumber_getallasync()
        {
            var httpclient = fixture.Client;

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

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

            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/taxaccountnumberasync/" + taxaccountnumberid.ToString());

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

            var vmenitity = JsonConvert.DeserializeObject <TaxAccountNumberViewModel>(jsonString);
            //Assert.True(vmenitity.Kids.Count == 1);
            //clean
            await util.removeTaxAccountNumber(httpclient, taxaccountnumberid);

            //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
            {
                FirstName   = "User 1",
                LastName    = "LastName",
                Email       = "*****@*****.**",
                Description = "desc",
                IsAdminRole = true,
                IsActive    = true,
                Password    = "******",
                AccountId   = 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);
        }