Пример #1
0
        public async Task SaveSurveyAnswerAddMessageToQueueWithSavedBlobId()
        {
            var mockTenantStore = new Mock <ITenantStore>();
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockSurveyContainerFactory    = new Mock <ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerStoredQueue   = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                mockSurveyAnswerStoredQueue.Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenantAsync(It.IsAny <string>())).ReturnsAsync(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);
            string blobId = string.Empty;

            mockSurveyAnswerBlobContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <SurveyAnswer>()))
            .Returns(Task.Delay(0))
            .Callback((string id, SurveyAnswer sa) => blobId = id);

            await store.SaveSurveyAnswerAsync(new SurveyAnswer());

            mockTenantStore.Verify(t => t.GetTenantAsync(It.IsAny <string>()));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessageAsync(
                    It.Is <SurveyAnswerStoredMessage>(m => m.SurveyAnswerBlobId == blobId)));
        }
Пример #2
0
        public async Task AppendSurveyAnswerIdToAnswersListSavesModifiedListToTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            var answerIdsList = new List <string> {
                "id 1", "id 2"
            };

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")).ReturnsAsync(answerIdsList);
            List <string> savedList = null;

            mockSurveyAnswerIdsListContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <List <string> >()))
            .Callback <string, List <string> >((str, l) => savedList = l)
            .Returns(Task.Delay(0));

            await store.AppendSurveyAnswerIdToAnswersListAsync("tenant", "slug-name", "new id");

            Assert.AreEqual(3, savedList.Count);
            Assert.AreEqual("new id", savedList.Last());
        }
Пример #3
0
        public void SaveSurveyAnswerAddMessageToQueueWithSurveySlugName()
        {
            var mockTenantStore             = new Mock <ITenantStore>();
            var mockSurveyContainerFactory  = new Mock <ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerStoredQueue = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                mockSurveyAnswerStoredQueue.Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenant(It.IsAny <string>())).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            store.SaveSurveyAnswer(new SurveyAnswer {
                SlugName = "slug-name"
            });

            mockTenantStore.Verify(t => t.GetTenant(It.IsAny <string>()));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessage(
                    It.Is <SurveyAnswerStoredMessage>(m => m.SurveySlugName == "slug-name")));
        }
Пример #4
0
        public void AppendSurveyAnswerIdsToAnswersListCreatesListWhenItDoesNotExistAndSavesIt()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            List <string> answerIdsList = null;
            var           optContext    = It.IsAny <OptimisticConcurrencyContext>();

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name", out optContext)).Returns(answerIdsList);
            List <string> savedList = null;

            mockSurveyAnswerIdsListContainer.Setup(c => c.Save(optContext, It.IsAny <List <string> >()))
            .Callback <IConcurrencyControlContext, List <string> >((id, l) => savedList = l);

            store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List <string>()
            {
                "new id"
            });

            Assert.AreEqual(1, savedList.Count);
            Assert.AreEqual("new id", savedList.Last());
        }
Пример #5
0
        public void GetSurveyAnswerBrowsingContextGetTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", string.Empty);

            mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name"), Times.Once());
        }
Пример #6
0
        public async Task GetFirstSurveyAnswerIdGetTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name");

            mockSurveyAnswerIdsListContainer.Verify(c => c.GetAsync("tenant-slug-name"), Times.Once());
        }
        public void AppendSurveyAnswerIdsToAnswersListGetTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List<string>());

            var optContext = It.IsAny<OptimisticConcurrencyContext>();
            mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name", out optContext), Times.Once());
        }
Пример #8
0
        public void AppendSurveyAnswerIdsToAnswersListGetTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List <string>());

            var optContext = It.IsAny <OptimisticConcurrencyContext>();

            mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name", out optContext), Times.Once());
        }
Пример #9
0
        public async Task GetSurveyAnswerIdsReturnsList()
        {
            var azureBlobContainerMock = new Mock <IAzureBlobContainer <List <string> > >();

            azureBlobContainerMock.Setup(b => b.GetAsync("tenant-slug")).ReturnsAsync(new List <string>()
            {
                "1", "2", "3"
            });

            var surveyStore = new SurveyAnswerStore(null, null, null, null, azureBlobContainerMock.Object);
            var answers     = await surveyStore.GetSurveyAnswerIdsAsync("tenant", "slug");

            Assert.AreEqual(3, answers.Count());

            azureBlobContainerMock.Verify(b => b.GetAsync("tenant-slug"), Times.Once());
        }
Пример #10
0
        public async Task DeleteSurveyAnswersCreatesBlobContainer()
        {
            var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            await store.DeleteSurveyAnswersAsync("tenant", "slug-name");

            mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"), Times.Once());
        }
Пример #11
0
        public async Task GetFirstSurveyAnswerIdReturnsEmprtyStringWhenListIsEmpty()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name"))
            .ReturnsAsync(default(List <string>));

            var id = await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name");

            Assert.AreEqual(string.Empty, id);
        }
Пример #12
0
        public async Task GetSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey()
        {
            var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            await store.GetSurveyAnswerAsync("tenant", "slug-name", string.Empty);

            mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"));
        }
Пример #13
0
        public void GetSurveyAnswerEnsuresBlobContainerExists()
        {
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockSurveyContainerFactory    = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);

            store.GetSurveyAnswer("tenant", "slug-name", string.Empty);

            mockSurveyAnswerBlobContainer.Verify(c => c.EnsureExist());
        }
Пример #14
0
        public void DeleteSurveyAnswersDeletesAnswersList()
        {
            var mockSurveyContainerFactory       = new Mock <ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            store.DeleteSurveyAnswers("tenant", "slug-name");

            mockSurveyAnswerIdsListContainer.Verify(c => c.Delete("tenant-slug-name"), Times.Once());
        }
Пример #15
0
        public async Task GetSurveyAnswerGetsAnswerFromBlobContainer()
        {
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockSurveyContainerFactory    = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);

            await store.GetSurveyAnswerAsync("tenant", "slug-name", "id");

            mockSurveyAnswerBlobContainer.Verify(c => c.GetAsync("id"));
        }
Пример #16
0
        public async Task GetSurveyAnswerBrowsingContextReturnsNullNextIdAndPreviousIdWhenListDoesNotExist()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name"))
            .ReturnsAsync(default(List <string>));

            var surveyAnswerBrowsingContext = await store.GetSurveyAnswerBrowsingContextAsync("tenant", "slug-name", "id");

            Assert.IsNull(surveyAnswerBrowsingContext.PreviousId);
            Assert.IsNull(surveyAnswerBrowsingContext.NextId);
        }
Пример #17
0
        public async Task GetSurveyAnswerBrowsingContextReturnsNextId()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name"))
            .ReturnsAsync(new List <string> {
                "id 1", "id 2", "id 3"
            });

            var surveyAnswerBrowsingContext = await store.GetSurveyAnswerBrowsingContextAsync("tenant", "slug-name", "id 2");

            Assert.AreEqual("id 3", surveyAnswerBrowsingContext.NextId);
        }
Пример #18
0
        public void GetSurveyAnswerBrowsingContextReturnsNullPreviousIdWhenInBeginingOfList()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name"))
            .Returns(new List <string> {
                "id 1"
            });

            var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 1");

            Assert.IsNull(surveyAnswerBrowsingContext.PreviousId);
        }
Пример #19
0
        public async Task GetFirstSurveyAnswerIdReturnsTheAnswerWhichAppearsFirstOnTheListWhenListIsNotEmpty()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name"))
            .ReturnsAsync(new List <string> {
                "id"
            });

            var id = await store.GetFirstSurveyAnswerIdAsync("tenant", "slug-name");

            Assert.AreEqual("id", id);
        }
Пример #20
0
        public void SaveSurveyAnswerEnsuresBlobContainerExists()
        {
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockTenantStore            = new Mock <ITenantStore>();
            var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenant(It.IsAny <string>())).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);

            store.SaveSurveyAnswer(new SurveyAnswer());

            mockTenantStore.Verify(t => t.GetTenant(It.IsAny <string>()));
        }
Пример #21
0
        public async Task SaveSurveyAnswerSavesAnswerInBlobContainerWithId()
        {
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockTenantStore            = new Mock <ITenantStore>();
            var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenantAsync(It.IsAny <string>())).ReturnsAsync(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);

            await store.SaveSurveyAnswerAsync(new SurveyAnswer());

            mockTenantStore.Verify(t => t.GetTenantAsync(It.IsAny <string>()));
            mockSurveyAnswerBlobContainer.Verify(c => c.SaveAsync(It.Is <string>(s => s.Length == 19), It.IsAny <SurveyAnswer>()));
        }
        public void AppendSurveyAnswerIdsToAnswersListSavesModifiedListToTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            var answerIdsList = new List<string> { "id 1", "id 2" };
            var optContext = It.IsAny<OptimisticConcurrencyContext>();
            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name", out optContext)).Returns(answerIdsList);
            List<string> savedList = null;
            mockSurveyAnswerIdsListContainer.Setup(c => c.Save(optContext, It.IsAny<List<string>>()))
                                            .Callback<IConcurrencyControlContext, List<string>>((id, l) => savedList = l);

            store.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", new List<string>() { "new id" });

            Assert.AreEqual(3, savedList.Count);
            Assert.AreEqual("new id", savedList.Last());
        }
Пример #23
0
        public async Task GetSurveyAnswerReturnsAnswerObtainedFromBlobContainer()
        {
            var mockSurveyAnswerBlobContainer = new Mock <IAzureBlobContainer <SurveyAnswer> >();
            var mockSurveyContainerFactory    = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockSurveyAnswerBlobContainer.Object);
            var surveyAnswer = new SurveyAnswer();

            mockSurveyAnswerBlobContainer.Setup(c => c.GetAsync(It.IsAny <string>()))
            .ReturnsAsync(surveyAnswer);

            var actualSurveyAnswer = await store.GetSurveyAnswerAsync("tenant", "slug-name", string.Empty);

            Assert.AreSame(surveyAnswer, actualSurveyAnswer);
        }
Пример #24
0
        public async Task SaveSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey()
        {
            var mockTenantStore            = new Mock <ITenantStore>();
            var mockSurveyContainerFactory = new Mock <ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenantAsync("tenant")).ReturnsAsync(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            var surveyAnswer = new SurveyAnswer {
                TenantId = "tenant", SlugName = "slug-name"
            };
            await store.SaveSurveyAnswerAsync(surveyAnswer);

            mockTenantStore.Verify(t => t.GetTenantAsync("tenant"));
            mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"));
        }
Пример #25
0
        public async Task SaveSurveyAnswerAddMessageToQueueWithTenant()
        {
            var mockTenantStore             = new Mock <ITenantStore>();
            var mockSurveyContainerFactory  = new Mock <ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerStoredQueue = new Mock <IAzureQueue <SurveyAnswerStoredMessage> >();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                mockSurveyAnswerStoredQueue.Object,
                null,
                new Mock <IAzureBlobContainer <List <string> > >().Object);

            mockTenantStore.Setup(t => t.GetTenantAsync("tenant")).ReturnsAsync(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new Mock <IAzureBlobContainer <SurveyAnswer> >().Object);

            await store.SaveSurveyAnswerAsync(new SurveyAnswer { TenantId = "tenant" });

            mockTenantStore.Verify(t => t.GetTenantAsync("tenant"));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessageAsync(
                    It.Is <SurveyAnswerStoredMessage>(m => m.TenantId == "tenant")));
        }
        public async Task AppendSurveyAnswerIdToAnswersListCreatesListWhenItDoesNotExistAndSavesIt()
        {
            var mockSurveyAnswerIdsListContainer = new Mock <IAzureBlobContainer <List <string> > >();
            var store = new SurveyAnswerStore(
                new Mock <ITenantStore>().Object,
                new Mock <ISurveyAnswerContainerFactory>().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                new Mock <IAzureQueue <SurveyAnswerStoredMessage> >().Object,
                mockSurveyAnswerIdsListContainer.Object);

            List <string> answerIdsList = null;

            mockSurveyAnswerIdsListContainer.Setup(c => c.GetAsync("tenant-slug-name")).ReturnsAsync(answerIdsList);
            List <string> savedList = null;

            mockSurveyAnswerIdsListContainer.Setup(c => c.SaveAsync(It.IsAny <string>(), It.IsAny <List <string> >()))
            .Callback <string, List <string> >((str, l) => savedList = l)
            .Returns(Task.FromResult(0));

            await store.AppendSurveyAnswerIdToAnswersListAsync("tenant", "slug-name", "new id");

            Assert.AreEqual(1, savedList.Count);
            Assert.AreEqual("new id", savedList.Last());
        }
        public void GetSurveyAnswerBrowsingContextReturnsNullNextIdWhenEndOfList()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name"))
                                            .Returns(new List<string> { "id 1" });

            var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 1");

            Assert.IsNull(surveyAnswerBrowsingContext.NextId);
        }
        public void GetSurveyAnswerBrowsingContextReturnsPreviousId()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name"))
                                            .Returns(new List<string> { "id 1", "id 2", "id 3" });

            var surveyAnswerBrowsingContext = store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", "id 2");

            Assert.AreEqual("id 1", surveyAnswerBrowsingContext.PreviousId);
        }
        public void GetSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey()
        {
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object);

            store.GetSurveyAnswer("tenant", "slug-name", string.Empty);

            mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"));
        }
        public void GetSurveyAnswerGetsAnswerFromBlobContainer()
        {
            var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(mockSurveyAnswerBlobContainer.Object);

            store.GetSurveyAnswer("tenant", "slug-name", "id");

            mockSurveyAnswerBlobContainer.Verify(c => c.Get("id"));
        }
        public void GetSurveyAnswerIdsReturnsList()
        {
            var azureBlobContainerMock = new Mock<IAzureBlobContainer<List<string>>>();
            azureBlobContainerMock.Setup(b => b.Get("tenant-slug")).Returns(new List<string>() { "1", "2", "3" });

            var surveyStore = new SurveyAnswerStore(null, null, null, null, azureBlobContainerMock.Object);
            var answers = surveyStore.GetSurveyAnswerIds("tenant", "slug");

            Assert.AreEqual(3, answers.Count());

            azureBlobContainerMock.Verify(b => b.Get("tenant-slug"), Times.Once());
        }
        public void DeleteSurveyAnswersCallsDeleteFromBlobContainer()
        {
            var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(mockSurveyAnswerBlobContainer.Object);

            store.DeleteSurveyAnswers("tenant", "slug-name");

            mockSurveyAnswerBlobContainer.Verify(c => c.DeleteContainer(), Times.Once());
        }
        public void GetFirstSurveyAnswerIdReturnsTheAnswerWhichAppearsFirstOnTheListWhenListIsNotEmpty()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name"))
                                            .Returns(new List<string> { "id" });

            var id = store.GetFirstSurveyAnswerId("tenant", "slug-name");

            Assert.AreEqual("id", id);
        }
        public void SaveSurveyAnswerAddMessageToQueueWithTenant()
        {
            var mockTenantStore = new Mock<ITenantStore>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerStoredQueue = new Mock<IAzureQueue<SurveyAnswerStoredMessage>>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                mockSurveyAnswerStoredQueue.Object,
                null,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockTenantStore.Setup(t => t.GetTenant("tenant")).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object);

            store.SaveSurveyAnswer(new SurveyAnswer { Tenant = "tenant" });

            mockTenantStore.Verify(t => t.GetTenant("tenant"));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessage(
                    It.Is<SurveyAnswerStoredMessage>(m => m.Tenant == "tenant")));
        }
        public void SaveSurveyAnswerCreatesBlobContainerForGivenTenantAndSurvey()
        {
            var mockTenantStore = new Mock<ITenantStore>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                null,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockTenantStore.Setup(t => t.GetTenant("tenant")).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(new Mock<IAzureBlobContainer<SurveyAnswer>>().Object);

            var surveyAnswer = new SurveyAnswer { Tenant = "tenant", SlugName = "slug-name" };
            store.SaveSurveyAnswer(surveyAnswer);

            mockTenantStore.Verify(t => t.GetTenant("tenant"));
            mockSurveyContainerFactory.Verify(f => f.Create("tenant", "slug-name"));
        }
        public void SaveSurveyAnswerSavesAnswerInBlobContainerWithId()
        {
            var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>();
            var mockTenantStore = new Mock<ITenantStore>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                null,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockTenantStore.Setup(t => t.GetTenant(It.IsAny<string>())).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(mockSurveyAnswerBlobContainer.Object);

            store.SaveSurveyAnswer(new SurveyAnswer());

            mockTenantStore.Verify(t => t.GetTenant(It.IsAny<string>()));
            mockSurveyAnswerBlobContainer.Verify(c => c.Save(It.Is<string>(s => s.Length == 36), It.IsAny<SurveyAnswer>()));
        }
        public void GetSurveyAnswerBrowsingContextGetTheAnswersListBlob()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            store.GetSurveyAnswerBrowsingContext("tenant", "slug-name", string.Empty);

            mockSurveyAnswerIdsListContainer.Verify(c => c.Get("tenant-slug-name"), Times.Once());
        }
        public void SaveSurveyAnswerAddMessageToQueueWithSavedBlobId()
        {
            var mockTenantStore = new Mock<ITenantStore>();
            var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var mockSurveyAnswerStoredQueue = new Mock<IAzureQueue<SurveyAnswerStoredMessage>>();
            var store = new SurveyAnswerStore(
                mockTenantStore.Object,
                mockSurveyContainerFactory.Object,
                mockSurveyAnswerStoredQueue.Object,
                null,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockTenantStore.Setup(t => t.GetTenant(It.IsAny<string>())).Returns(new Tenant());
            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(mockSurveyAnswerBlobContainer.Object);
            string blobId = string.Empty;
            mockSurveyAnswerBlobContainer.Setup(c => c.Save(It.IsAny<string>(), It.IsAny<SurveyAnswer>()))
                .Callback((string id, SurveyAnswer sa) => blobId = id);

            store.SaveSurveyAnswer(new SurveyAnswer());

            mockTenantStore.Verify(t => t.GetTenant(It.IsAny<string>()));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessage(
                    It.Is<SurveyAnswerStoredMessage>(m => m.SurveyAnswerBlobId == blobId)));
        }
        public void GetSurveyAnswerReturnsAnswerObtainedFromBlobContainer()
        {
            var mockSurveyAnswerBlobContainer = new Mock<IAzureBlobContainer<SurveyAnswer>>();
            var mockSurveyContainerFactory = new Mock<ISurveyAnswerContainerFactory>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                mockSurveyContainerFactory.Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureBlobContainer<List<string>>>().Object);

            mockSurveyContainerFactory.Setup(f => f.Create(It.IsAny<string>(), It.IsAny<string>()))
                                      .Returns(mockSurveyAnswerBlobContainer.Object);
            var surveyAnswer = new SurveyAnswer();
            mockSurveyAnswerBlobContainer.Setup(c => c.Get(It.IsAny<string>()))
                                         .Returns(surveyAnswer);

            var actualSurveyAnswer = store.GetSurveyAnswer("tenant", "slug-name", string.Empty);

            Assert.AreSame(surveyAnswer, actualSurveyAnswer);
        }
        public void GetFirstSurveyAnswerIdReturnsEmprtyStringWhenListIsEmpty()
        {
            var mockSurveyAnswerIdsListContainer = new Mock<IAzureBlobContainer<List<string>>>();
            var store = new SurveyAnswerStore(
                new Mock<ITenantStore>().Object,
                new Mock<ISurveyAnswerContainerFactory>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                new Mock<IAzureQueue<SurveyAnswerStoredMessage>>().Object,
                mockSurveyAnswerIdsListContainer.Object);

            mockSurveyAnswerIdsListContainer.Setup(c => c.Get("tenant-slug-name"))
                                            .Returns(default(List<string>));

            var id = store.GetFirstSurveyAnswerId("tenant", "slug-name");

            Assert.AreEqual(string.Empty, id);
        }