public void MergeSurveyAnswersSummary(SurveyAnswersSummary partialSurveyAnswersSummary)
 {
     OptimisticConcurrencyContext context;
     var id = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", partialSurveyAnswersSummary.Tenant, partialSurveyAnswersSummary.SlugName);
     var surveyAnswersSummaryInStore = this.surveyAnswersSummaryBlobContainer.Get(id, out context);
     partialSurveyAnswersSummary.MergeWith(surveyAnswersSummaryInStore);
     this.surveyAnswersSummaryBlobContainer.Save(context, partialSurveyAnswersSummary);
 }
Exemple #2
0
        public async Task MergeSurveyAnswersSummaryAsync(SurveyAnswersSummary partialSurveyAnswersSummary)
        {
            var id = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", partialSurveyAnswersSummary.Tenant, partialSurveyAnswersSummary.SlugName);
            var surveyAnswersSummaryInStore = await this.surveyAnswersSummaryBlobContainer.GetAsync(id).ConfigureAwait(false);

            partialSurveyAnswersSummary.MergeWith(surveyAnswersSummaryInStore);
            await this.surveyAnswersSummaryBlobContainer.SaveAsync(id, partialSurveyAnswersSummary).ConfigureAwait(false);
        }
        public void MergeSurveyAnswersSummary(SurveyAnswersSummary partialSurveyAnswersSummary)
        {
            OptimisticConcurrencyContext context;
            var id = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", partialSurveyAnswersSummary.Tenant, partialSurveyAnswersSummary.SlugName);
            var surveyAnswersSummaryInStore = this.surveyAnswersSummaryBlobContainer.Get(id, out context);

            partialSurveyAnswersSummary.MergeWith(surveyAnswersSummaryInStore);
            this.surveyAnswersSummaryBlobContainer.Save(context, partialSurveyAnswersSummary);
        }
Exemple #4
0
        public void MergeThrowsWhenSlugNamesAreNotEqual()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                SlugName = "slug-name"
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                SlugName = "other-slug-name"
            };

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);
        }
Exemple #5
0
        public void MergeThrowsWhenTenantsAreNotEqual()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                Tenant = "tenant"
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                Tenant = "other tenant"
            };

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);
        }
Exemple #6
0
        public void MergeCopiesTotalAnswersWhenThereAreNoPreviousAnswers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 0
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };

            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(new QuestionAnswersSummary());

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(1, existingSurveyAnswersSummary.TotalAnswers);
        }
Exemple #7
0
        public void MergeMultipleChoiceAnswersFor2DifferentAnswers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var existingQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType   = QuestionType.MultipleChoice,
                AnswersSummary = new JavaScriptSerializer().Serialize(new Dictionary <string, int> {
                    { "choice 1", 1 }
                }),
                QuestionText = "question to merge"
            };

            existingSurveyAnswersSummary.QuestionAnswersSummaries.Add(existingQuestionAnswersSummary);

            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var newQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType   = QuestionType.MultipleChoice,
                AnswersSummary = new JavaScriptSerializer().Serialize(new Dictionary <string, int> {
                    { "choice 2", 1 }
                }),
                QuestionText = "question to merge"
            };

            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(newQuestionAnswersSummary);

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(2, existingSurveyAnswersSummary.TotalAnswers);
            Assert.AreEqual(1, existingSurveyAnswersSummary.QuestionAnswersSummaries.Count);
            var questionAnswersSummary = existingSurveyAnswersSummary.QuestionAnswersSummaries.First();

            Assert.AreEqual("question to merge", questionAnswersSummary.QuestionText);
            Assert.AreEqual(QuestionType.MultipleChoice, questionAnswersSummary.QuestionType);
            var actualSummary = new JavaScriptSerializer().Deserialize <Dictionary <string, int> >(questionAnswersSummary.AnswersSummary);

            Assert.AreEqual(2, actualSummary.Keys.Count);
            Assert.AreEqual(1, actualSummary["choice 1"]);
            Assert.AreEqual(1, actualSummary["choice 2"]);
        }
Exemple #8
0
        public void Merge5StarsAnswersCalculatesRatingAverageFor3Answers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 2
            };
            var existingQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType   = QuestionType.FiveStars,
                AnswersSummary = "1",
                QuestionText   = "question to merge"
            };

            existingSurveyAnswersSummary.QuestionAnswersSummaries.Add(existingQuestionAnswersSummary);

            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var newQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType   = QuestionType.FiveStars,
                AnswersSummary = "2",
                QuestionText   = "question to merge"
            };

            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(newQuestionAnswersSummary);

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(3, existingSurveyAnswersSummary.TotalAnswers);
            Assert.AreEqual(1, existingSurveyAnswersSummary.QuestionAnswersSummaries.Count);
            var questionAnswersSummary = existingSurveyAnswersSummary.QuestionAnswersSummaries.First();

            Assert.AreEqual("question to merge", questionAnswersSummary.QuestionText);
            Assert.AreEqual(QuestionType.FiveStars, questionAnswersSummary.QuestionType);
            Assert.AreEqual("1.33", questionAnswersSummary.AnswersSummary);
        }
        public void Merge5StarsAnswersCalculatesRatingAverageFor2Answers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var existingQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType = QuestionType.FiveStars,
                AnswersSummary = "1",
                QuestionText = "question to merge"
            };
            existingSurveyAnswersSummary.QuestionAnswersSummaries.Add(existingQuestionAnswersSummary);

            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var newQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType = QuestionType.FiveStars,
                AnswersSummary = "2",
                QuestionText = "question to merge"
            };
            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(newQuestionAnswersSummary);

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(2, existingSurveyAnswersSummary.TotalAnswers);
            Assert.AreEqual(1, existingSurveyAnswersSummary.QuestionAnswersSummaries.Count);
            var questionAnswersSummary = existingSurveyAnswersSummary.QuestionAnswersSummaries.First();
            Assert.AreEqual("question to merge", questionAnswersSummary.QuestionText);
            Assert.AreEqual(QuestionType.FiveStars, questionAnswersSummary.QuestionType);
            Assert.AreEqual("1.50", questionAnswersSummary.AnswersSummary);
        }
        public void MergeThrowsWhenTenantsAreNotEqual()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                Tenant = "tenant"
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                Tenant = "other tenant"
            };

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);
        }
        public void MergeThrowsWhenSlugNamesAreNotEqual()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                SlugName = "slug-name"
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                SlugName = "other-slug-name"
            };

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);
        }
        public void MergeMultipleChoiceAnswersFor2SameAnswers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var existingQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType = QuestionType.MultipleChoice,
                AnswersSummary = new JavaScriptSerializer().Serialize(new Dictionary<string, int> { { "choice 1", 1 } }),
                QuestionText = "question to merge"
            };
            existingSurveyAnswersSummary.QuestionAnswersSummaries.Add(existingQuestionAnswersSummary);

            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            var newQuestionAnswersSummary = new QuestionAnswersSummary
            {
                QuestionType = QuestionType.MultipleChoice,
                AnswersSummary = new JavaScriptSerializer().Serialize(new Dictionary<string, int> { { "choice 1", 1 } }),
                QuestionText = "question to merge"
            };
            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(newQuestionAnswersSummary);

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(2, existingSurveyAnswersSummary.TotalAnswers);
            Assert.AreEqual(1, existingSurveyAnswersSummary.QuestionAnswersSummaries.Count);
            var questionAnswersSummary = existingSurveyAnswersSummary.QuestionAnswersSummaries.First();
            Assert.AreEqual("question to merge", questionAnswersSummary.QuestionText);
            Assert.AreEqual(QuestionType.MultipleChoice, questionAnswersSummary.QuestionType);
            var actualSummary = new JavaScriptSerializer().Deserialize<Dictionary<string, int>>(questionAnswersSummary.AnswersSummary);
            Assert.AreEqual(1, actualSummary.Keys.Count);
            Assert.AreEqual(2, actualSummary["choice 1"]);
        }
        public void MergeCopiesTotalAnswersWhenThereAreNoPreviousAnswers()
        {
            var existingSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 0
            };
            var newSurveyAnswersSummary = new SurveyAnswersSummary
            {
                TotalAnswers = 1
            };
            newSurveyAnswersSummary.QuestionAnswersSummaries.Add(new QuestionAnswersSummary());

            existingSurveyAnswersSummary.MergeWith(newSurveyAnswersSummary);

            Assert.AreEqual(1, existingSurveyAnswersSummary.TotalAnswers);
        }