示例#1
0
        public async Task CookieController_LoginWithValidCredentials_CookieIsReturned(string userName, string passWord)
        {
            await _fixture.SeedWithUsers();

            var loginModel = new LoginModel {
                Username = userName, Password = passWord
            };
            var content = JsonConvert.SerializeObject(loginModel);

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri("Cookie/Login", UriKind.Relative),
                Content    = new StringContent(content, Encoding.UTF8, "application/json")
            };

            var response = await _fixture.HttpClient.SendAsync(request);

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


            response.Headers.TryGetValues("Set-Cookie", out var newCookies);
            var cookieList = newCookies.ToList();

            Assert.Single(cookieList);
            Assert.Contains("auth_cookie", cookieList.First());
        }
        public async Task SurveyController_CreateSurvey_EmptySurveyCreated()
        {
            await _fixture.SeedWithUsers();

            await _fixture.SignInAsResearcher();

            var surveyName = "testSurvey";

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri($"Survey/Create?name={surveyName}", UriKind.Relative)
            };


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


            var surveyManager = _fixture.ManagerFactory.CreateSurveyManager();
            var createdSurvey = await surveyManager.GetSurvey("testSurvey");


            Assert.NotNull(createdSurvey);
            Assert.Single(createdSurvey);
            Assert.True(createdSurvey.ContainsKey(surveyName));
            Assert.True(createdSurvey.ContainsValue("{}"));
        }
        public async Task EditorController_ChangeJson_SurveyCorrectlyChanged()
        {
            await _fixture.SeedWithUsers();

            await _fixture.SignInAsResearcher();

            var surveyName1 = "testSurvey1";

            var manager = _fixture.ManagerFactory.CreateSurveyManager();
            await manager.CreateSurvey(surveyName1);

            var newJson     = "{'test': 'test'}";
            var resultModel = new ChangeSurveyModel {
                Json = newJson, Id = surveyName1
            };
            var jsonContent = JsonConvert.SerializeObject(resultModel);

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri("Editor/changeJson", UriKind.Relative),
                Content    = new StringContent(jsonContent, Encoding.UTF8, "application/json")
            };

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

            var content = await response.Content.ReadAsStringAsync();

            var survey = await manager.GetSurvey(surveyName1);

            var surveyString = JsonConvert.SerializeObject(survey);

            Assert.NotNull(survey);
            Assert.Equal("", content);
            Assert.Contains(newJson, surveyString);
        }
示例#4
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);
        }