public void CanVerifyX(string file, string serial) { file = Path.Combine(_inputPath, file); var signer = DocumentSigner.For(file); signer.Verify(File.OpenRead(file), serial).Should().BeTrue(); }
public void Test_with_mock_repository() { // assign var mockDocumentRepository = new MockDocumentRepository(); _sut = new DocumentSigner(mockDocumentRepository); // act _sut.Sign(4); // assert Assert.IsTrue(mockDocumentRepository.Verify_Update); }
public void CanSignX(string inputName, string outputName) { var input = Path.Combine(_inputPath, inputName); var output = Path.Combine(_outputPath, outputName); if (File.Exists(output)) { File.Delete(output); } File.Exists(output).Should().BeFalse(); var signer = DocumentSigner.For(input); var cert = CertUtil.GetFromFile(_certPath, _certPassword); var serial = cert.SerialNumber; signer.Sign(input, output, cert); File.Exists(output).Should().BeTrue(); CanVerifyX(output, serial); }
public void Test_using_moq() { // assign var dummyDocumentRepository = It.IsAny <IDocumentRepository>(); // dummy var mockDocumentRepository = new Mock <IDocumentRepository>(); // stub, fake, mock var document = new Document { Number = 1 }; mockDocumentRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(document); // stub method _sut = new DocumentSigner(mockDocumentRepository.Object); // act _sut.Sign(4); // assert mockDocumentRepository.Verify(x => x.Update(document)); }
public static void CreateListWatermark(string watermarkText, List <TAILIEUDINHKEM> ListTaiLieu, string Signature, string personalSign) { Application app = new Application(); try { foreach (var item in ListTaiLieu) { var doc = app.Documents.Open(FolderPath + item.DUONGDAN_FILE); try { if (doc.Bookmarks != null && !string.IsNullOrEmpty(personalSign)) { if (doc.Bookmarks["chuky"] != null) { var shape = doc.Bookmarks["chuky"].Range.InlineShapes .AddPicture(personalSign, false, true); } } //var shape = doc.Bookmarks["PicHere"].Range.InlineShapes.AddPicture(Signature, false, true); //shape.Width = 345; //shape.Height = 150; //doc.Close(); object Missing = System.Reflection.Missing.Value; object oMissing = System.Reflection.Missing.Value; object saveChanges = null; Microsoft.Office.Interop.Word.Shape nShape = null; string wmText = watermarkText; foreach (Microsoft.Office.Interop.Word.Section section in doc.Sections) { nShape = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect( MsoPresetTextEffect.msoTextEffect1, wmText, "Calibri", (float)65, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 350, ref oMissing); nShape.Fill.Visible = MsoTriState.msoTrue; nShape.Line.Visible = MsoTriState.msoFalse; nShape.Fill.Solid(); nShape.Fill.ForeColor.RGB = (Int32)WdColor.wdColorGray35; nShape.Left = (float)WdShapePosition.wdShapeLeft; nShape.Top = 250; nShape.Rotation = -45; } object newFile = FolderPath + item.DUONGDAN_FILE; object a = 11; doc.SaveAs(ref newFile, ref a, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); doc.Close(ref saveChanges, ref oMissing, ref oMissing); app.Quit(ref saveChanges, ref Missing, ref Missing); doc.Close(); } catch (Exception ex) { doc.Close(); } #region ap dung chu ky so if (ENABLECHUKYSO.ToIntOrZero() == 1) { FileUltilities file = new FileUltilities(); string fileinput = FolderPath + item.DUONGDAN_FILE; string fileoutput = Path.GetDirectoryName(FolderPath + item.DUONGDAN_FILE) + Path.GetFileNameWithoutExtension(FolderPath + item.DUONGDAN_FILE) + "_1.docx"; if (System.IO.File.Exists(fileoutput)) { System.IO.File.Delete(fileoutput); } var signer = DocumentSigner.For(fileinput); var cert = CertUtil.GetFromFile(CHUKYSO, PASSCHUKYSO); var serial = cert.SerialNumber; signer.Sign(fileinput, fileoutput, cert); file.MoveFile(fileoutput, fileinput); } #endregion } } catch (Exception ex) { throw ex; } }