Skip to content

Use Partial Types To Define Expectations #342

@JasonBock

Description

@JasonBock

Is your feature request related to a problem? Please describe.
It may solve #335...

Describe the solution you'd like
It would look like this:

public interface IService 
{
  void DoStuff(string value);
}

[RockPartial(typeof(IService), BuildType.Create)]
public partial class ServiceExpectationStuff;

What Rocks would do is generate the mocking infrastructure code using ServiceExpectationStuff, something like this:

public partial class ServiceExpectationStuff
  : global::Rocks.Expectations
{
  internal sealed class Handler0
    : global::Rocks.Handler<global::System.Action<string>>
  {
    public global::Rocks.Argument<string> @value { get; set; }
  }

  // and so on...
}

This gives the developer the flexibility to define public expectation classes (which would address #341), and to use whatever name they want for the expectations class. Everything within would still be generated the same way Rocks does it now; the only difference is that top-level expectations class is defined and named by the user. In most cases, defining [RockAttribute] at the assembly level should always be the default way, but this provides some extra flexibility, and may also solve #335 as well.

Things that would need to change:

  • Add [RockPartialAttribute]:
    • It would have to be allowed to be defined on a type
    • Only one attribute per type.
    • Only one flag. It would look for Create, and then Make
  • If [RockPartialAttribute] would be defined on the type, that type:
    • Must be partial
    • Must not be static
    • Must be a class, not an interface or struct
    • If the target type to mock is generic, the partial class must define the same number of type parameters

The user should probably not define anything on the partial type to avoid any kind of member collision, but I don't think I should try to look for that either. Basically, "buyer beware" if the developer decides to do that.

Describe alternatives you've considered
Not doing this, but then I don't know of a way to solve #335 either :(.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions