NBuilder has two of the following fluent methods
.Has(..)
.Have(..)
eg.
return Builder<User>.CreateListOfSize(100)
.WhereTheFirst(1)
.Has(x => x.FirstName = "Jon Skeet")
.Build();
return Builder<User&g开发者_高级运维t;.CreateListOfSize(100)
.WhereTheFirst(1)
.Have(x => x.FirstName = "Jon Skeet")
.Build();
I don't understand the difference? Can someone please explain why I would do a Have instead of Has .. or vice versa?
They are identical. Full source code here.
Has:
[Obsolete(Messages.NewSyntax_UseWith)]
public static IOperable<T> Has<T, TFunc>(this IOperable<T> operable, Func<T, TFunc> func)
{
return With(operable, func);
}
Have:
[Obsolete(Messages.NewSyntax_UseWith)]
public static IOperable<T> Have<T, TFunc>(this IOperable<T> operable, Func<T, TFunc> func)
{
return With(operable, func);
}
The reason there was Has
and Have
was to provide a fluent syntax in two different uses.
For example, Has
makes sense in this case:
Builder<User>.CreateListOfSize(100)
.WhereTheFirst(1)
.Has(x => x.FirstName = "Jon Skeet")
.Build();
While, Have
makes sense in this case:
Builder<User>.CreateListOfSize(100)
.WhereAll()
.Have(x => x.FirstName = "Jon Skeet")
.Build();
Recently, however, it was recognized that the syntax needed to be cleaned up to prevent confusion due to differences in the syntax when creating lists vs single objects.
So now you can do the following:
Builder<User>.CreateListOfSize(100)
.All()
.With(x => x.FirstName = "Jon")
.TheFirst(1)
.With(x => x.LastName = "Skeet")
.Build();
...hopefully that should be less confusing going forward.
also, you'll notice in the answer given by ClosureCowboy that the Has
and Have
extensions had already been marked as Obsolete when he answered...
精彩评论