Exemplo n.º 1
0
        public async Task <string> ChangeJson([FromBody] ChangeSurveyModel model)
        {
            var manager = _context.ManagerFactory.CreateSurveyManager();

            await manager.ChangeSurvey(model);

            return(""); //wat
        }
Exemplo n.º 2
0
        public async Task ChangeSurvey(ChangeSurveyModel model)
        {
            var coll = _db.GetCollection <Survey>("survey_collection");

            var update = Builders <Survey> .Update.Set(s => s.Json, model.Json);

            await coll.UpdateOneAsync(s => s.SurveyName == model.Id, update);
        }
        public async Task SurveyManager_ChangeSurvey_UpdateOneAsyncCalled()
        {
            _mockClient.GetDatabase(Arg.Any <string>()).Returns(_mockDb);
            _mockDb.GetCollection <Survey>(Arg.Any <string>()).Returns(_mockSurveyCollection);

            var manager = new SurveyManager(_mockClient, "test");

            var changeSurveyModel = new ChangeSurveyModel()
            {
                Json = "{}", Id = "test"
            };

            await manager.ChangeSurvey(changeSurveyModel);

            await _mockSurveyCollection.Received(1).UpdateOneAsync(Arg.Any <ExpressionFilterDefinition <Survey> >(), Arg.Any <UpdateDefinition <Survey> >());
        }
        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);
        }