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());
        }
コード例 #3
0
        internal static Models.Survey ToSurvey(this Client.Models.Survey survey)
        {
            if (survey == null)
            {
                throw new ArgumentNullException(nameof(survey));
            }

            return(new Models.Survey()
            {
                CreatedOn = survey.CreatedOn,
                Questions = survey.Questions.Select(q => q.ToQuestion()).ToList(),
                SlugName = survey.SlugName,
                Title = survey.Title
            });
        }
        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());
        }
コード例 #5
0
        internal static SurveyInformationRow ToSurveyRow(this Client.Models.Survey survey, string partitionKey)
        {
            if (survey == null)
            {
                throw new ArgumentNullException(nameof(survey));
            }

            if (string.IsNullOrWhiteSpace(partitionKey))
            {
                throw new ArgumentException($"{nameof(partitionKey)} cannot be null, empty, or only whitespace");
            }

            return(new SurveyInformationRow()
            {
                CreatedOn = survey.CreatedOn,
                PartitionKey = partitionKey,
                // Store the rows in reverse DateTime order
                RowKey = $"{DateTime.MaxValue.Ticks - survey.CreatedOn.Ticks:D19}",
                SlugName = survey.SlugName,
                Title = survey.Title
            });
        }