Ejemplo n.º 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)));
        }
Ejemplo n.º 2
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>()));
        }
Ejemplo n.º 3
0
        public async Task 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.GetTenantAsync(It.IsAny <string>())).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 { SlugName = "slug-name" });

            mockTenantStore.Verify(t => t.GetTenantAsync(It.IsAny <string>()));
            mockSurveyAnswerStoredQueue.Verify(
                q => q.AddMessageAsync(
                    It.Is <SurveyAnswerStoredMessage>(m => m.SurveySlugName == "slug-name")));
        }
Ejemplo n.º 4
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"));
        }