Esempio n. 1
0
		public void TestAddZipActionEncryptor_DocumentAlreadyZipped(string docFileName, string zipFileName, string password)
		{
			// Use function currying to keep the password.
			Func<FileType, string, string, string, ContentItem> CreateContentItem =
				(ft, fp, ci, pi) => CreateZipActionContentItem(password, ft, fp, ci, pi);

			// A message with null parent ID, because it's the top-most element.
			const string emailBodyId = "1";
			const string emailBodyName = "message subject/body";
			ContentItem emailContentItem = CreateContentItem(FileType.Email, emailBodyName, emailBodyId, null);

			// A zip with parent being email
			const string zipId = "2";
			string zipPath = Path.Combine(TestFileDirectory, zipFileName);
			ContentItem zipContentItem = CreateContentItem(FileType.ZIP, zipPath, zipId, emailBodyId);
			var zipAttachment = new Attachment(zipPath, zipPath, FileType.ZIP.ToString(), zipId, zipId, true);

			// A doc with parent being zip.
			const string docId = "3";
			string docPath = Path.Combine(TestFileDirectory, docFileName);
			ContentItem docContentItem = CreateContentItem(FileType.WordDocument, docPath, docId, zipId);

			using (ContentEncryptionManager manager = new ContentEncryptionManager())
			{
				var response = new Response { Contents = new[] { emailContentItem, zipContentItem, docContentItem } };
				manager.AddZipActionEncryptor(response);

				IContentEncryption contentEncryption = manager.GetAssociatedEncryptionObject(zipAttachment);
				Assert.IsNotNull(contentEncryption, "Expected the encryption map to contain the zip encryption entry.");
				Assert.AreEqual(zipPath, contentEncryption.Name, "The zip encryption name was wrong.");
				Assert.AreEqual(password, contentEncryption.OpenPassword, "The zip encryption \"open password\" was wrong.");
			}
		}
Esempio n. 2
0
		public void TestAddZipActionEncryptor_DocumentWillBeZipped(string docFileName, string password)
		{
			// Use function currying to keep the password.
			Func<FileType, string, string, string, ContentItem> CreateContentItem =
				(ft, fp, ci, pi) => CreateZipActionContentItem(password, ft, fp, ci, pi);

			// A message with null parent ID, because it's the top-most element.
			const string emailBodyId = "1";
			const string emailBodyName = "message subject/body";
			ContentItem emailContentItem = CreateContentItem(FileType.Email, emailBodyName, emailBodyId, null);

			// A doc with parent being the email.
			const string docId = "2";
			string docPath = Path.Combine(TestFileDirectory, docFileName);
			ContentItem docContentItem = CreateContentItem(FileType.WordDocument, docPath, docId, emailBodyId);

			// Expected info that the newly created zip should have.
			const string zipId = docId;
			string zipPath = Path.ChangeExtension(docPath, ".zip");
			var zipAttachment = new Attachment(zipPath, zipPath, FileType.ZIP.ToString(), zipId, zipId, true);

			using (ContentEncryptionManager manager = new ContentEncryptionManager())
			{
				var response = new Response { Contents = new[] { emailContentItem, docContentItem } };
				manager.AddZipActionEncryptor(response);

				ContentItem foundDocItem = response.Contents.SingleOrDefault(i => i.Name == docPath);
				ContentItem foundZipItem = response.Contents.SingleOrDefault(i => i.Name == zipPath);

				// Test that the doc content item still exists and a new zip content item has been added.
				Assert.IsNotNull(foundDocItem, "Unable to find the document content item.");
				Assert.IsNotNull(foundZipItem, "Unable to find the zip content item.");

				// Make that
				Assert.AreNotEqual(docId, foundDocItem.Id, "The document content ID should have been changed.");
				Assert.AreEqual(zipId, foundDocItem.ParentId, "The document content item's parent ID should now be the document's original ID.");
				Assert.AreEqual(zipId, foundZipItem.Id, "The zip content ID should now be the document's original content ID.");
				Assert.AreEqual(emailBodyId, foundZipItem.ParentId, "The zip content item's parent ID should be the message ID.");

				IContentEncryption contentEncryption = manager.GetAssociatedEncryptionObject(zipAttachment);
				Assert.IsNotNull(contentEncryption, "Expected the encryption map to contain the zip encryption entry.");
				Assert.AreEqual(zipPath, contentEncryption.Name, "The zip encryption name was wrong.");
				Assert.AreEqual(password, contentEncryption.OpenPassword, "The zip encryption \"open password\" was wrong.");
			}
		}