public static void CanCallAttributeWithName()
        {
            var name   = "TestValue905136492";
            var result = Generate.Attribute(name);

            Assert.That(result.NormalizeWhitespace().ToFullString(), Is.EqualTo("TestValue905136492"));
        }
        public ClassDeclarationSyntax Create(ClassModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var classDeclaration = SyntaxFactory.ClassDeclaration(_frameworkSet.GetTargetTypeName(model, true));

            model.TargetInstance = model.TypeSyntax;

            classDeclaration = classDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            if (_frameworkSet.TestFramework.SupportsStaticTestClasses)
            {
                classDeclaration = classDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
            }

            if (!string.IsNullOrWhiteSpace(_frameworkSet.TestFramework.TestClassAttribute))
            {
                var testFixtureAtt = Generate.Attribute(_frameworkSet.TestFramework.TestClassAttribute);
                var list           = SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(testFixtureAtt));
                classDeclaration = classDeclaration.AddAttributeLists(list);
            }

            return(classDeclaration);
        }
        public static void CanCallAttributeWithStringAndArrayOfExpressionSyntax()
        {
            var name      = "TestValue1946645090";
            var arguments = new[] { Generate.Literal(1), Generate.Literal(1), Generate.Literal(1) };
            var result    = Generate.Attribute(name, arguments);

            Assert.That(result.NormalizeWhitespace().ToFullString(), Is.EqualTo("TestValue1946645090(1, 1, 1)"));
        }
        public static void CanCallAttributeWithStringAndArrayOfObject()
        {
            var name      = "TestValue220626612";
            var arguments = new object[] { 1, 4, 2 };
            var result    = Generate.Attribute(name, arguments);

            Assert.That(result.NormalizeWhitespace().ToFullString(), Is.EqualTo("TestValue220626612(1, 4, 2)"));
        }
Esempio n. 5
0
        public BaseMethodDeclarationSyntax CreateSetupMethod(string targetTypeName)
        {
            if (string.IsNullOrWhiteSpace(targetTypeName))
            {
                throw new ArgumentNullException(nameof(targetTypeName));
            }

            var method = Generate.Method("SetUp", false, false);

            return(method.AddAttributeLists(
                       SyntaxFactory.AttributeList(
                           SyntaxFactory.SingletonSeparatedList(Generate.Attribute("TestInitialize")))));
        }
        public ClassDeclarationSyntax Create(ClassModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var targetTypeName   = _frameworkSet.GetTargetTypeName(model, true);
            var classDeclaration = SyntaxFactory.ClassDeclaration(targetTypeName);

            classDeclaration = classDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            if (!string.IsNullOrWhiteSpace(_frameworkSet.TestFramework.TestClassAttribute))
            {
                var testFixtureAtt = Generate.Attribute(_frameworkSet.TestFramework.TestClassAttribute);
                var list           = SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(testFixtureAtt));
                classDeclaration = classDeclaration.AddAttributeLists(list);
            }

            classDeclaration = classDeclaration.AddMembers(GenerateConcreteInheritor(model));

            var variableDeclaration = SyntaxFactory.VariableDeclaration(SyntaxFactory.ParseTypeName("Test" + model.ClassName))
                                      .AddVariables(SyntaxFactory.VariableDeclarator("_testClass"));

            var fieldDeclaration = SyntaxFactory.FieldDeclaration(variableDeclaration)
                                   .AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword));

            classDeclaration = classDeclaration.AddMembers(fieldDeclaration);

            var setupMethod = Generate.SetupMethod(model, targetTypeName, _frameworkSet, ref classDeclaration);

            var identifierNameSyntax = SyntaxFactory.IdentifierName("Test" + model.ClassName);

            model.TypeSyntax = identifierNameSyntax;

            var creationExpression = model.GetObjectCreationExpression(_frameworkSet);

            var assignment = SyntaxFactory.AssignmentExpression(
                SyntaxKind.SimpleAssignmentExpression,
                model.TargetInstance,
                creationExpression);

            setupMethod = setupMethod.AddBodyStatements(SyntaxFactory.ExpressionStatement(assignment));

            classDeclaration = classDeclaration.AddMembers(setupMethod);

            return(classDeclaration);
        }
 public static void CannotCallAttributeWithStringAndArrayOfExpressionSyntaxWithInvalidName(string value)
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute(value, Generate.Literal(1), Generate.Literal(1), Generate.Literal(1)));
 }
 public static void CannotCallAttributeWithStringAndArrayOfExpressionSyntaxWithNullArguments()
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute("TestValue638342250", default(ExpressionSyntax[])));
 }
 public static void CannotCallAttributeWithStringAndArrayOfExpressionSyntaxWithNullName()
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute(default(string), Generate.Literal(1), Generate.Literal(1), Generate.Literal(1)));
 }
Esempio n. 10
0
 public static void CannotCallAttributeWithStringAndArrayOfObjectWithInvalidName(string value)
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute(value, new object(), new object(), new object()));
 }
Esempio n. 11
0
 public static void CannotCallAttributeWithStringAndArrayOfObjectWithNullArguments()
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute("TestValue565899197", default(object[])));
 }
Esempio n. 12
0
 public static void CannotCallAttributeWithStringAndArrayOfObjectWithNullName()
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute(default(string), new object(), new object(), new object()));
 }
Esempio n. 13
0
 public static void CannotCallAttributeWithNameWithInvalidName(string value)
 {
     Assert.Throws <ArgumentNullException>(() => Generate.Attribute(value));
 }
Esempio n. 14
0
        public MethodDeclarationSyntax CreateTestMethod(string name, bool isAsync, bool isStatic)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var method = Generate.Method(name, isAsync, false);

            return(method.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(Generate.Attribute("TestMethod")))));
        }
Esempio n. 15
0
        public MethodDeclarationSyntax CreateTestCaseMethod(string name, bool isAsync, bool isStatic, TypeSyntax valueType, IEnumerable <object> testValues)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (valueType == null)
            {
                throw new ArgumentNullException(nameof(valueType));
            }

            if (testValues == null)
            {
                throw new ArgumentNullException(nameof(testValues));
            }

            var method = Generate.Method(name, isAsync, false);

            method = method.AddParameterListParameters(SyntaxFactory.Parameter(SyntaxFactory.Identifier(Strings.MsTestTestFramework_CreateTestCaseMethod_value)).WithType(valueType));
            method = method.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(Generate.Attribute("DataTestMethod"))));

            foreach (var testValue in testValues)
            {
                method = method.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(Generate.Attribute("DataRow", testValue))));
            }

            return(method);
        }