Ejemplo n.º 1
0
 public async Task AppendSurveyAnswerIdToSurveyAnswerListWithNullSlugName()
 {
     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);
     var privateService = new PrivateObject(service);
     var task           = (Task)privateService.Invoke(
         "AppendSurveyAnswerIdToSurveyAnswerListAsync",
         new Type[] { typeof(string), typeof(string) },
         new object[] { null, null });
     await AssertEx.ThrowsExceptionAsync <ArgumentException>(async() => await task, string.Empty, null);
 }
Ejemplo n.º 2
0
        public async Task SaveSurveyAnswerWithNullSurveyAnswer()
        {
            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 <ArgumentNullException>(async() => await service.SaveSurveyAnswerAsync(null),
                                                                        string.Empty, null);
        }
Ejemplo n.º 3
0
        public void TestInitialize()
        {
            target = new SurveyAnswerService(null,
                                             (containerName) => {
                azureBlobSurveyAnswerContainer = new AzureBlobContainer <Models.SurveyAnswer>(
                    account,
                    containerName);
                azureBlobSurveyAnswerContainer.EnsureExistsAsync().Wait();
                return(azureBlobSurveyAnswerContainer);
            },

                                             (containerName) => {
                azureBlogStringListContainer = new AzureBlobContainer <List <string> >(
                    account,
                    containerName);
                azureBlogStringListContainer.EnsureExistsAsync().Wait();
                return(azureBlogStringListContainer);
            },

                                             new Mock <ISurveyAnalysisService>().Object);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public async Task AppendSurveyAnswerIdToAnswersListSavesModifiedListToTheAnswersListBlob()
        {
            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 answerIdsList = new List <string> {
                "id 1", "id 2"
            };
            List <string> savedList = null;

            mockSurveyAnswerListContainer.Setup(c => c.GetAsync("slug-name"))
            .ReturnsAsync(answerIdsList);
            mockSurveyAnswerListContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <List <string> >()))
            .Callback <string, List <string> >((s, l) => savedList = l)
            .Returns(Task.FromResult(0));


            var surveyAnswer = new SurveyAnswer()
            {
                SlugName = "slug-name"
            };

            await service.SaveSurveyAnswerAsync(surveyAnswer);

            Assert.AreEqual(3, savedList.Count);
        }
Ejemplo n.º 6
0
        public async Task SaveSurveyAnswerCreatesBlobContainerForGivenSurvey()
        {
            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);

            var surveyAnswer = new SurveyAnswer()
            {
                SlugName = "slug-name"
            };
            await service.SaveSurveyAnswerAsync(surveyAnswer);

            mockSurveyAnswerContainerFactory.Verify(f => f("slug-name-answers"));
        }
Ejemplo n.º 7
0
        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);
        }