示例#1
0
        public void ShouldReturnTrueForSequenceDiagramIsEmptyBecauseOnlyCallsToStrangers()
        {
            //Arrange
            var sdType = new SDType("SharpDox.UML.Tests.DiagramExtensionsTests", "DiagramExtensionTests", new SDNamespace("SharpDox.UML.Tests"));
            var sdMethod = new SDMethod("SharpDox.UML.Tests.DiagramExtensionsTests.Method1", "Method1");

            var sdTypeStranger = new SDType("System.String", "String", new SDNamespace("System"));
            var sdMethodStranger = new SDMethod("System.String.Method1", "Method1");

            var sdNode = new SDTargetNode();
            sdNode.CalledType = sdTypeStranger;
            sdNode.CalledMethod = sdMethodStranger;
            sdNode.CallerMethod = sdMethod;
            sdNode.CallerType = sdType;

            sdMethod.Calls.Add(sdNode);

            //Act
            var isEmpty = sdMethod.IsSequenceDiagramEmpty();

            //Assert
            Assert.AreEqual(true, isEmpty);
        }
示例#2
0
        public void ShouldReturnFalseForSequenceDiagramIsEmpty()
        {
            //Arrange
            var sdType = new SDType("SharpDox.UML.Tests.DiagramExtensionsTests", "DiagramExtensionTests", new SDNamespace("SharpDox.UML.Tests"));
            sdType.IsProjectStranger = false;
            var sdMethod = new SDMethod("SharpDox.UML.Tests.DiagramExtensionsTests.Method1", "Method1");

            var sdNode = new SDTargetNode();
            sdNode.CalledMethod = new SDMethod("SharpDox.UML.Tests.DiagramExtensionsTests.Method2", "Method2");
            sdNode.CallerMethod = sdMethod;
            sdNode.CallerType = sdType;
            sdNode.CalledType = sdType;

            //Add this node twice, because the check will skipp call number one
            //because this one is usually the first call to the method itself
            sdMethod.Calls.Add(sdNode);
            sdMethod.Calls.Add(sdNode);

            //Act
            var isEmpty = sdMethod.IsSequenceDiagramEmpty();

            //Assert
            Assert.AreEqual(false, isEmpty);
        }
示例#3
0
        private void ParseTargetExpression(InvocationExpressionSyntax expression)
        {
            var compilation = _file.Project.GetCompilationAsync().Result;
            var symbolInfo = compilation.GetSemanticModel(_file.GetSyntaxTreeAsync().Result).GetSymbolInfo(expression);

            if (symbolInfo.Symbol != null)
            {
                var member = symbolInfo.Symbol;
                var method = member as IMethodSymbol;

                if (method != null)
                {
                    var callerType = _type;
                    var callerMethod = _method;

                    SDType calledType = null;
                    var sdType = _repository.GetTypeByIdentifier(member.ContainingType.GetIdentifier());
                    if (sdType == null)
                    {
                        var sdNamespace = _repository.GetNamespaceByIdentifier(member.ContainingNamespace.GetIdentifier());
                        sdNamespace = sdNamespace ?? new SDNamespace(member.ContainingNamespace.GetIdentifier()) { IsProjectStranger = true };
                        calledType = new SDType(member.ContainingType.GetIdentifier(), member.ContainingType.Name, sdNamespace) { IsProjectStranger = true };
                    }
                    else
                    {
                        calledType = sdType;
                    }

                    SDMethod calledMethod = null;
                    if (calledType.IsProjectStranger)
                    {
                        calledMethod = new SDMethod(method.GetIdentifier(), method.Name);
                    }
                    else
                    {
                        SDMethod sdMethod = sdType.Methods.Concat(sdType.Constructors).SingleOrDefault(m => m.Identifier == method.GetIdentifier());
                        if (sdMethod != null)
                        {
                            calledMethod = sdMethod;
                        }
                    }

                    // Only add method, if it is project stranger, public or private (if not only public members option on)
                    if (calledMethod != null)
                    {
                        var token = new SDTargetNode
                        {
                            CalledType = calledType,
                            CallerType = callerType,
                            CalledMethod = calledMethod,
                            CallerMethod = callerMethod
                        };

                        _tokenList.Add(token);
                    }
                }
            }
        }
示例#4
0
        private void ParseTargetNode(SequenceDiagramComposite composite, SDTargetNode targetNode)
        {
            if (!targetNode.CalledType.IsProjectStranger)
            {
                var caller = _sequenceDiagram.Nodes.SingleOrDefault(o => o.TypeIdentifier == targetNode.CallerType.Identifier);
                caller = caller == null ? _sequenceDiagram.Nodes.Single(o => o.ID == _sequenceDiagram.StartNodeID) : caller;

                var called = _sequenceDiagram.Nodes.SingleOrDefault(o => o.TypeIdentifier == targetNode.CalledType.Identifier) ?? _sequenceDiagram.AddNode(targetNode.CalledType.Identifier);

                composite.AddConnection(caller.ID, called.ID, targetNode.CalledMethod.Name, targetNode.CalledMethod.Identifier);

                var sdType = _sdRepository.GetTypeByIdentifier(targetNode.CalledType.Identifier);
                var targetMethod = sdType.Methods.SingleOrDefault(o => o.Identifier == targetNode.CalledMethod.Identifier);
                if (caller.ID != called.ID && targetMethod.ReturnType != null && targetMethod.ReturnType.Name.ToUpper() != "VOID")
                {
                    composite.AddConnection(called.ID, caller.ID, targetMethod.ReturnType.Name, targetNode.CalledMethod.Identifier, true);
                }
            }
        }
示例#5
0
        private void ParseTargetExpression(Expression expression)
        {
            if (_file != null)
            {
                var resolver = new CSharpAstResolver(_file.Project.Compilation, _file.SyntaxTree, _file.UnresolvedTypeSystemForFile);
                var resolveResult = resolver.Resolve(expression);

                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var member = ((CSharpInvocationResolveResult)resolveResult).Member;
                    var method = member as IMethod;

                    if (method != null)
                    {
                        var callerType = _type;
                        var callerMethod = _method;

                        SDType calledType = null;
                        var sdType = _repository.GetTypeByIdentifier(member.DeclaringType.GetIdentifier());
                        if (sdType == null)
                        {
                            var sdNamespace = _repository.GetNamespaceByIdentifier(member.DeclaringType.Namespace);
                            sdNamespace = sdNamespace == null ? new SDNamespace(member.DeclaringType.Namespace) { IsProjectStranger = true } : sdNamespace;
                            calledType = new SDType(member.DeclaringType.GetIdentifier(), member.DeclaringType.Name, sdNamespace) { IsProjectStranger = true };
                        }
                        else
                        {
                            calledType = sdType;
                        }

                        SDMethod calledMethod = null;
                        if (calledType.IsProjectStranger)
                        {
                            calledMethod = new SDMethod(method.GetIdentifier(), method.Name);
                        }
                        else
                        {
                            SDMethod sdMethod = sdType.Methods.Concat(sdType.Constructors).SingleOrDefault(m => m.Identifier == method.GetIdentifier());
                            if(sdMethod != null)
                            {
                                calledMethod = sdMethod;
                            }
                        }

                        // Only add method, if it is project stranger, public or private (if not only public members option on)
                        if (calledMethod != null)
                        {
                            var token = new SDTargetNode
                                            {
                                                    CalledType = calledType,
                                                    CallerType = callerType,
                                                    CalledMethod = calledMethod,
                                                    CallerMethod = callerMethod
                                            };

                            _tokenList.Add(token);
                        }
                    }
                }
            }
        }