[英]Unit testing umbraco based sites
有沒有辦法測試依賴於umbraco的代碼。 即在我的模型中,我正在調用getNode或使用uquery來獲取節點,但我無法測試這些類,因為它們依賴於umbraco ...
我想解決這個問題的一種方法是通過模擬,但你怎么能模擬uquery或nodefactory?
我不相信CMS系統自然適合於單元測試,因為輸出並不總是像業務邏輯那樣切割和干燥。
但是(總有一個但是)你可以模擬節點的生成 - 操縱它們並至少檢查錯誤。 一個示例單元測試將是創建具有一些必需字段和一些可選字段的文檔類型 - 然后僅在必填字段之前填充具有必填字段的內容節點 - 然后該字段應該是錯誤的。 不過,我認為你不能通過代碼添加屬性作為強制性。
(另請參閱: 如何從代碼中向Umbraco中的文檔類型添加屬性? http: //our.umbraco.org/wiki/reference/api-cheatsheet/creating-a-document http://our.umbraco.org / wiki / how-tos / working-with-document-types )
就像是:
var alias = "aliasOfOptionalField";
var value = string.Empty;
var docType = "Textpage";
DocumentType dt = DocumentType.GetByAlias(docType);
User author = User.GetUser(0);
Document doc = Document.MakeNew("My new document", dt, author, 1018);
doc.Publish(author);
umbraco.library.UpdateDocumentCache(doc.Id);
var newProperty = dt.AddPropertyType(new DataTypeDefinition(-49), alias, "test prop");
if (doc.HasProperty(alias))
{
doc.getProperty(alias).Value = value;
doc.Publish(new User(0));
library.UpdateDocumentCache(doc.Id);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.