private PlantUmlComponent GetComponentWithName(string componentName, PlantUmlDiagram diagram)
        {
            PlantUmlComponent component = diagram.AllComponents
                                          .Where(comp => Equals(comp.ComponentName, new ComponentName(componentName)))
                                          .First();

            return(component);
        }
        public void ParsesASimpleComponent()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("SomeOrigin").WithStereoTypes("Origin.*")
                                                    .Write());

            PlantUmlComponent origin = GetComponentWithName("SomeOrigin", diagram);

            Assert.Equal(origin.Stereotypes.SingleOrDefault(), new Stereotype("Origin.*"));
            Assert.Null(origin.Alias);
        }
        public void ParsesComponentDiagramWithMultipleStereotypesAndAlias()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("someComponent").WithAlias("someAlias")
                                                    .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*")
                                                    .Write());

            PlantUmlComponent component = diagram.AllComponents.Single();

            Assert.Equal(new Alias("someAlias"), component.Alias);
        }
        public void ParsesComponentDiagramWithMultipleStereotypes()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("someComponent")
                                                    .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*")
                                                    .Write());

            PlantUmlComponent component = diagram.AllComponents.Single();

            Assert.Equal(new[] { new Stereotype("FirstNamespace.*"), new Stereotype("SecondNamespace.*"), new Stereotype("ThirdNamespace.*") },
                         component.Stereotypes.OrderBy(st => st.AsString()));
        }
        public void ParsesDependenciesBetweenComponentsWithoutBrackets()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("A").WithStereoTypes("Origin.*")
                                                    .Component("B").WithStereoTypes("Target.*")
                                                    .DependencyFrom("A").To("B")
                                                    .Write());

            PlantUmlComponent a = GetComponentWithName("A", diagram);
            PlantUmlComponent b = GetComponentWithName("B", diagram);

            Assert.Equal(new[] { b }, a.Dependencies);
        }
示例#6
0
        public void TwoComponentsWithSameNameStereoTypeAndAliasHaveSameHashCode()
        {
            var component1 = new PlantUmlComponent(new ComponentName("someName"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));
            var component2 = new PlantUmlComponent(new ComponentName("someName"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));

            Assert.Equal(component1.GetHashCode(), component2.GetHashCode());
        }
        public void DoesNotIncludeDependencyDescriptions()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("component").WithStereoTypes("SomeNamespace.*")
                                                    .Component("otherComponent").WithStereoTypes("SomeNamespace2.*")
                                                    .RawLine("[component] --> [otherComponent] : this part should be ignored, no matter the comment tick ' ")
                                                    .Write());

            PlantUmlComponent component = GetComponentWithName("component", diagram);
            PlantUmlComponent targetOfDescribedDependency = component.Dependencies.Single();

            Assert.Equal(targetOfDescribedDependency.ComponentName, new ComponentName("otherComponent"));
        }
示例#8
0
        public void TwoComponentsWithSameNameStereoTypeAndAliasShouldBeEqual()
        {
            var component1 = new PlantUmlComponent(new ComponentName("someName"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));
            var component2 = new PlantUmlComponent(new ComponentName("someName"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));

            Assert.Equal(component1, component2);
        }
示例#9
0
        public void TwoNonIdenticalComponentsShouldNotBeEqual()
        {
            var component1 = new PlantUmlComponent(new ComponentName("someName1"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));
            var component2 = new PlantUmlComponent(new ComponentName("someName2"), new HashSet <Stereotype>()
            {
                new Stereotype("someStereoType")
            }, new Alias("someAlias"));

            Assert.NotEqual(component1, component2);
        }
示例#10
0
        public void ParsesVariousTypesOfDependencyArrows(string dependency)
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("SomeOrigin").WithStereoTypes("Origin.*")
                                                    .Component("SomeTarget").WithStereoTypes("Target.*")
                                                    .RawLine(dependency)
                                                    .Write());

            PlantUmlComponent component = GetComponentWithName("SomeOrigin", diagram);
            PlantUmlComponent target    = component.Dependencies.Single();

            Assert.Equal(target.ComponentName, new ComponentName("SomeTarget"));
        }
示例#11
0
        public void ParsesATrickyAlias()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("tricky").WithAlias("because it's quoted").WithStereoTypes("Tricky.*")
                                                    .Component("tricky as hell cause of as keyword").WithAlias("other").WithStereoTypes("Other.*")
                                                    .Write());

            PlantUmlComponent trickyAsHell = GetComponentWithName("tricky as hell cause of as keyword", diagram);
            PlantUmlComponent tricky       = GetComponentWithName("tricky", diagram);

            Assert.Equal(new Alias("other"), trickyAsHell.Alias);
            Assert.Equal(new Alias("because it's quoted"), tricky.Alias);
        }
示例#12
0
        public void DoesNotIncludeCommentedOutLines()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("uncommentedComponent").WithAlias("uncommentedAlias").WithStereoTypes("UncommentedNamespace.*")
                                                    .RawLine("  '  [commentedComponent] <<CommentedNamespace.*>> as commentedAlias")
                                                    .RawLine("")
                                                    .RawLine(" ' [uncommentedComponent] --> [commentedComponent]")
                                                    .Write());

            PlantUmlComponent uncommentedComponent = GetComponentWithName("uncommentedComponent", diagram);

            Assert.Equal(diagram.AllComponents.Single(), uncommentedComponent);
            Assert.Empty(uncommentedComponent.Dependencies);
        }
示例#13
0
        public void ParsesDependencyOfSimpleComponentDiagram(Func <TestDiagram, TestDiagram> testCaseFunc)
        {
            TestDiagram initialDiagram = TestDiagram.From(_memoryStream)
                                         .Component("SomeOrigin").WithStereoTypes("Origin.*")
                                         .Component("SomeTarget").WithStereoTypes("Target.*");
            PlantUmlDiagram diagram = CreateDiagram(testCaseFunc(initialDiagram).Write());

            PlantUmlComponent origin = GetComponentWithName("SomeOrigin", diagram);
            PlantUmlComponent target = origin.Dependencies.Single();

            Assert.Equal(target.ComponentName, new ComponentName("SomeTarget"));
            Assert.Empty(target.Dependencies);
            Assert.Equal(new Stereotype("Target.*"), target.Stereotypes.Single());
            Assert.Null(target.Alias);
        }
示例#14
0
        public void ParsesDiagramWithDependenciesThatUseAlias()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("A").WithAlias("aliasForA").WithStereoTypes("Controller.*")
                                                    .Component("B").WithAlias("aliasForB").WithStereoTypes("Service.*")
                                                    .DependencyFrom("aliasForA").To("aliasForB")
                                                    .Write());

            PlantUmlComponent aliasForA = GetComponentWithAlias(new Alias("aliasForA"), diagram);
            PlantUmlComponent aliasForB = GetComponentWithAlias(new Alias("aliasForB"), diagram);

            Assert.Equal(aliasForA, GetComponentWithName("A", diagram));
            Assert.Equal(aliasForB, GetComponentWithName("B", diagram));
            Assert.Equal(new[] { aliasForB }, aliasForA.Dependencies);
        }
示例#15
0
        public void ParseAComponentDiagramWithBothAliasAndNamesUsed()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("A").WithAlias("foo").WithStereoTypes(".Service.*")
                                                    .Component("B").WithStereoTypes("Controller.*")
                                                    .DependencyFrom("[B]").To("foo")
                                                    .DependencyFrom("foo").To("[B]")
                                                    .Write());

            PlantUmlComponent componentB   = GetComponentWithName("B", diagram);
            PlantUmlComponent componentFoo = GetComponentWithAlias(new Alias("foo"), diagram);

            Assert.Equal(new[] { componentFoo }, componentB.Dependencies);
            Assert.Equal(new[] { componentB }, componentFoo.Dependencies);
        }
示例#16
0
        public void ParsesAComponentDiagramThatUsesAliasWithAndWithoutBrackets()
        {
            TestDiagram.From(_memoryStream)
            .Component("A").WithAlias("foo").WithStereoTypes("Origin.*")
            .Component("B").WithAlias("bar").WithStereoTypes("Target.*")
            .DependencyFrom("foo").To("bar")
            .DependencyFrom("[foo]").To("[bar]")
            .Write();

            PlantUmlDiagram diagram = CreateDiagram(_memoryStream);

            PlantUmlComponent foo = GetComponentWithAlias(new Alias("foo"), diagram);
            PlantUmlComponent bar = GetComponentWithAlias(new Alias("bar"), diagram);

            Assert.Equal(new[] { bar }, foo.Dependencies);
            Assert.Empty(bar.Dependencies);
        }
示例#17
0
        public void ParsesASimpleComponentWithFile()
        {
            string path = Path.Combine(Path.GetTempPath(), "plantuml_diagram_" + Guid.NewGuid() + ".puml");

            using (FileStream fileStream = File.Create(path))
            {
                TestDiagram.From(fileStream)
                .Component("SomeOrigin").WithStereoTypes("Origin.*")
                .Write();
            }

            PlantUmlDiagram diagram = CreateDiagram(path);

            PlantUmlComponent origin = GetComponentWithName("SomeOrigin", diagram);

            Assert.Equal(origin.Stereotypes.SingleOrDefault(), new Stereotype("Origin.*"));
            Assert.Null(origin.Alias);
        }
示例#18
0
        public void ParsesADiagramWithNoUniqueOrigins()
        {
            TestDiagram.From(_memoryStream)
            .Component("Component1").WithStereoTypes("Origin.*")
            .Component("Component2").WithStereoTypes("Target1.*")
            .Component("Component3").WithStereoTypes("Target2.*")
            .DependencyFrom("[Component1]").To("[Component2]")
            .DependencyFrom("[Component1]").To("[Component3]")
            .Write();

            PlantUmlDiagram diagram = CreateDiagram(_memoryStream);

            PlantUmlComponent component1 = GetComponentWithName("Component1", diagram);
            PlantUmlComponent component2 = GetComponentWithName("Component2", diagram);
            PlantUmlComponent component3 = GetComponentWithName("Component3", diagram);

            Assert.Equal(new[] { component2, component3 }, component1.Dependencies);
        }
示例#19
0
        public void ParsesMultipleComponentsAndDependencies()
        {
            TestDiagram.From(_memoryStream)
            .Component("Component1").WithStereoTypes("Origin1.*")
            .Component("Component2").WithStereoTypes("Target1.*")
            .Component("Component3").WithStereoTypes("Origin2.*")
            .Component("Component4").WithStereoTypes("Target2.*")
            .DependencyFrom("Component1").To("Component2")
            .DependencyFrom("Component3").To("Component4")
            .Write();

            PlantUmlDiagram diagram = CreateDiagram(_memoryStream);

            PlantUmlComponent component1 = GetComponentWithName("Component1", diagram);
            PlantUmlComponent component2 = GetComponentWithName("Component2", diagram);
            PlantUmlComponent component3 = GetComponentWithName("Component3", diagram);
            PlantUmlComponent component4 = GetComponentWithName("Component4", diagram);

            Assert.Equal(new[] { component1, component2, component3, component4 }, diagram.AllComponents.OrderBy(c => c.ComponentName.AsString()));
            Assert.Equal(new[] { component2 }, component1.Dependencies);
            Assert.Empty(component2.Dependencies);
            Assert.Equal(new[] { component4 }, component3.Dependencies);
            Assert.Empty(component4.Dependencies);
        }