public void PostRunAddsTheAnswerIdToTheListInTheStore()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock<IDictionary<string, TenantSurveyProcessingInfo>>();
            var mockUpdateableQueue = new Mock<IUpdateableAzureQueue>();
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock<ISurveyAnswersSummaryStore>();
            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var message = new SurveyAnswerStoredMessage
            {
                Tenant = "tenant",
                SurveySlugName = "slug-name",
                SurveyAnswerBlobId = "id",
                AppendedToAnswers = false
            };
            message.SetUpdateableQueueReference(mockUpdateableQueue.Object);
            var tenantSurveyProcessingInfo = new TenantSurveyProcessingInfo("tenant", "slug-name");
            tenantSurveyProcessingInfo.AnswersMessages.Add(message);
            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { tenantSurveyProcessingInfo });

            command.PostRun();

            mockSurveyAnswerStore.Verify(
                r => r.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", It.IsAny<IEnumerable<string>>()),
                Times.Once());
            mockUpdateableQueue.Verify(q => q.UpdateMessage(message), Times.Once());
        }
        public void PostRunAddsTheAnswerIdToTheListInTheStore()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock <IDictionary <string, TenantSurveyProcessingInfo> >();
            var mockUpdateableQueue           = new Mock <IUpdateableAzureQueue>();
            var mockSurveyAnswerStore         = new Mock <ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock <ISurveyAnswersSummaryStore>();
            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var message = new SurveyAnswerStoredMessage
            {
                Tenant             = "tenant",
                SurveySlugName     = "slug-name",
                SurveyAnswerBlobId = "id",
                AppendedToAnswers  = false
            };

            message.SetUpdateableQueueReference(mockUpdateableQueue.Object);
            var tenantSurveyProcessingInfo = new TenantSurveyProcessingInfo("tenant", "slug-name");

            tenantSurveyProcessingInfo.AnswersMessages.Add(message);
            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { tenantSurveyProcessingInfo });

            command.PostRun();

            mockSurveyAnswerStore.Verify(
                r => r.AppendSurveyAnswerIdsToAnswersList("tenant", "slug-name", It.IsAny <IEnumerable <string> >()),
                Times.Once());
            mockUpdateableQueue.Verify(q => q.UpdateMessage(message), Times.Once());
        }
        public void PostRunMergesTheSummaryToTheStore()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock<IDictionary<string, TenantSurveyProcessingInfo>>();
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock<ISurveyAnswersSummaryStore>();
            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var tenantSurveyProcessingInfo = new TenantSurveyProcessingInfo("tenant", "slug-name");
            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { tenantSurveyProcessingInfo });

            command.PostRun();

            mockSurveyAnswersSummaryStore.Verify(
                r => r.MergeSurveyAnswersSummary(It.Is<SurveyAnswersSummary>(s => s == tenantSurveyProcessingInfo.AnswersSummary)),
                Times.Once());
        }
        public void PostRunMergesTheSummaryToTheStore()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock <IDictionary <string, TenantSurveyProcessingInfo> >();
            var mockSurveyAnswerStore         = new Mock <ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock <ISurveyAnswersSummaryStore>();
            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var tenantSurveyProcessingInfo = new TenantSurveyProcessingInfo("tenant", "slug-name");

            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { tenantSurveyProcessingInfo });

            command.PostRun();

            mockSurveyAnswersSummaryStore.Verify(
                r => r.MergeSurveyAnswersSummary(It.Is <SurveyAnswersSummary>(s => s == tenantSurveyProcessingInfo.AnswersSummary)),
                Times.Once());
        }
        public void PostRunMergesTheSummaryFromTheReporitoryWithTheSumamryInTheCache()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock<IDictionary<string, TenantSurveyProcessingInfo>>();
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock<ISurveyAnswersSummaryStore>();

            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var mockTenantSurveyProcessingInfo = new Mock<TenantSurveyProcessingInfo>("tenant", "slug-name");
            var mockTenantSurveyProcessingInfoObj = mockTenantSurveyProcessingInfo.Object;
            mockTenantSurveyProcessingInfoObj.AnswersSummary.TotalAnswers = 1;
            mockTenantSurveyProcessingInfoObj.AnswersSummary.QuestionAnswersSummaries.Add(new QuestionAnswersSummary() { QuestionType = QuestionType.FiveStars, AnswersSummary = "1" });
            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { mockTenantSurveyProcessingInfoObj });

            command.PostRun();

            mockSurveyAnswersSummaryStore.Verify(s => s.MergeSurveyAnswersSummary(mockTenantSurveyProcessingInfoObj.AnswersSummary), Times.Once());
        }
        public void PostRunMergesTheSummaryFromTheReporitoryWithTheSumamryInTheCache()
        {
            var mockTenantSurveyProcessingInfoCache = new Mock <IDictionary <string, TenantSurveyProcessingInfo> >();
            var mockSurveyAnswerStore         = new Mock <ISurveyAnswerStore>();
            var mockSurveyAnswersSummaryStore = new Mock <ISurveyAnswersSummaryStore>();

            var command = new UpdatingSurveyResultsSummaryCommand(mockTenantSurveyProcessingInfoCache.Object, mockSurveyAnswerStore.Object, mockSurveyAnswersSummaryStore.Object);
            var mockTenantSurveyProcessingInfo    = new Mock <TenantSurveyProcessingInfo>("tenant", "slug-name");
            var mockTenantSurveyProcessingInfoObj = mockTenantSurveyProcessingInfo.Object;

            mockTenantSurveyProcessingInfoObj.AnswersSummary.TotalAnswers = 1;
            mockTenantSurveyProcessingInfoObj.AnswersSummary.QuestionAnswersSummaries.Add(new QuestionAnswersSummary()
            {
                QuestionType = QuestionType.FiveStars, AnswersSummary = "1"
            });
            mockTenantSurveyProcessingInfoCache.Setup(c => c.Values).Returns(new[] { mockTenantSurveyProcessingInfoObj });

            command.PostRun();

            mockSurveyAnswersSummaryStore.Verify(s => s.MergeSurveyAnswersSummary(mockTenantSurveyProcessingInfoObj.AnswersSummary), Times.Once());
        }