public void ParsesCorrectNumberOfComponents()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("SomeOrigin").WithStereoTypes("Origin.*")
                                                    .Component("SomeTarget").WithStereoTypes("Target.*")
                                                    .Write());

            Assert.Equal(2, diagram.AllComponents.Count);
        }
        public void ParsesTwoIdenticalComponentsNoDependency()
        {
            PlantUmlDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream)
                                                    .Component("someName").WithAlias("someAlias").WithStereoTypes("someStereotype")
                                                    .Component("someName").WithAlias("someAlias").WithStereoTypes("someStereotype")
                                                    .Write());

            Assert.Equal(new[] { GetComponentWithName("someName", diagram) }, diagram.AllComponents);
        }
        public void RejectsAComponentWithAnIllegalAlias()
        {
            TestDiagram.From(_memoryStream)
            .Component("irrelevant").WithAlias("ill[]egal").WithStereoTypes("Irrelevant.*")
            .Write();

            IllegalDiagramException exception = Assert.Throws <IllegalDiagramException>(() => CreateDiagram(_memoryStream));

            Assert.Contains("Alias 'ill[]egal' should not contain character(s): '[' or ']' or '\"'", exception.Message);
        }
        public void ThrowsExceptionWithComponentsWithoutStereotypes()
        {
            TestDiagram.From(_memoryStream)
            .RawLine("[componentWithoutStereotype]")
            .Write();

            IllegalDiagramException exception = Assert.Throws <IllegalDiagramException>(() => CreateDiagram(_memoryStream));

            Assert.Contains("componentWithoutStereotype", exception.Message);
            Assert.Contains("at least one stereotype specifying the namespace identifier (<<.*>>)", exception.Message);
        }
        public void ThrowsExceptionWithComponentsThatAreNotYetDefined()
        {
            TestDiagram.From(_memoryStream)
            .DependencyFrom("[NotYetDefined]").To("[AlsoNotYetDefined]")
            .Write();

            IllegalDiagramException exception = Assert.Throws <IllegalDiagramException>(() => CreateDiagram(_memoryStream));

            Assert.Contains("There is no Component with name or alias = 'NotYetDefined'", exception.Message);
            Assert.Contains("Components must be specified separately from dependencies", exception.Message);
        }
        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 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 ReportsIfClassIsContainedInAnyComponent()
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream)
                                                                                    .Component("Object").WithStereoTypes(typeof(object).Namespace)
                                                                                    .Write());

                Assert.True(classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(object))), "association contains " + typeof(object).Name);
                Assert.False(classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(Class2))), "association contains " + typeof(Class2).Name);
            }
        }
        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 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"));
        }
        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);
        }
        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"));
        }
        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);
        }
        public void GetNamespaceIdentifierAssociatedWithClass()
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                string expectedNamespaceIdentifier = typeof(SomeOriginClass).Namespace;
                ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream)
                                                                                    .Component("A").WithStereoTypes(expectedNamespaceIdentifier)
                                                                                    .Component("B").WithStereoTypes(".*.Noclasshere")
                                                                                    .Write());

                Class clazz = Architecture.GetClassOfType(typeof(SomeOriginClass));
                Assert.Equal(expectedNamespaceIdentifier, classDiagramAssociation.GetNamespaceIdentifiersFromComponentOf(clazz).Single());
            }
        }
        public void RejectsClassNotContainedInAnyComponent()
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream)
                                                                                    .Component("SomeComponent").WithStereoTypes(".*.SomeStereotype.")
                                                                                    .Write());

                Class classNotContained = Architecture.GetClassOfType(typeof(object));

                InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => classDiagramAssociation.GetTargetNamespaceIdentifiers(classNotContained));
                Assert.Equal(string.Format("Class {0} is not contained in any component", typeof(object).Name), exception.Message);
            }
        }
        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);
        }
        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);
        }
        public void RejectsDuplicateStereotype()
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                TestDiagram.From(memoryStream)
                .Component("first").WithStereoTypes(".*.Identical.*")
                .Component("second").WithStereoTypes(".*.Identical.*")
                .Write();

                Class classContainedInTwoComponents = Architecture.GetClassOfType(typeof(ClassInFooAndBarNamespace));

                IllegalDiagramException exception = Assert.Throws <IllegalDiagramException>(() => CreateAssociation(memoryStream));
                Assert.Equal("Stereotype '.*.Identical.*' should be unique", exception.Message);
            }
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        public void ClassResidesInMultipleNamespaces()
        {
            string path = Path.Combine(Path.GetTempPath(), "plantuml_diagram_" + Guid.NewGuid() + ".puml");

            using (FileStream fileStream = File.Create(path))
            {
                TestDiagram.From(fileStream)
                .Component("A").WithStereoTypes(".*.FooNamespace.*")
                .Component("B").WithStereoTypes(".*.BarNamespace.*")
                .Write();
            }

            ClassDiagramAssociation classDiagramAssociation = CreateAssociation(path);
            Class classContainedInTwoComponents             = Architecture.GetClassOfType(typeof(ClassInFooAndBarNamespace));

            ComponentIntersectionException exception = Assert.Throws <ComponentIntersectionException>(() => classDiagramAssociation.GetTargetNamespaceIdentifiers(classContainedInTwoComponents));

            Assert.Equal(string.Format("Class {0} may not be contained in more than one component, but is contained in [A, B]", typeof(ClassInFooAndBarNamespace).Name), exception.Message);
        }
        public void GetTargetNamespaceIdentifierOfClass()
        {
            string expectedTarget1 = ".*.Target1";
            string expectedTarget2 = ".*.Target2";

            using (MemoryStream memoryStream = new MemoryStream())
            {
                ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream)
                                                                                    .Component("A").WithStereoTypes(Regex.Replace(typeof(SomeOriginClass).Namespace, @".*\.", ".*."))
                                                                                    .Component("B").WithStereoTypes(expectedTarget1)
                                                                                    .Component("C").WithStereoTypes(expectedTarget2)
                                                                                    .DependencyFrom("[A]").To("[B]")
                                                                                    .DependencyFrom("[A]").To("[C]")
                                                                                    .Write());

                Class clazz = Architecture.GetClassOfType(typeof(SomeOriginClass));

                Assert.Equal(new[] { expectedTarget1, expectedTarget2 }, classDiagramAssociation.GetTargetNamespaceIdentifiers(clazz).OrderBy(s => s).ToList());
            }
        }
        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);
        }
Exemple #27
0
 public DependencyFromCreator(string origin, TestDiagram testDiagram)
 {
     _origin      = origin;
     _testDiagram = testDiagram;
 }
Exemple #28
0
 public DependencyToCreator(string target, TestDiagram testDiagram)
 {
     _target      = target;
     _testDiagram = testDiagram;
 }
Exemple #29
0
 public ComponentBuilder(string componentName, TestDiagram testDiagram)
 {
     ComponentName = componentName;
     _testDiagram  = testDiagram;
 }