Пример #1
0
        public void Exception(string name, MethodDefinitionFactory factory)
        {
            var methodSyntax =
                SyntaxFactory.MethodDeclaration(
                    SyntaxFactory.ArrayType(SyntaxFactory.GenericName(CreateSyntaxIdentifierToken(name))), name);

            Assert.Throws <NotImplementedException>(() => factory.CreateMethodFromSyntax(methodSyntax));
        }
Пример #2
0
        public void CorrectInput(string name, string[] parameters, string[] attributes,
                                 [Frozen] Mock <IParameterDefinitionFactory> parameterFactoryMock,
                                 [Frozen] Mock <IAttributeDefinitionFactory> attributeFactoryMock, MethodDefinitionFactory factory)
        {
            Expression <Func <IParameterDefinitionFactory, ParameterDefinition> > parameterExpression =
                f => f.CreateParameterFromSyntax(It.IsAny <ParameterSyntax>());

            parameterFactoryMock.Setup(parameterExpression).Returns(() => null).Verifiable();

            Expression <Func <IAttributeDefinitionFactory, AttributeDefinition> > attributeExpression =
                f => f.CreateAttributeFromSyntax(It.IsAny <AttributeSyntax>());

            attributeFactoryMock.Setup(attributeExpression).Returns(() => null).Verifiable();


            var x = CreateMethod(name, parameters, attributes);


            var result = factory.CreateMethodFromSyntax(x);

            Assert.NotNull(result);
            Assert.Equal(name, result.Name);

            Assert.Equal(parameters.Length, result.Parameters.Length);
            parameterFactoryMock.Verify(parameterExpression, Times.Exactly(parameters.Length));

            Assert.Equal(attributes.Length, result.Attributes.Length);
            attributeFactoryMock.Verify(attributeExpression, Times.Exactly(attributes.Length));
        }