Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }