コード例 #1
0
 public static IfFilterExpression IfPropertyNameContains <TType>(
     this ConventionExpression conventionExpression,
     params string[] propertyNames)
 {
     return(conventionExpression.IfProperty(p =>
                                            p.PropertyType == typeof(TType) && propertyNames.Any(propertyName => p.Name.Contains(propertyName))));
 }
コード例 #2
0
        private static void Names(ConventionExpression cfg)
        {
            cfg.IfPropertyNameIs("Name").Use(faker => faker.Name.FullName());
            cfg.IfPropertyNameIs("FullName").Use(faker => faker.Name.FullName());

            cfg.IfPropertyNameIs("FirstName").Use(faker => faker.Name.FirstName());
            cfg.IfPropertyNameIs("LastName").Use(faker => faker.Name.LastName());
        }
コード例 #3
0
 public static IfFilterExpression IfPropertyIs <TType>(
     this ConventionExpression conventionExpression,
     Expression <Func <TType, object> > expression) where TType : class
 {
     return(conventionExpression.IfProperty(p =>
                                            p.DeclaringType == typeof(TType) &&
                                            p.Name == expression.ToAccessor().Name));
 }
コード例 #4
0
 public static IfFilterExpression IfPropertyImplements(
     this ConventionExpression conventionExpression,
     Type typeImplemented)
 {
     return(conventionExpression.IfProperty(p =>
                                            p.PropertyType.Implements(typeImplemented) ||
                                            p.PropertyType.ImplementsGenericOf(typeImplemented)));
 }
コード例 #5
0
        public static IfFilterExpression IfPropertyIs <TClass, TProperty>(
            this ConventionExpression conventionExpression,
            Expression <Func <TClass, TProperty> > property)
        {
            var accessor = property.ToAccessor();

            return(conventionExpression.IfProperty(p => p.DeclaringType == accessor.OwnerType &&
                                                   p.PropertyType == accessor.PropertyType));
        }
コード例 #6
0
        public static ConventionExpression AddEntityFramework(this ConventionExpression cfg)
        {
            cfg.IfProperty(p => p.Name.EndsWith("Id")).Ignore();

            cfg.IfProperty(p => p.PropertyType.Implements(typeof(Collection <>)) ||
                           p.PropertyType.ImplementsGenericOf(typeof(Collection <>))).Ignore();

            return(cfg);
        }
コード例 #7
0
        private static void Address(ConventionExpression cfg)
        {
            cfg.IfPropertyNameIs("Street").Use(faker => faker.Address.StreetAddress());

            cfg.IfPropertyNameIs("Complement").Use(faker => faker.Address.BuildingNumber());

            cfg.IfPropertyNameIs("State").Use(faker => faker.Address.State());

            cfg.IfPropertyNameIs("City").Use(faker => faker.Address.City());

            cfg.IfPropertyNameIs("PostalCode").Use(faker => faker.Address.ZipCode());
        }
コード例 #8
0
        public static ConventionExpression AddAutoFaker(this ConventionExpression cfg)
        {
            Names(cfg);
            Address(cfg);

            cfg.Use(f => f.Phone.PhoneNumber()).If(_ =>
            {
                _.IfPropertyNameIs("Phone");
                _.IfPropertyNameIs("PhoneNumber");
            });

            cfg.IfPropertyNameIs("Email").Use(faker => faker.Internet.Email());

            cfg.IfPropertyNameIs("CompanyName").Use(faker => faker.Company.CompanyName());

            return(cfg);
        }
コード例 #9
0
 public static IfFilterExpression IfPropertyNameIs(
     this ConventionExpression conventionExpression, string propertyName)
 {
     return(conventionExpression.IfProperty(p => p.Name == propertyName));
 }
コード例 #10
0
 public static IfFilterExpression IfClassImplements <TType>(this ConventionExpression conventionExpression)
 {
     return(conventionExpression.IfClass(t => t.Implements <TType>()));
 }
コード例 #11
0
 public static IfFilterExpression IfClassIs <TType>(this ConventionExpression conventionExpression)
 {
     return(conventionExpression.IfClass(t => t == typeof(TType)));
 }
コード例 #12
0
 public static IfFilterExpression IfPropertyImplementsEnumerableOf <TType>(
     this ConventionExpression conventionExpression)
 {
     return(conventionExpression.IfProperty(p => p.PropertyType.ImplementsEnumerableOf <TType>()));
 }
コード例 #13
0
 public static IfFilterExpression IfPropertyTypeIs <TType>(this ConventionExpression conventionExpression)
 {
     return(conventionExpression.IfProperty(p => p.PropertyType == typeof(TType)));
 }
コード例 #14
0
 public static IfFilterExpression IfPropertyNameEnds(
     this ConventionExpression conventionExpression, string propertyNameEnd)
 {
     return(conventionExpression.IfProperty(p => p.Name.EndsWith(propertyNameEnd)));
 }