Skip to content

Change Default Parameters to Have Optional Value in Expectation Extension Method #264

@JasonBock

Description

@JasonBock

Right now, if I have an interface defined like this:

public interface IHaveOptionalArguments
{
  void Foo(int a, string b = "b", double c = 3.2);
}

The gen'd expectation method looks like this:

internal static global::Rocks.MethodAdornments<global::Rocks.IntegrationTests.IHaveOptionalArguments, global::System.Action<int, string, double>> Foo(
  this global::Rocks.Expectations.MethodExpectations<global::Rocks.IntegrationTests.IHaveOptionalArguments> @self,
  global::Rocks.Argument<int> @a, 
  global::Rocks.Argument<string> @b, 
  global::Rocks.Argument<double> @c)

I think I can do this:

internal static global::Rocks.MethodAdornments<global::Rocks.IntegrationTests.IHaveOptionalArguments, global::System.Action<int, string, double>> Foo(
  this global::Rocks.Expectations.MethodExpectations<global::Rocks.IntegrationTests.IHaveOptionalArguments> @self,
  global::Rocks.Argument<int> @a, 
  global::Rocks.Argument<string> @b = "b", 
  global::Rocks.Argument<double> @c = 3.2)

In other words, put the optional argument in the call site. Then, instead of having to set the expectation like this:

expectations.Methods().Foo(1, Arg.IsDefault<string>(), Arg.IsDefault<double>());

It'll be a little shorter:

expectations.Methods().Foo(1);

Developers can still choose to use Arg.IsDefault() if they want, or specify their own value.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions