Exemplo n.º 1
0
        public void Model_Usage()
        {
            var tree = ExcessMock.Compile(@"
            namespace SomeNS
            {
                model SomeModel
                {
                    int Property1;
                    string Property2 = ""SomeValue"";
                }
            }", builder: (compiler) => ModelExtension.Apply(compiler));

            Assert.IsNotNull(tree);

            //an struct should have been added
            var @class = tree
                         .GetRoot()
                         .DescendantNodes()
                         .OfType <ClassDeclarationSyntax>()
                         .Single();

            //with one constructor
            var constructor = @class
                              .DescendantNodes()
                              .OfType <ConstructorDeclarationSyntax>()
                              .Single();

            //must have 2 parameters and 2 assignments
            Assert.AreEqual(2, constructor.ParameterList.Parameters.Count);
            Assert.AreEqual(2, constructor
                            .DescendantNodes()
                            .OfType <AssignmentExpressionSyntax>()
                            .Count());

            //must have 2 properties with private sets
            Assert.AreEqual(2, @class
                            .DescendantNodes()
                            .OfType <PropertyDeclarationSyntax>()
                            .Where(property => property
                                   .AccessorList
                                   .Accessors
                                   .Any(accessor =>
                                        accessor.Keyword.IsKind(SyntaxKind.SetKeyword) &&
                                        accessor
                                        .Modifiers
                                        .Any(modifier => modifier.IsKind(SyntaxKind.PrivateKeyword))))
                            .Count());
        }
Exemplo n.º 2
0
        public void Model_WithMultiTokenType_ShouldSucceed()
        {
            var tree = ExcessMock.Compile(@"
                namespace SomeNamespace
                {
	                public model SomeModel 
	                {
                        IEnumerable<int> SomeGeneric;
		                Guid[] SomeArray;
	                }
                }", builder: (compiler) => ModelExtension.Apply(compiler));

            Assert.IsNotNull(tree);

            //must have transform both fields into properties
            Assert.AreEqual(2, tree
                            .GetRoot()
                            .DescendantNodes()
                            .OfType <PropertyDeclarationSyntax>()
                            .Count());
        }