/// <summary> /// Generates DevExpress report. /// </summary> /// <param name="userConnection">User connection.</param> /// <param name="configuration">Provides configuration for report generator.</param> /// <returns>Returns prepared report.</returns> public ReportData Generate(UserConnection userConnection, ReportGeneratorConfiguration configuration) { var templateId = configuration.ReportTemplateId; var schemaName = GetSchemaNameByTemplateId(userConnection, templateId); var recordUId = configuration.RecordId; string reportName = GetTemplateNameByUId(userConnection, templateId); byte[] data = GetTemplateSource(userConnection, templateId); var openXmlUtility = new OpenXmlUtility(userConnection); using (MemoryStream stream = new MemoryStream()) { stream.Write(data, 0, data.Length); using (WordprocessingDocument docx = WordprocessingDocument.Open(stream, true)) { Collection <string> captions = openXmlUtility.GetMergeFieldName(docx); Dictionary <string, DataValue> dic = GetEntityValuesByColumnName(userConnection, recordUId, schemaName, captions, templateId); WordprocessingDocument report = openXmlUtility.GetWordReport(docx, dic); var additionalMacrosUtility = new AdditionalMacrosUtility(userConnection); additionalMacrosUtility.FillAdditionalMacros(report, recordUId, schemaName, templateId); docx.Close(); } stream.Seek(0, SeekOrigin.Begin); return(new ReportData { Caption = reportName, Format = "docx", Data = stream.ToArray() }); } }
public void ReportGeneratorConfiguration_ConstructorParameterContainerNotNullReturnsReportGenerationConfiguration() { IUnityContainer fakeUnityContainer = NSubstitute.Substitute.For <IUnityContainer>(); var reportGenerationConfiguration = new ReportGeneratorConfiguration(fakeUnityContainer); Assert.NotNull(reportGenerationConfiguration); }
public void ReportGeneratorConfiguration_Configure_ReportGeneratorInContainer() { IUnityContainer fakeUnityContainer = new UnityContainer(); var reportGeneratorConfiguration = new ReportGeneratorConfiguration(fakeUnityContainer); reportGeneratorConfiguration.Configure(); var numberOfRegistration = fakeUnityContainer.Registrations.Where(x => x.RegisteredType == typeof(IReportGenerator)).Count(); var expectedNumberOfRegistrations = 1; Assert.Equal(expectedNumberOfRegistrations, numberOfRegistration); }