public async Task GetFirstSurveyAnswerIdGetTheAnswersListBlob() { var mockSurveyAnswerContainerFactory = new Mock <AzureBlobContainerFactory <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainerFactory = new Mock <AzureBlobContainerFactory <List <string> > >(); var mockSurveyAnswerContainer = new Mock <IAzureBlobContainer <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var service = new SurveyAnswerService( this.CreateServiceContext(), mockSurveyAnswerContainerFactory.Object, mockSurveyAnswerListContainerFactory.Object, new Mock <ISurveyAnalysisService>().Object); mockSurveyAnswerContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerContainer.Object); mockSurveyAnswerListContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerListContainer.Object); mockSurveyAnswerContainer.Setup(c => c.ExistsAsync()) .Returns(Task.FromResult(true)); var surveyAnswer = new Tailspin.SurveyAnswerService.Models.SurveyAnswer(); mockSurveyAnswerContainer.Setup(c => c.GetAsync("id 1")) .ReturnsAsync(surveyAnswer); mockSurveyAnswerListContainer.Setup(c => c.GetAsync("slug-name")) .ReturnsAsync(new List <string>() { "id 1" }); var browsingContext = await service.GetSurveyAnswerBrowsingContextAsync("slug-name", null); Assert.IsNotNull(browsingContext.SurveyAnswer); }
public async Task GetSurveyAnswerBrowsingContextReturnsPreviousId() { var mockSurveyAnswerContainerFactory = new Mock <AzureBlobContainerFactory <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainerFactory = new Mock <AzureBlobContainerFactory <List <string> > >(); var mockSurveyAnswerContainer = new Mock <IAzureBlobContainer <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var service = new SurveyAnswerService( this.CreateServiceContext(), mockSurveyAnswerContainerFactory.Object, mockSurveyAnswerListContainerFactory.Object, new Mock <ISurveyAnalysisService>().Object); mockSurveyAnswerContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerContainer.Object); mockSurveyAnswerListContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerListContainer.Object); mockSurveyAnswerContainer.Setup(c => c.ExistsAsync()) .Returns(Task.FromResult(true)); mockSurveyAnswerContainer.Setup(c => c.GetAsync(It.IsAny <string>())) .ReturnsAsync(new Tailspin.SurveyAnswerService.Models.SurveyAnswer()); mockSurveyAnswerListContainer.Setup(c => c.GetAsync("slug-name")) .ReturnsAsync(new List <string>() { "id 1", "id 2", "id 3" }); var browsingContext = await service.GetSurveyAnswerBrowsingContextAsync("slug-name", "id 2"); Assert.AreEqual("id 1", browsingContext.PreviousAnswerId); }
public async Task SaveAndGet() { var objId = Guid.NewGuid().ToString(); var questionAnswers1 = new List <Client.Models.QuestionAnswer>(); questionAnswers1.Add(new Client.Models.QuestionAnswer { QuestionText = "q1", QuestionType = Client.Models.QuestionType.SimpleText, Answer = "testanswer1" }); questionAnswers1.Add(new Client.Models.QuestionAnswer { QuestionText = "q2", QuestionType = Client.Models.QuestionType.FiveStars, Answer = "3" }); var questionAnswers2 = new List <Client.Models.QuestionAnswer>(); questionAnswers2.Add(new Client.Models.QuestionAnswer { QuestionText = "q1", QuestionType = Client.Models.QuestionType.SimpleText, Answer = "testanswer2" }); questionAnswers2.Add(new Client.Models.QuestionAnswer { QuestionText = "q2", QuestionType = Client.Models.QuestionType.FiveStars, Answer = "5" }); await target.SaveSurveyAnswerAsync(new Client.Models.SurveyAnswer { SlugName = "test-title" + objId, QuestionAnswers = questionAnswers1 }); await target.SaveSurveyAnswerAsync(new Client.Models.SurveyAnswer { SlugName = "test-title" + objId, QuestionAnswers = questionAnswers2 }); var surveyAnswerBrowsingContext = await target.GetSurveyAnswerBrowsingContextAsync("test-title" + objId, null); Assert.AreEqual(2, surveyAnswerBrowsingContext.SurveyAnswer.QuestionAnswers.Count); Assert.AreEqual("testanswer1", surveyAnswerBrowsingContext.SurveyAnswer.QuestionAnswers.Single(a => a.QuestionText == "q1").Answer); Assert.IsNull(surveyAnswerBrowsingContext.PreviousAnswerId); var surveyAnswerBrowsingContextNext = await target.GetSurveyAnswerBrowsingContextAsync("test-title" + objId, surveyAnswerBrowsingContext.NextAnswerId); Assert.AreEqual(2, surveyAnswerBrowsingContextNext.SurveyAnswer.QuestionAnswers.Count); Assert.AreEqual("testanswer2", surveyAnswerBrowsingContextNext.SurveyAnswer.QuestionAnswers.Single(a => a.QuestionText == "q1").Answer); Assert.IsNull(surveyAnswerBrowsingContextNext.NextAnswerId); }
public async Task GetSurveyAnswerBrowsingContextWithEmptySlugName() { var mockSurveyAnswerContainerFactory = new Mock <AzureBlobContainerFactory <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainerFactory = new Mock <AzureBlobContainerFactory <List <string> > >(); var service = new SurveyAnswerService( this.CreateServiceContext(), mockSurveyAnswerContainerFactory.Object, mockSurveyAnswerListContainerFactory.Object, new Mock <ISurveyAnalysisService>().Object); mockSurveyAnswerContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >().Object); mockSurveyAnswerListContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(new Mock <IAzureBlobContainer <List <string> > >().Object); await AssertEx.ThrowsExceptionAsync <ArgumentException>( async() => await service.GetSurveyAnswerBrowsingContextAsync(string.Empty, null), string.Empty, null); }
public async Task GetSurveyAnswerBrowsingContextGetTheAnswersListBlob() { var mockSurveyAnswerContainerFactory = new Mock <AzureBlobContainerFactory <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainerFactory = new Mock <AzureBlobContainerFactory <List <string> > >(); var mockSurveyAnswerContainer = new Mock <IAzureBlobContainer <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var service = new SurveyAnswerService( this.CreateServiceContext(), mockSurveyAnswerContainerFactory.Object, mockSurveyAnswerListContainerFactory.Object, new Mock <ISurveyAnalysisService>().Object); mockSurveyAnswerContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerContainer.Object); mockSurveyAnswerListContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerListContainer.Object); var browsingContext = await service.GetSurveyAnswerBrowsingContextAsync("slug-name", string.Empty); mockSurveyAnswerListContainer.Verify(c => c.GetAsync("slug-name"), Times.Once); }
public async Task GetSurveyAnswerBrowsingContextReturnsNullNextIdAndPreviousIdWhenListDoesNotExist() { var mockSurveyAnswerContainerFactory = new Mock <AzureBlobContainerFactory <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainerFactory = new Mock <AzureBlobContainerFactory <List <string> > >(); var mockSurveyAnswerContainer = new Mock <IAzureBlobContainer <Tailspin.SurveyAnswerService.Models.SurveyAnswer> >(); var mockSurveyAnswerListContainer = new Mock <IAzureBlobContainer <List <string> > >(); var service = new SurveyAnswerService( this.CreateServiceContext(), mockSurveyAnswerContainerFactory.Object, mockSurveyAnswerListContainerFactory.Object, new Mock <ISurveyAnalysisService>().Object); mockSurveyAnswerContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerContainer.Object); mockSurveyAnswerListContainerFactory.Setup(f => f(It.IsAny <string>())) .Returns(mockSurveyAnswerListContainer.Object); mockSurveyAnswerContainer.Setup(c => c.ExistsAsync()) .Returns(Task.FromResult(true)); var browsingContext = await service.GetSurveyAnswerBrowsingContextAsync("slug-name", "id"); Assert.IsNull(browsingContext.PreviousAnswerId); Assert.IsNull(browsingContext.NextAnswerId); }