public void When_CreateReviewAuditDocument_Then_should_call_correct_methods(long riskAssessmentId, long reviewId, RiskAssessmentType raType, SqlReportHelper.ReportType sqlReportType)
        {
            // Given
            var riskAssessmentDto = new RiskAssessmentDto()
                                        {
                                            Id = riskAssessmentId,
                                            Reference = "Test Reference",
                                            Title = "Test Tile"
                                        };

            var documentViewModel = new DocumentViewModel()
                                        {
                                            FileName = "Test File Name.pdf",
                                            FileStream = new MemoryStream(100)
                                        };

            var expectedStartOfFileName = string.Format("{0}_{1}_", riskAssessmentDto.Title, riskAssessmentDto.Reference);
            var expectedEndOfFileName = ".pdf";

            _sqlReportsService
                .Setup(x => x.GetReport(sqlReportType, It.IsAny<object[]>(), SqlReportHelper.ReportFormatType.PDF))
                .Returns(documentViewModel);

            //When
            target.CreateReviewAuditDocument(raType, riskAssessmentDto);



            //Then
            _sqlReportsService.VerifyAll();
            _documentLibraryUploader.Verify(x => x.Upload(It.Is<string>(y => y.StartsWith(expectedStartOfFileName) && y.EndsWith(expectedEndOfFileName) && y.Contains(DateTime.Now.ToString("dd_MM_yyyy"))), It.IsAny<Stream>()));

        }
 private DocumentViewModel GetSqlReport(long riskAssessmentId, SqlReportHelper.ReportType type)
 {
     return _sqlReportExecutionServiceFacade.GetReport(
         type,
         new object[] { riskAssessmentId },
         SqlReportHelper.ReportFormatType.PDF
         );
 }
        private static SqlReportDefinition GetSqlReportDefinition(SqlReportHelper.ReportType report)
        {
            var reportDefinitions = SqlReportDefinitionFactory.GetSqlReportDefinitions();
            var reportDefinition = reportDefinitions.SingleOrDefault(a => a.Report == report);

            if (reportDefinition == null)
            {
                throw new SqlReportDefinitonNotFoundException(report);
            }
            return reportDefinition;
        }
        public DocumentViewModel GetReport(SqlReportHelper.ReportType report, object[] parameterValues, SqlReportHelper.ReportFormatType format)
        {
            var reportDefinition = GetSqlReportDefinition(report);

            SetReportParameters(reportDefinition.Parameters.ToArray(), parameterValues);

            ServerInfoHeader serverInfoHeader;
            ExecutionInfo executionInfo;

            var sqlReportsSuffix = ConfigurationManager.AppSettings["SQLReportsSuffix"];
            var reportDefinitionReportPath = reportDefinition.ReportPath + sqlReportsSuffix;
            reportDefinitionReportPath.Trim();

            var executionHeader = ReportingService.LoadReport(null, reportDefinitionReportPath, null,
                out serverInfoHeader,
                out executionInfo);

            // Attach Report Parameters
            ReportingService.SetExecutionParameters(executionHeader, null, reportDefinition.Parameters.ToArray(),
                null,
                out executionInfo);

            // Render
            byte[] result;
            string extension;
            string mimeType;
            string encoding;
            Warning[] warnings = null;
            string[] streamIds;

            ReportingService.Render(executionHeader, null, SqlReportHelper.GetExportFormatString(format), null,
                out result,
                out extension, out mimeType, out encoding, out warnings, out streamIds);

            var ms = new MemoryStream();

            ms.Write(result, 0, result.Length);
            ms.Position = 0;
            var fileName = reportDefinition.Filename.Replace("/", "_");

            return new DocumentViewModel()
            {
                MimeType = mimeType,
                FileName =
                    !string.IsNullOrEmpty(fileName)
                        ? fileName + "." + extension
                        : Guid.NewGuid() + "." + extension,
                FileStream = ms
            };


        }
        public DocumentViewModel GetReport(SqlReportHelper.ReportType report, object[] parameterValues, SqlReportHelper.ReportFormatType format)
        {
            const string fileName = "lorem_ipsum";
            const string fileExtension = ".txt";

            var documentViewModel = new DocumentViewModel
                                        {
                                            FileName = fileName + fileExtension,
                                            FileStream = new MemoryStream(10),
                                            MimeType = ContentTypeHelper.GetContentTypeFromExtension(fileExtension)
                                        };

            return documentViewModel;
        }
 public SqlReportDefinitonNotFoundException(SqlReportHelper.ReportType report) : base(string.Format("Report definition not found for {0}", report.ToString())) { }
예제 #7
0
        public void When_complete_is_called_Then_check_sql_feature_is_available_then_call_GetSqlReport_documentLibraryUploader_Upload(RiskAssessmentType raType, string configKeyName, bool featureAvailable, SqlReportHelper.ReportType reportType)
        {
            // Given
            var model = new CompleteReviewViewModel()
            {
                CompanyId = TestControllerHelpers.CompanyIdAssigned,
                RiskAssessmentId = 123,
                RiskAssessmentReviewId = 456,
                IsComplete = true,
                CompletedComments = "complete",
                NextReviewDate = DateTime.Today,
                RiskAssessmentType = raType
            };

            var target = GetTarget();
            target.IsSqlReportAvailable = raType == RiskAssessmentType.GRA;

            // When
            target.Complete(model);

            //Then
            var timesToCall = featureAvailable ? Times.Once() : Times.Never();
            
            _reviewAuditService.Verify(x => x.CreateReviewAuditDocument(raType, It.IsAny<RiskAssessmentDto>()), timesToCall);
        }
 public ISqlReportsViewModelFactory WithReportId(SqlReportHelper.ReportType reportId)
 {
     _reportId = reportId;
     return this;
 }