public async Task PublishAndGet()
        {
            var objId     = Guid.NewGuid().ToString();
            var questions = new List <Question>();

            questions.Add(new Question {
                Text = "q1", Type = QuestionType.SimpleText
            });
            questions.Add(new Question {
                Text = "q2", Type = QuestionType.MultipleChoice, PossibleAnswers = "a1"
            });
            questions.Add(new Question {
                Text = "q3", Type = QuestionType.FiveStars
            });

            var surveyInfo = await target.PublishSurveyAsync(new Survey { Title = "test title" + objId, Questions = questions });

            Assert.AreEqual("test title" + objId, surveyInfo.Title);
            Assert.AreEqual("test-title" + objId, surveyInfo.SlugName);

            var survey = await target.GetSurveyAsync("test-title" + objId);

            Assert.AreEqual(3, survey.Questions.Count);

            var q1 = survey.Questions.Single(q => q.Text == "q1");
            var q2 = survey.Questions.Single(q => q.Text == "q2");
            var q3 = survey.Questions.Single(q => q.Text == "q3");

            Assert.AreEqual(QuestionType.SimpleText, q1.Type);
            Assert.AreEqual(QuestionType.MultipleChoice, q2.Type);
            Assert.AreEqual(QuestionType.FiveStars, q3.Type);
        }
        public async Task PublishSurveyCallsSaveFromSurveyBlobWithQuestionPossibleAnswers()
        {
            var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >();
            var mockSurveyBlobContainer    = new Mock <IAzureBlobContainer <Models.Survey> >();

            mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >()))
            .ReturnsAsync(new SurveyInformationRow[] { });

            var target = new SurveyManagementService(null,
                                                     (tableName) => mockSurveyInformationTable.Object,
                                                     (containerName) => mockSurveyBlobContainer.Object);
            var question = new Client.Models.Question {
                PossibleAnswers = "possible answers"
            };
            var survey = new Client.Models.Survey
            {
                Title     = "title",
                Questions = new List <Client.Models.Question>(new[] { question })
            };

            await target.PublishSurveyAsync(survey);

            mockSurveyBlobContainer.Verify(
                c => c.SaveAsync(
                    "title",
                    It.Is <Models.Survey>(s => s.Questions.First().PossibleAnswers == "possible answers")),
                Times.Once());
        }
        public async Task PublishSurveyCallsAddFromSurveyTableWithAllTheQuestions()
        {
            var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >();
            var mockSurveyBlobContainer    = new Mock <IAzureBlobContainer <Models.Survey> >();

            mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >()))
            .ReturnsAsync(new SurveyInformationRow[] { });

            var target = new SurveyManagementService(null,
                                                     (tableName) => mockSurveyInformationTable.Object,
                                                     (containerName) => mockSurveyBlobContainer.Object);
            var survey = new Client.Models.Survey
            {
                Title     = "title",
                Questions = new List <Client.Models.Question>(new[] { new Client.Models.Question(), new Client.Models.Question() })
            };

            await target.PublishSurveyAsync(survey);

            mockSurveyBlobContainer.Verify(
                c => c.SaveAsync(
                    "title",
                    It.Is <Models.Survey>(s => s.Questions.Count == 2)),
                Times.Once());
        }
        public async Task PublishSurveyCallsAddFromSurveyTableGeneratingTheSlugName()
        {
            var mockSurveyInformationTable = new Mock <IAzureTable <SurveyInformationRow> >();
            var mockSurveyBlobContainer    = new Mock <IAzureBlobContainer <Models.Survey> >();

            mockSurveyInformationTable.Setup(t => t.GetByStringPropertiesAsync(It.IsAny <ICollection <KeyValuePair <string, string> > >()))
            .ReturnsAsync(new SurveyInformationRow[] { });
            var target = new SurveyManagementService(null,
                                                     (tableName) => mockSurveyInformationTable.Object,
                                                     (containerName) => mockSurveyBlobContainer.Object);
            var survey = new Client.Models.Survey {
                Title = "title to slug"
            };

            await target.PublishSurveyAsync(survey);

            mockSurveyInformationTable.Verify(
                c => c.AddAsync(
                    It.Is <SurveyInformationRow>(s => s.SlugName == "title-to-slug")),
                Times.Once());
        }