2

I'm trying the next rule :

var result = new AutoFaker<MyModel>().RuleFor(x => x.AnotherModel, null).Generate();

public class MyModel
{
    public string Test { get; set; }
    public AnotherModel AnotherModel { get; set; }
}

public class AnotherModel
{
    public string Test1 { get; set; }
}

Got the message :

Severity    Code    Description Project File    Line    Suppression State
Error   CS0121  The call is ambiguous between the following methods or properties: 
'Faker<T>.RuleFor<TProperty>(Expression<Func<T, TProperty>>, Func<Faker, T, TProperty>)' 
and 'Faker<T>.RuleFor<TProperty>(Expression<Func<T, TProperty>>, TProperty)'    

Why can't I assign null to that model?

user7849697
  • 503
  • 1
  • 8
  • 19

1 Answers1

2

The following should work:

void Main()
{
   var result = new AutoFaker<MyModel>()
         .RuleFor(x => x.AnotherModel, _ => null);
         
   result.Generate().Dump();
}

public class MyModel
{
   public string Test { get; set; }
   public AnotherModel AnotherModel { get; set; }
}

public class AnotherModel
{
   public string Test1 { get; set; }
}

result

The reason there's an ambigrous call is because you need to be a bit more specific about what "rule for" method you want to use. eg:.RuleFor(expr, value) or .RuleFor(expr, Func<T>) etc...

Thanks, hope that helps,
Brian Chavez

Brian Chavez
  • 8,048
  • 5
  • 54
  • 47