public void TestPackagePathLocation() { string packageID = "d1f7cade-cb74-4457-a9a0-27d94f5c2d5b"; string templateFileName = "Demo Employment Agreement.docx"; HotDocs.Sdk.PackagePathTemplateLocation location = CreatePackagePathLocation(packageID); Template template; Assert.IsTrue(File.Exists(location.PackagePath)); // Verify that null switches and key are resolved to empty strings. template = new Template(location, null, null); Assert.AreEqual("", template.Switches); Assert.AreEqual("", template.Key); Assert.IsTrue(template.HasInterview); template.Switches = "/nw /naw /ni"; Assert.IsFalse(template.HasInterview); string switches = "/ni"; string key = "Test file key"; template = new Template(location, switches, key); Assert.AreEqual(templateFileName, template.FileName); Assert.AreEqual(key, template.Key); Assert.AreEqual(switches, template.Switches); Assert.AreEqual("Employment Agreement (Word RTF version)", template.Title.Trim()); string filePath = template.GetFullPath(); Assert.IsTrue(File.Exists(filePath)); //Directory.Delete(Path.GetDirectoryName(filePath)); //Check the second time since the folder has been deleted. //filePath = template.GetFullPath();//The folder should come into existence here. //Assert.IsTrue(File.Exists(filePath)); //Directory.Delete(Path.GetDirectoryName(filePath));//Clean up. TestTemplate(template, new TemplateInfo() { Title = "Employment Agreement", DocExtension = ".docx", TmpType = TemplateType.WordDOCX, DocType = DocumentType.WordDOCX }); }
public void TestPathTemplateLocation() { string templateDir = Path.Combine(GetSamplePortalTemplateDir(), "TestTemplates"); Assert.IsTrue(Directory.Exists(templateDir)); PathTemplateLocation location = new PathTemplateLocation(templateDir); Template template; // Make sure that null fileName causes exception. try { template = new Template(null, location, null, null); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("fileName")); } // Make sure that null location causes exception. try { template = new Template("filename.docx", null, null, null); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("location")); } // Make sure that a null location causes exception. try { template = new Template(null, null, null); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("location")); } // Try to locate a template with a null locator. try { template = Template.Locate(null); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.IsTrue(ex.Message.Contains("locator")); } // Try to locate a template with an empty string locator. try { template = Template.Locate(""); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.IsTrue(ex.Message.Contains("locator")); } // Try to locate a template with an invalid template locator. try { template = Template.Locate(Util.EncryptString("abcdefg")); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("Invalid template locator.")); } try { HotDocs.Sdk.TemplateLocation.RegisterLocation(typeof(string)); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("The registered location must be of type TemplateLocation.")); } // Try to get the TemplateType for an unknown template type. template = new Template("filename.tfx", location, null, null); Assert.AreEqual(TemplateType.Unknown, template.TemplateType); Assert.AreEqual("", template.Title); // Verify that null switches and key resolve to empty string. template = new Template("Demo Employment Agreement.docx", location, null, null); Assert.AreEqual("", template.Switches); Assert.AreEqual("", template.Key); string switches = "/ni"; string key = "Test file key"; Dictionary<string, TemplateInfo> testTemplates = new Dictionary<string, TemplateInfo>(); testTemplates.Add("Demo Employment Agreement.docx", new TemplateInfo() { Title = "Employment Agreement", DocExtension = ".docx", TmpType = TemplateType.WordDOCX, DocType = DocumentType.WordDOCX }); testTemplates.Add("Sample rtf template.rtf", new TemplateInfo() { Title = "Sample rtf template", DocExtension = ".rtf", TmpType = TemplateType.WordRTF, DocType = DocumentType.WordRTF }); testTemplates.Add("Sample wpt template.wpt", new TemplateInfo() { Title = "Sample wpt template", DocExtension = ".wpd", TmpType = TemplateType.WordPerfect, DocType = DocumentType.WordPerfect }); testTemplates.Add("sample interview template.cmp", new TemplateInfo() { Title = "sample interview template", DocExtension = ".wpd", TmpType = TemplateType.InterviewOnly, DocType = DocumentType.Unknown }); testTemplates.Add("sample hft template.hft", new TemplateInfo() { Title = "sample hft template", DocExtension = ".hfd", TmpType = TemplateType.HotDocsHFT, DocType = DocumentType.HFD }); testTemplates.Add("sample pdf template.hpt", new TemplateInfo() { Title = "sample pdf template", DocExtension = ".pdf", TmpType = TemplateType.HotDocsPDF, DocType = DocumentType.PDF }); testTemplates.Add("sample ttx template.ttx", new TemplateInfo() { Title = "sample ttx template", DocExtension = ".txt", TmpType = TemplateType.PlainText, DocType = DocumentType.PlainText }); foreach (var t in testTemplates) { template = new Template(t.Key, location, switches, key); Assert.AreEqual(template.Title, t.Value.Title); string filePath = template.GetFullPath(); Assert.IsTrue(File.Exists(filePath)); TestTemplate(template, t.Value); } }