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 GetSurveyReturnsNullWhenNotFound()
        {
            var mock   = new Mock <IAzureBlobContainer <Models.Survey> >();
            var target = new SurveyManagementService(null, null, (containerName) => mock.Object);

            var survey = await target.GetSurveyAsync("slug-name");

            Assert.IsNull(survey);
        }
        public async Task GetSurveyReturnsTitle()
        {
            string slugName    = "slug-name";
            var    surveyModel = new Models.Survey {
                Title = "title"
            };
            var mock = new Mock <IAzureBlobContainer <Models.Survey> >();

            mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable();
            var target = new SurveyManagementService(null, null, (containerName) => mock.Object);

            var survey = await target.GetSurveyAsync(slugName);

            Assert.AreEqual("title", survey.Title);
        }
        public async Task GetSurveyByTenantAndSlugNameReturnsCreatedOn()
        {
            string slugName     = "slug-name";
            var    expectedDate = new DateTime(2000, 1, 1);
            var    surveyModel  = new Models.Survey {
                CreatedOn = expectedDate
            };
            var mock = new Mock <IAzureBlobContainer <Models.Survey> >();

            mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable();
            var target = new SurveyManagementService(null, null, (containerName) => mock.Object);

            var survey = await target.GetSurveyAsync(slugName);

            Assert.AreEqual(expectedDate, survey.CreatedOn);
        }
        public async Task GetSurveyFiltersBySlugName()
        {
            string slugName    = "slug-name";
            var    mock        = new Mock <IAzureBlobContainer <Models.Survey> >();
            var    surveyModel = new Models.Survey {
                SlugName = slugName
            };

            mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable();
            var target = new SurveyManagementService(null, null, (containerName) => mock.Object);

            var survey = await target.GetSurveyAsync(slugName);

            Assert.IsNotNull(survey);
            mock.Verify();
            Assert.AreEqual(surveyModel.SlugName, survey.SlugName);
        }
        public async Task GetSurveyReturnsWithQuestionsFilteredBySlugName()
        {
            string slugName = "slug-name";
            var    mock     = new Mock <IAzureBlobContainer <Models.Survey> >();
            var    question = new Models.Question {
                Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText)
            };
            var questions   = new[] { question };
            var surveyModel = new Models.Survey {
                Questions = questions
            };

            mock.Setup(t => t.GetAsync(slugName)).ReturnsAsync(surveyModel).Verifiable();
            var target = new SurveyManagementService(null, null, (containerName) => mock.Object);

            var survey = await target.GetSurveyAsync(slugName);

            Assert.AreEqual(1, survey.Questions.Count);
        }