public void AddNew5StarsAnswerCallsMergeWithNewSummary()
        {
            var surveyAnswersSummary = new StubSurveyAnswersSummary();
            var questionAnswer = new QuestionAnswer
            {
                QuestionType = QuestionType.FiveStars,
                QuestionText = "5 stars",
                Answer = "1"
            };
            var surveyAnswer = new SurveyAnswer();
            surveyAnswer.QuestionAnswers.Add(questionAnswer);

            surveyAnswersSummary.AddNewAnswer(surveyAnswer);

            var questionAnswersSummary = surveyAnswersSummary.MergeParameter.QuestionAnswersSummaries.First();
            Assert.AreEqual("5 stars", questionAnswersSummary.QuestionText);
            Assert.AreEqual(QuestionType.FiveStars, questionAnswersSummary.QuestionType);
            Assert.AreEqual("1.00", questionAnswersSummary.AnswersSummary);
        }
        public void AddNewMultipleChoiceAnswerCallsMergeWithNewSummary()
        {
            var surveyAnswersSummary = new StubSurveyAnswersSummary();
            var questionAnswer = new QuestionAnswer
            {
                QuestionType = QuestionType.MultipleChoice,
                QuestionText = "multiple choice",
                Answer = "choice 1",
                PossibleAnswers = "possible answers"
            };
            var surveyAnswer = new SurveyAnswer();
            surveyAnswer.QuestionAnswers.Add(questionAnswer);

            surveyAnswersSummary.AddNewAnswer(surveyAnswer);

            var questionAnswersSummary = surveyAnswersSummary.MergeParameter.QuestionAnswersSummaries.First();
            Assert.AreEqual("multiple choice", questionAnswersSummary.QuestionText);
            Assert.AreEqual("possible answers", questionAnswersSummary.PossibleAnswers);
            Assert.AreEqual(QuestionType.MultipleChoice, questionAnswersSummary.QuestionType);
            var actualSummary = new JavaScriptSerializer().Deserialize<Dictionary<string, int>>(questionAnswersSummary.AnswersSummary);
            Assert.AreEqual(1, actualSummary.Keys.Count);
            Assert.AreEqual(1, actualSummary["choice 1"]);
        }
        public void SaveAndGet()
        {
            var account = CloudConfiguration.GetStorageAccount("DataConnectionString");
            var surveyAnswerStorage = new EntitiesBlobContainer<SurveyAnswer>(account, SurveyAnswersContainer);
            var surveyAnswerId = new Guid("{DB0298D2-432B-41A7-B80F-7E7A025FA267}").ToString();
            var expectedSurveyAnswer = new SurveyAnswer { Tenant = "tenant", Title = "title", SlugName = "slugname" };
            var question1 = new QuestionAnswer { QuestionText = "text 1", QuestionType = QuestionType.SimpleText, PossibleAnswers = string.Empty };
            var question2 = new QuestionAnswer { QuestionText = "text 2", QuestionType = QuestionType.MultipleChoice, PossibleAnswers = "answer 1\nanswer2" };
            var question3 = new QuestionAnswer { QuestionText = "text 3", QuestionType = QuestionType.FiveStars, PossibleAnswers = string.Empty };
            (expectedSurveyAnswer.QuestionAnswers as List<QuestionAnswer>).AddRange(new[] { question1, question2, question3 });

            surveyAnswerStorage.Save(surveyAnswerId, expectedSurveyAnswer);
            SurveyAnswer actualSurveyAnswer = surveyAnswerStorage.Get(surveyAnswerId);

            Assert.AreEqual(expectedSurveyAnswer.Tenant, actualSurveyAnswer.Tenant);
            Assert.AreEqual(expectedSurveyAnswer.Title, actualSurveyAnswer.Title);
            Assert.AreEqual(expectedSurveyAnswer.SlugName, actualSurveyAnswer.SlugName);
            Assert.AreEqual(3, actualSurveyAnswer.QuestionAnswers.Count);
            var actualQuestionAnswer1 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                q.QuestionText == "text 1" &&
                q.QuestionType == QuestionType.SimpleText &&
                q.PossibleAnswers == string.Empty);
            Assert.IsNotNull(actualQuestionAnswer1);
            var actualQuestionAnswer2 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                q.QuestionText == "text 2" &&
                q.QuestionType == QuestionType.MultipleChoice &&
                q.PossibleAnswers == "answer 1\nanswer2");
            Assert.IsNotNull(actualQuestionAnswer2);
            var actualQuestionAnswer3 = actualSurveyAnswer.QuestionAnswers.SingleOrDefault(q =>
                q.QuestionText == "text 3" &&
                q.QuestionType == QuestionType.FiveStars &&
                q.PossibleAnswers == string.Empty);
            Assert.IsNotNull(actualQuestionAnswer3);
        }