Example #1
0
        /// <summary>
        /// Adds a page to the pdf detailing that the contract was digitally signed.
        /// </summary>
        /// <param name="pdf">The PDF to add the page to.</param>
        /// <param name="contractRefernce">The contract reference.</param>
        /// <param name="signer">Who signed the contract.</param>
        /// <param name="signedOn">When the contract was signed.</param>
        /// <param name="manuallyApproved">Flag indicating if the contract was manually approved.</param>
        /// <param name="fundingType">the contract funding type.</param>
        /// <param name="principalId">The ID of the current user.</param>
        /// <returns>The PDF with signed page.</returns>
        public byte[] AddSignedDocumentPage(byte[] pdf, string contractRefernce, string signer, DateTime signedOn, bool manuallyApproved, ContractFundingType fundingType, string principalId = null)
        {
            _logger.LogInformation($"[{nameof(AddSignedDocumentPage)}] Adding signed document page to {contractRefernce}.");

            using (var inputStream = new MemoryStream(pdf))
            {
                using (var doc = new Document(inputStream))
                {
                    var newPage        = doc.Pages.Insert(1);
                    var cursorLocation = 0d;

                    var imageHeight = AddImage(newPage, $"{AsposeLicenceManagement.EmbededResourcesNamespace}.Logo.png", 170, 105);

                    var top = CreateTextBox(newPage);
                    cursorLocation = imageHeight + 100;
                    top.Top        = cursorLocation;

                    var contractType = "contract";

                    if (fundingType == ContractFundingType.Levy)
                    {
                        contractType = "agreement";
                    }

                    top.Paragraphs.Add(CreateTitle($"Signed {contractType} document"));

                    if (manuallyApproved)
                    {
                        top.Paragraphs.Add(CreateParagraph($"This {contractType} has been signed by the authorised signatory for the {OrganisationName}, acting on behalf of the Secretary of State."));
                    }
                    else
                    {
                        top.Paragraphs.Add(CreateParagraph($"This {contractType} has been signed by the authorised signatory for the {OrganisationName}, acting on behalf of the Secretary of State, and has been digitally signed by all parties."));
                    }

                    var bottom = CreateTextBox(newPage);
                    cursorLocation += top.Height + 200;
                    bottom.Top      = cursorLocation;
                    bottom.Paragraphs.Add(CreateParagraph($"Document reference: {contractRefernce}"));
                    bottom.Paragraphs.Add(CreateParagraph($"Signed by {signer} on {signedOn.ToDateDisplay()} as the provider's authorised signatory"));
                    if (!string.IsNullOrEmpty(principalId))
                    {
                        bottom.Paragraphs.Add(CreateParagraph($"User ID: {principalId}"));
                    }

                    using (var outputStream = new MemoryStream())
                    {
                        doc.ConvertToPdfA();

                        EnsureLandscapePagesAreMarkedCorrectly(doc);
                        doc.Save(outputStream, SaveFormat.Pdf);
                        _logger.LogInformation($"[{nameof(AddSignedDocumentPage)}] Added signed document page to {contractRefernce}.");
                        return(outputStream.ToArray());
                    }
                }
            }
        }
        /// <summary>
        /// Should have signed page.
        /// </summary>
        /// <param name="pdfAsArray">pdf content as an array.</param>
        /// <param name="contractReference">contract reference number.</param>
        /// <param name="who">who signed contract.</param>
        /// <param name="when">When contract was signed.</param>
        /// <param name="manuallyApproved">has contract been approved manually or electronically.</param>
        /// <param name="fileName">Pdf file name.</param>
        /// <param name="fundingType">Contract funding type.</param>
        /// <param name="principalId">principalId.</param>
        public static void ShouldHaveSignedPage(this byte[] pdfAsArray, string contractReference, string who, DateTime when, bool manuallyApproved, string fileName, ContractFundingType fundingType, string principalId)
        {
            using (var stream = new MemoryStream(pdfAsArray))
            {
                using (var pdf = new Document(stream))
                {
                    var contractType = "contract";

                    if (fundingType == ContractFundingType.Levy)
                    {
                        contractType = "agreement";
                    }

                    pdf.AssertPage1HasText(fileName, $"Signed {contractType} document");

                    if (manuallyApproved)
                    {
                        pdf.AssertPage1HasText(fileName, $"This {contractType} has been signed by the authorised signatory for the Education and " + Environment.NewLine + "Skills Funding Agency, acting on behalf of the Secretary of State.");
                    }
                    else
                    {
                        pdf.AssertPage1HasText(fileName, $"This {contractType} has been signed by the authorised signatory for the Education and " + Environment.NewLine + "Skills Funding Agency, acting on behalf of the Secretary of State, and has been " + Environment.NewLine + "digitally signed by all parties.");
                    }

                    pdf.AssertPage1HasText(fileName, $"Document reference: {contractReference}");
                    pdf.AssertPage1HasText(fileName, $"Signed by {who} on {when.ToDateDisplay()} as the " + Environment.NewLine + "provider's authorised signatory");
                    if (!string.IsNullOrEmpty(principalId))
                    {
                        pdf.AssertPage1HasText(fileName, $"User ID: {principalId}");
                    }

                    // Just in case you want to check the output
                    pdf.Save(fileName);
                }
            }
        }
        public async Task Deserilize_PartialXML_ValidateFundingTypeEnum_ReturnsExpectedResult(string fundingType, ContractFundingType expectedType)
        {
            // Arrange
            string xml      = LoadPartialXMLFile();
            var    document = new XmlDocument();

            document.LoadXml(xml);

            var ns = new XmlNamespaceManager(new NameTable());

            ns.AddNamespace("c", Deserializer_v1103._contractEvent_Namespace);

            document.SelectSingleNode("/content/c:contract/c:contracts/c:contract/c:fundingType/c:fundingTypeCode", ns).InnerText = fundingType;

            ILoggerAdapter_SetupLogInformation();
            IContractValidationService_Setup_ValidateContractStatus();
            IContractValidationService_Setup_ValidateFundingType();
            IContractValidationService_Setup_ValidateXmlWithSchema(document);

            var expected = GeneratePocoForESIF9999(document);

            expected.First().ContractEvent.FundingType = expectedType;

            var sut = GetDeserializer();

            // Act
            var actual = await sut.DeserializeAsync(xml);

            // Assert
            actual.Should().BeEquivalentTo(expected, "Because the input XML has all required fields.");
            Verify_All();
        }