Exemplo n.º 1
0
        public async Task AdminController_ChangeUserRole_ResearcherIsNowAdmin()
        {
            await _fixture.SeedWithUsers();

            await _fixture.SignInAsAdmin();

            var testUser = _fixture.GetResearcherUserModel();

            testUser.Role = Role.Administrator;

            var userEnum = new List <KeyValuePair <string, string> >()
            {
                KeyValuePair.Create("FirstName", testUser.FirstName),
                KeyValuePair.Create("LastName", testUser.LastName),
                KeyValuePair.Create("Email", testUser.Email),
                KeyValuePair.Create("Role", testUser.Role.ToString()),
                KeyValuePair.Create("Institution", testUser.Institution),
                KeyValuePair.Create("Country", testUser.Country),
            };

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"Admin/ChangeUserRole", UriKind.Relative),
                Content    = new FormUrlEncodedContent(userEnum)
            };

            await _fixture.HttpClient.SendAsyncWithCookie(request, "login");

            var userManager = _fixture.ManagerFactory.CreateUserManager();
            var updatedUser = await userManager.GetUserModel(testUser.Email);

            Assert.NotNull(updatedUser);
            Assert.True(updatedUser.Email == testUser.Email);
            Assert.True(updatedUser.Role == Role.Administrator);
        }