Ejemplo n.º 1
0
 public void Create_WhenCreatingAutoPropertyWithModifer_ShouldHaveModifier()
 {
     Assert.AreEqual("publicstaticintMyProperty{get;set;}", PropertyGenerator.Create(new AutoProperty("MyProperty", typeof(int), PropertyTypes.GetAndSet, new List <Modifiers>()
     {
         Modifiers.Public, Modifiers.Static
     })).ToString());
 }
Ejemplo n.º 2
0
        public void Test_CreateModelClass()
        {
            var classBuilder = new ClassBuilder("Cat", "Models");
            var @class       = classBuilder
                               .WithUsings("System")
                               .WithConstructor(
                ConstructorGenerator.Create(
                    "Cat",
                    BodyGenerator.Create(
                        Statement.Declaration.Assign("Name", ReferenceGenerator.Create(new VariableReference("name"))),
                        Statement.Declaration.Assign("Age", ReferenceGenerator.Create(new VariableReference("age")))),
                    new List <Parameter> {
                new Parameter("name", typeof(string)), new Parameter("age", typeof(int))
            },
                    new List <Modifiers> {
                Modifiers.Public
            }))
                               .WithProperties(
                PropertyGenerator.Create(new AutoProperty("Name", typeof(string), PropertyTypes.GetAndSet, new List <Modifiers> {
                Modifiers.Public
            })),
                PropertyGenerator.Create(new AutoProperty("Age", typeof(int), PropertyTypes.GetAndSet, new List <Modifiers> {
                Modifiers.Public
            })))
                               .Build();

            Assert.AreEqual(
                "usingSystem;namespaceModels{publicclassCat{publicCat(stringname,intage){Name=name;Age=age;}publicstringName{get;set;}publicintAge{get;set;}}}",
                @class.ToString());
        }
Ejemplo n.º 3
0
 public void Create_WhenCreatingBodyPropertyWithModifier_ShouldHaveModifier()
 {
     Assert.AreEqual("publicvirtualintMyProperty{get{return1;}}", PropertyGenerator.Create(new BodyProperty(
                                                                                               "MyProperty",
                                                                                               typeof(int),
                                                                                               BodyGenerator.Create(Statement.Jump.Return(new ConstantReference(1))),
                                                                                               new List <Modifiers> {
         Modifiers.Public, Modifiers.Virtual
     })).ToString());
 }
Ejemplo n.º 4
0
 public void Create_WhenCreatingBodyPropertyWithAttribute_ShouldHaveAttribute()
 {
     Assert.AreEqual("[Test]intMyProperty{get{return1;}}", PropertyGenerator.Create(new BodyProperty(
                                                                                        "MyProperty",
                                                                                        typeof(int),
                                                                                        BodyGenerator.Create(Statement.Jump.Return(new ConstantReference(1))),
                                                                                        attributes: new List <Attribute> {
         new Attribute("Test")
     })).ToString());
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Set class properties.
        /// </summary>
        /// <param name="properties">A set of wanted properties.</param>
        /// <returns>The current class builder</returns>
        public ClassBuilder WithProperties(params Property[] properties)
        {
            _properties.Clear();
            foreach (var property in properties)
            {
                _properties.Add(PropertyGenerator.Create(property));
            }

            return(this);
        }
Ejemplo n.º 6
0
        public void Test_CreateModelClassWithBodyProperties()
        {
            var classBuilder = new ClassBuilder("Cat", "Models");
            var @class       = classBuilder
                               .WithUsings("System")
                               .WithFields(
                new Field("_name", typeof(string), new List <Modifiers>()
            {
                Modifiers.Private
            }),
                new Field("_age", typeof(int), new List <Modifiers>()
            {
                Modifiers.Private
            }))
                               .WithConstructor(
                ConstructorGenerator.Create(
                    "Cat",
                    BodyGenerator.Create(
                        Statement.Declaration.Assign("Name", ReferenceGenerator.Create(new VariableReference("name"))),
                        Statement.Declaration.Assign("Age", ReferenceGenerator.Create(new VariableReference("age")))),
                    new List <Parameter> {
                new Parameter("name", typeof(string)), new Parameter("age", typeof(int))
            },
                    new List <Modifiers> {
                Modifiers.Public
            }))
                               .WithProperties(
                PropertyGenerator.Create(
                    new BodyProperty(
                        "Name",
                        typeof(string),
                        BodyGenerator.Create(Statement.Jump.Return(new VariableReference("_name"))), BodyGenerator.Create(Statement.Declaration.Assign("_name", new ValueKeywordReference())),
                        new List <Modifiers> {
                Modifiers.Public
            })),
                PropertyGenerator.Create(
                    new BodyProperty(
                        "Age",
                        typeof(int),
                        BodyGenerator.Create(Statement.Jump.Return(new VariableReference("_age"))), BodyGenerator.Create(Statement.Declaration.Assign("_age", new ValueKeywordReference())),
                        new List <Modifiers> {
                Modifiers.Public
            })))
                               .Build();

            Assert.AreEqual(
                "usingSystem;namespaceModels{publicclassCat{privatestring_name;privateint_age;publicCat(stringname,intage){Name=name;Age=age;}publicstringName{get{return_name;}set{_name=value;}}publicintAge{get{return_age;}set{_age=value;}}}}",
                @class.ToString());
        }
Ejemplo n.º 7
0
        public void Test_CreateClassWithRegion()
        {
            var classBuilder = new ClassBuilder("Cat", "Models");
            var @class       = classBuilder
                               .WithUsings("System")
                               .WithRegions(new RegionBuilder("MyRegion")
                                            .WithProperties(PropertyGenerator.Create(new AutoProperty("Name", typeof(string), PropertyTypes.GetAndSet, new List <Modifiers> {
                Modifiers.Public
            })))
                                            .Build())
                               .Build();

            Assert.AreEqual(
                "usingSystem;namespaceModels{publicclassCat{#region MyRegion \npublicstringName{get;set;}#endregion}}",
                @class.ToString());
        }
Ejemplo n.º 8
0
        public void Test_CreateClassWithRegionWithMultipleMembers()
        {
            var classBuilder = new ClassBuilder("Cat", "Models");
            var @class       = classBuilder
                               .WithUsings("System")
                               .WithRegions(new RegionBuilder("MyRegion")
                                            .WithFields(
                                                new Field("_name", typeof(string), new List <Modifiers>()
            {
                Modifiers.Private
            }),
                                                new Field("_age", typeof(int), new List <Modifiers>()
            {
                Modifiers.Private
            }))
                                            .WithProperties(PropertyGenerator.Create(new AutoProperty("Name", typeof(string), PropertyTypes.GetAndSet, new List <Modifiers> {
                Modifiers.Public
            })))
                                            .WithConstructor(
                                                ConstructorGenerator.Create(
                                                    "Cat",
                                                    BodyGenerator.Create(
                                                        Statement.Declaration.Assign("Name", ReferenceGenerator.Create(new VariableReference("name"))),
                                                        Statement.Declaration.Assign("Age", ReferenceGenerator.Create(new VariableReference("age")))),
                                                    new List <Parameter> {
                new Parameter("name", typeof(string)), new Parameter("age", typeof(int))
            },
                                                    new List <Modifiers> {
                Modifiers.Public
            }))
                                            .Build())
                               .Build();

            Assert.AreEqual(
                "usingSystem;namespaceModels{publicclassCat{#region MyRegion \nprivatestring_name;privateint_age;publicstringName{get;set;}publicCat(stringname,intage){Name=name;Age=age;}#endregion}}",
                @class.ToString());
        }
Ejemplo n.º 9
0
 public void Create_WhenCreatingBodyPropertyWithGetAndSet_ShouldHaveBothGetAndSet()
 {
     Assert.AreEqual("intMyProperty{get{return1;}}", PropertyGenerator.Create(new BodyProperty("MyProperty", typeof(int), BodyGenerator.Create(Statement.Jump.Return(new ConstantReference(1))))).ToString());
 }
Ejemplo n.º 10
0
 public void Create_WhenCreatingAutoPropertyWithAttribute_ShouldHaveAttribute()
 {
     Assert.AreEqual("[Test]intMyProperty{get;set;}", PropertyGenerator.Create(new AutoProperty("MyProperty", typeof(int), PropertyTypes.GetAndSet, new List <Modifiers>(), new List <Attribute> {
         new Attribute("Test")
     })).ToString());
 }
Ejemplo n.º 11
0
 public void Create_WhenCreatingPropertyWithSetModifiers_ShouldHaveGetModifiers()
 {
     Assert.AreEqual("intMyProperty{get;privateinternalset;}", PropertyGenerator.Create(new AutoProperty("MyProperty", typeof(int), PropertyTypes.GetAndSet, setModifiers: new List <Modifiers> {
         Modifiers.Private, Modifiers.Internal
     })).ToString());
 }
Ejemplo n.º 12
0
 public void Create_WhenCreatingPropertyWithGetModifiers_ShouldHaveGetModifiers()
 {
     Assert.AreEqual("intMyProperty{protectedget;set;}", PropertyGenerator.Create(new AutoProperty("MyProperty", typeof(int), PropertyTypes.GetAndSet, getModifiers: new List <Modifiers> {
         Modifiers.Protected
     })).ToString());
 }
Ejemplo n.º 13
0
 public void Create_WhenCreatingAutoPropertyWithGetAndSet_ShouldHaveBothGetAndSet()
 {
     Assert.AreEqual("intMyProperty{get;set;}", PropertyGenerator.Create(new AutoProperty("MyProperty", typeof(int), PropertyTypes.GetAndSet)).ToString());
 }