Skip to content

Commit

Permalink
Merge pull request #6 from lstrzepek/fixes/wrong-direction-relations
Browse files Browse the repository at this point in the history
Fixed relations drew in wrong direction
  • Loading branch information
lstrzepek committed Dec 11, 2022
2 parents be87c18 + 0de7383 commit 1bfd19f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public void AddClass_WithAttributeWithTypeWithSpecialCharacters_ShouldDisplayCla
}.ToDiagram());
}



[Fact]
public void TwoEmptyClasses_WithRelation_ShouldDisplayRelationOnly()
{
Expand All @@ -63,7 +61,7 @@ public void TwoEmptyClasses_WithRelation_ShouldDisplayRelationOnly()
var diagram = sut.Generate();
diagram.Should().Be(new[]{
"classDiagram",
"ClassA <|-- ClassB"
"ClassA --|> ClassB"
}.ToDiagram());
}
}
Expand Down
41 changes: 20 additions & 21 deletions DomainModel.Generator.Mermaid/ClassDiagramGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ public IClass AddClass(string name)
classes.TryGetValue(name, out var @class);
return @class;
}
private void AddRelation(IClass classA, IClass classB, string symbol, string? label = default)
private void AddRelation(IClass from, IClass to, string symbol, string? label = default)
{
HashSet<string> key = new(new[] { classA.Name, classB.Name });
HashSet<string> key = new(new[] { from.Name, to.Name });
if (!relations.ContainsKey(key))
relations.Add(key, new Relation(
classA.Name,
classB.Name,
from.Name,
to.Name,
symbol,
label
));
}
public void LinkWithInheritance(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "<|--", label);
public void LinkWithComposition(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "*--", label);
public void LinkWithAggregation(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "o--", label);
public void LinkWithAssociation(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "<--", label);
public void LinkSolid(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "--", label);
public void LinkDashed(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "..", label);
public void LinkWithDependency(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "<..", label);
public void LinkWithRealization(IClass classA, IClass classB, string? label = default)
=> AddRelation(classA, classB, "<|..", label);
public void LinkWithInheritance(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "--|>", label);
public void LinkWithComposition(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "--*", label);
public void LinkWithAggregation(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "--o", label);
public void LinkWithAssociation(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "-->", label);
public void LinkSolid(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "--", label);
public void LinkDashed(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "..", label);
public void LinkWithDependency(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "..>", label);
public void LinkWithRealization(IClass from, IClass to, string? label = default)
=> AddRelation(from, to, "..|>", label);

private bool RelationExist(string className) => relations.Keys.Any(r => r.Contains(className));

Expand All @@ -80,7 +80,6 @@ public string Generate()
}
class ClassDescription : IClass
{

public bool IsEmpty { get; private set; } = true;
private readonly System.Text.StringBuilder diagramBuilder;
public ClassDescription(string name)
Expand Down

0 comments on commit 1bfd19f

Please sign in to comment.