public void AllAttributesPropertyDeclaration_test()
        {
            // Arrange
            var setting = new PocoSetting
            {
                AddKeyAttribute      = true,
                AddRequiredAttribute = true,
                AddJsonAttribute     = true
            };

            _attributeManager.Init(setting);

            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };

            // Act
            var sut = new PropertyGenerator(property, setting);


            // Assert
            Assert.IsTrue(sut.ToString().Contains("[Key]") &&
                          sut.ToString().Contains("[Required]") &&
                          sut.ToString().Contains("[JsonProperty(PropertyName = \"CategoryID\")]"));
        }
        public void JsonAttributeWithCamelCasePropertyDeclaration_test()
        {
            // Arrange
            var setting = new PocoSetting
            {
                AddJsonAttribute = true,
                NameCase         = CaseEnum.Camel
            };

            _attributeManager.Init(setting);

            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            // Act
            var sut = new PropertyGenerator(property, setting);
            // Assert
            var expected =
                $"[JsonProperty(PropertyName = \"CategoryID\")] {Constant.NewLine}public int categoryID {{get;set;}} ";


            Assert.AreEqual(sut.ToString().TrimAllSpace(), expected.TrimAllSpace());
        }
        public void RequiredAttributePropertyDeclaration_test()
        {
            // Arrange
            var setting = new PocoSetting
            {
                AddRequiredAttribute = true
            };

            _attributeManager.Init(setting);

            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            // Act
            var sut = new PropertyGenerator(property, setting);
            // Assert

            var expected = @"
[Required]
public int CategoryID {get;set;} ";

            Assert.AreEqual(sut.ToString().TrimAllSpace(), expected.TrimAllSpace());
        }
        public void test1(string att, string expected)
        {
            // Arrange
            var setting = new PocoSetting
            {
                Attributes = new List <string> {
                    att
                }
            };

            _attributeManager.Init(setting);

            var property = new PropertyTemplate
            {
                PropName = "ProductId",
                PropType = "string",
                Serial   = 1,
                IsKey    = true,
            };
            // Act
            var sut = new PropertyGenerator(property, setting);

            // Assert
            Assert.IsTrue(sut.ToString().Contains(expected));
        }
示例#5
0
        public void AllAttributesPropertyDeclaration()
        {
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                AddKeyAttribute      = true,
                AddRequiredAttribute = true,
                AddJsonAttribute     = true
            });

            //Debug.WriteLine(pg);

            Assert.IsTrue(pg.ToString().Contains("[Key]") &&
                          pg.ToString().Contains("[Required]") &&
                          pg.ToString().Contains("[JsonProperty(PropertyName = \"CategoryID\")]"));
        }
示例#6
0
        public void JsonAttributePropertyDeclaration()
        {
            //public int CategoryID {get;set;} //PrimaryKey not null
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                AddJsonAttribute = true
            });
            //  Debug.WriteLine(pg);
            var expected = "[JsonProperty(PropertyName = \"CategoryID\")]";

            Assert.IsTrue(pg.ToString().Contains(expected));
        }
示例#7
0
        public void KeyAttributePropertyDeclaration()
        {
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                AddKeyAttribute = true
            });
            //  Debug.WriteLine(pg);
            var expected = @"
[Key]
public int CategoryID {get;set;} ";

            //Assert.IsTrue(CompareStringIgnoringSpaceCr(pg.ToString(), expected));
            Assert.AreEqual(pg.ToString().TrimAllSpace(), expected.TrimAllSpace());
        }
示例#8
0
        public void JsonAttributeWithCamelCasePropertyDeclaration()
        {
            //public int CategoryID {get;set;} //PrimaryKey not null
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                AddJsonAttribute = true,
                NameCase         = CaseEnum.Camel
            });
            //  Debug.WriteLine(pg);
            var expected = "[JsonProperty(PropertyName = \"CategoryID\")] " + Environment.NewLine +
                           "public int categoryID {get;set;} ";

            //   Debug.WriteLine("Expected: " + expected);
            //Assert.IsTrue(Helper.CompareStringIgnoringSpaceCr(pg.ToString(), expected));
            Assert.AreEqual(pg.ToString().TrimAllSpace(), expected.TrimAllSpace());
        }
        public void JsonAttributePropertyDeclaration_test()
        {
            // Arrange
            var setting = new PocoSetting
            {
                AddJsonAttribute = true
            };

            _attributeManager.Init(setting);
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            // Act
            var sut = new PropertyGenerator(property, setting);

            // Assert
            var expected = "[JsonProperty(PropertyName = \"CategoryID\")]";

            Assert.IsTrue(sut.ToString().Contains(expected));
        }
示例#10
0
 /// <summary>
 /// Add a new property generator to this emitter
 /// </summary>
 /// <remarks>
 /// Generator can be added only once
 /// </remarks>
 /// <param name="generator">The PropertyGenerator to be added</param>
 public void AddPropertyGenerator(PropertyGenerator generator)
 {
     Debug.Assert(!generators.Contains(generator),
                  "Tried adding " + generator.ToString() + " twice");
     generators.Add(generator);
 }