Skip to content

Improve Verify() Performance #292

@JasonBock

Description

@JasonBock

Describe the solution you'd like
I noticed that the verification test for BenchmarkMockNet got a little worse from 7.3.0 to 8.0.0-alpha.1. I think I can improve it. Right now, it generates this:

public override void Verify()
{
  if (this.WasInstanceInvoked)
  {
    var failures = new global::System.Collections.Generic.List<string>();

    failures.AddRange(this.Verify(handlers0));
    failures.AddRange(this.Verify(handlers1));

    if (failures.Count > 0)
    {
      throw new global::Rocks.Exceptions.VerificationException(failures);
    }
  }
}

I think if I change it so I only do Verify() on the handler list if it has members that will make things better, like this:

public override void Verify()
{
  if (this.WasInstanceInvoked)
  {
    var failures = new global::System.Collections.Generic.List<string>();

    if (this.handlers0.Count > 0) { failures.AddRange(this.Verify(this.handlers0)); }
    if (this.handlers1.Count > 0) { failures.AddRange(this.Verify(this.handlers1)); }

    if (failures.Count > 0)
    {
      throw new global::Rocks.Exceptions.VerificationException(failures);
    }
  }
}

Note that I should reference the handler lists with this. because reasons :).

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions