/// <summary> /// 初始化 <see cref="RelationshipMetadata"/> 类的新实例。 /// </summary> /// <param name="thisType"></param> /// <param name="otherType"></param> /// <param name="style"></param> /// <param name="keys"></param> internal RelationshipMetadata(Type thisType, Type otherType, RelationshipStyle style, IEnumerable <RelationshipKey> keys) { ThisType = thisType; OtherType = otherType; Style = style; Keys = keys.ToReadOnly(); }
public void Test_Color_ThrowsAnException_WhenAnInvalidHexColorCodeIsSpecified() { try { RelationshipStyle style = new RelationshipStyle(); style.Color = "white"; throw new TestFailedException(); } catch (ArgumentException ae) { Assert.Equal("'white' is not a valid hex color code.", ae.Message); } }
public void Test_Color_SetsTheColorProperty_WhenAValidHexColorCodeIsSpecified() { RelationshipStyle style = new RelationshipStyle(); style.Color = "#ffffff"; Assert.Equal("#ffffff", style.Color); style.Color = "#FFFFFF"; Assert.Equal("#ffffff", style.Color); style.Color = "#123456"; Assert.Equal("#123456", style.Color); }
protected RelationshipStyleBase(Structurizr.Styles styles, Action <ElementType, string> onCreatedFromExistingElement) { var styleName = NamedIdentity.GetNameFromType(GetType()); var tagName = styleName.Substring(0, styleName.Length - " Line Style".Length); _default = styles.Relationships.FirstOrDefault(x => x.Tag == tagName); if (_default == null) { _default = new RelationshipStyle(tagName); styles.Relationships.Add(_default); } else { onCreatedFromExistingElement(ElementType.RelationStyle, tagName); } }
public void Test_Position() { RelationshipStyle style = new RelationshipStyle(); Assert.Null(style.Position); style.Position = -1; Assert.Equal(0, style.Position); style.Position = 0; Assert.Equal(0, style.Position); style.Position = 50; Assert.Equal(50, style.Position); style.Position = 100; Assert.Equal(100, style.Position); style.Position = 101; Assert.Equal(100, style.Position); }
public void Test_Opacity() { RelationshipStyle style = new RelationshipStyle(); Assert.Null(style.Opacity); style.Opacity = -1; Assert.Equal(0, style.Opacity); style.Opacity = 0; Assert.Equal(0, style.Opacity); style.Opacity = 50; Assert.Equal(50, style.Opacity); style.Opacity = 100; Assert.Equal(100, style.Opacity); style.Opacity = 101; Assert.Equal(100, style.Opacity); }
private string GetRelationshipExpression(IProperty thisProperty, IProperty otherProperty, RelationshipStyle style) { switch (style) { case RelationshipStyle.One2One: return(string.Format("{0}=={1}", thisProperty, otherProperty)); case RelationshipStyle.One2Many: return(string.Format("{0}=>{1}", thisProperty, otherProperty)); case RelationshipStyle.Many2One: return(string.Format("{0}<={1}", thisProperty, otherProperty)); default: return(string.Empty); } }
/// <summary> /// 定义两个实体类间的关系。 /// </summary> /// <param name="thisType"></param> /// <param name="otherType"></param> /// <param name="thisProperty"></param> /// <param name="otherProperty"></param> /// <param name="style"></param> public void DefineRelation(Type thisType, Type otherType, IProperty thisProperty, IProperty otherProperty, RelationshipStyle style) { var relationName = thisType.Name + ":" + otherType.Name; m_assemblyBuilder.SetCustomAttribute(() => new RelationshipAttribute(relationName, thisType, otherType, GetRelationshipExpression(thisProperty, otherProperty, style))); }
internal C4Builder AddStyle(RelationshipStyle relationshipStyle) { _workspace.Views.Configuration.Styles.Add(relationshipStyle); return(this); }
private string GetRelationshipExpression(IProperty thisProperty, IProperty otherProperty, RelationshipStyle style) { return(style switch { RelationshipStyle.One2One => $"{thisProperty}=={otherProperty}", RelationshipStyle.One2Many => $"{thisProperty}=>{otherProperty}", RelationshipStyle.Many2One => $"{thisProperty}<={otherProperty}", _ => string.Empty, });