/// <summary> /// 以<paramref name="id" />为<see cref="Id"/>, /// <paramref name="metadata"/>为<see cref="Metadata"/>创建新节点。 /// 节点各属性其类型的赋默认值(但string赋string.Empty)。 /// </summary> public Node(string id, NodeMetadata metadata) { Id = id; _metadata = metadata; _properties = (from pm in Metadata.Properties let value = DefaultValueFor(pm.Type) select new NodeProperty(pm, value)).ToList(); }
private static INodeManager MockNodeManager() { var mockNodeManager = new Mock<INodeManager>(); var nodeMetadata = new NodeMetadata("知识点", new[] { new NodePropertyMetadata("标题", typeof (string)), new NodePropertyMetadata("内容", typeof (MsDoc)) }); mockNodeManager.Setup(m => m.GetNodeById(It.IsAny<string>())) .Returns<string>(id => { dynamic node = new Node(id, nodeMetadata); node.标题 = "Title for " + id; return node; }); mockNodeManager.Setup(m => m.AddNode(It.IsAny<Node>())) .Callback((Node node) => { Debug.WriteLine("Add Node"); }); mockNodeManager.Setup(m => m.UpdateNode(It.IsAny<Node>())) .Callback((Node node) => { Debug.WriteLine("Update Node"); }); mockNodeManager.Setup(m => m.DeleteNode(It.IsAny<Node>())) .Callback((Node node) => { Debug.WriteLine("Delete Node"); }); return mockNodeManager.Object; }
/// <summary> /// 从<paramref name="metadata"/>复制得到一份新的<see cref="NodeMetadata"/>对象。 /// </summary> public NodeMetadata(NodeMetadata metadata) { Name = metadata.Name; Properties = new List<NodePropertyMetadata>(metadata.Properties); }
/// <summary> /// 以<paramref name="metadata"/>为<see cref="Metadata"/>创建新节点。 /// 节点<see cref="Id"/>自动生成。 /// 节点各属性其类型的赋默认值(但string赋string.Empty)。 /// </summary> public Node(NodeMetadata metadata) : this(Guid.NewGuid().ToString(), metadata) { }