Exemple #1
0
        public async Task RegisterUser()
        {
            var registerUser = new RegisterUserRequest()
            {
                //Ta bort kommentarer och fyll i önskat värde. En ny användare kommer tillhöra
                //rollen employee. För att ge användaren en annan roll måste admin skicka en updaterequest för användaren

                //UserName =
                //Email =
                //Password =
                //EmpId =
            };

            var request = await client.PostAsJsonAsync("https://localhost:5001/api/authentication/register", registerUser);

            if (request != null && request.IsSuccessStatusCode)
            {
                var response = await request.Content.ReadAsStringAsync();

                var settings = new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Local
                };
                var receivedUser = JsonConvert.DeserializeObject <AuthResponse>(response, settings);
                var user         = new User()
                {
                    UserName = receivedUser.UserName
                };
                dbContext.users.Add(user);
                await dbContext.SaveChangesAsync();

                Console.WriteLine($"User {user.UserName} has now been registered");
                return;
            }
            Console.WriteLine("Request exception");
            return;
        }
Exemple #2
0
        public async Task SeedMethod()
        {
            var user1 = new RegisterUserRequest()
            {
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**",
                EmpId    = 1
            };
            var user2 = new RegisterUserRequest()
            {
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**",
                EmpId    = 2
            };
            var user3 = new RegisterUserRequest()
            {
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**",
                EmpId    = 3
            };
            var user4 = new RegisterUserRequest()
            {
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**",
                EmpId    = 4
            };
            var request1 = await client.PostAsJsonAsync("https://localhost:5001/api/authentication/register", user1);

            var response1 = await request1.Content.ReadAsStringAsync();

            var receivedUser1 = JsonConvert.DeserializeObject <AuthResponse>(response1);
            var newUser1      = new User()
            {
                UserName = user1.UserName
            };
            var request2 = await client.PostAsJsonAsync("https://localhost:5001/api/authentication/register", user2);

            var response2 = await request2.Content.ReadAsStringAsync();

            var receivedUser2 = JsonConvert.DeserializeObject <AuthResponse>(response1);
            var newUser2      = new User()
            {
                UserName = user2.UserName
            };
            var request3 = await client.PostAsJsonAsync("https://localhost:5001/api/authentication/register", user3);

            var response3 = await request3.Content.ReadAsStringAsync();

            var receivedUser3 = JsonConvert.DeserializeObject <AuthResponse>(response1);
            var newUser3      = new User()
            {
                UserName = user3.UserName
            };
            var request4 = await client.PostAsJsonAsync("https://localhost:5001/api/authentication/register", user4);

            var response4 = await request4.Content.ReadAsStringAsync();

            var receivedUser4 = JsonConvert.DeserializeObject <AuthResponse>(response1);
            var newUser4      = new User()
            {
                UserName = user4.UserName
            };

            dbContext.users.Add(newUser1);
            dbContext.users.Add(newUser2);
            dbContext.users.Add(newUser3);
            dbContext.users.Add(newUser4);
            dbContext.SaveChanges();

            Program p = new Program();
            await p.Login("Admin", "AsheTrash1!");

            await p.UpdateUser("Admin", "CountryManager");

            await p.UpdateUser("Admin", "CEO");
        }