Skip to content

NSubstitute future improvements #551

@zvirja

Description

@zvirja

Let's collect improvements we could/should make in our next major versions and are not allowed to apply now because of SemVer. Issue might be updated.

  • Make RouteAction a read-only struct to optimize performance

  • Return array instead of IList, so we can optimize contract

    IList<IArgumentSpecification> DequeueAllArgumentSpecifications();

  • Refactor ICall and replace Get methods with properties

    public interface ICall
    {
    Type GetReturnType();
    MethodInfo GetMethodInfo();
    object[] GetArguments();
    object[] GetOriginalArguments();
    object Target();
    IParameterInfo[] GetParameterInfos();
    IList<IArgumentSpecification> GetArgumentSpecifications();
    void AssignSequenceNumber(long number);
    long GetSequenceNumber();
    bool CanCallBase { get; }

  • Make NSubstitute.Core.Argument a read-only struct, as it's a thin wrapper on top of ICall and index.

  • Rework IAutoValueProvider interface to:

    • Have only bool TryCreateValue(Type type, out object result) method
    • Avoid cyclic dependency from provider to list of all providers
    • Expose single aggregate provider from factory rather than an array of providers.
  • Make the ReflectionExtensions helper internal and remove OrNull suffix as we use nullability for that.

  • Normalize Extension-like classes, as at the moment we have a plenty of them and it's a bit hard to navigate through them.

  • Add class constraint to all the DSL extension methods receiving substitute. Example: ReceivedExtensions.Received()

  • Review IPendingSpecification interface and potentially change it to Try pattern.

  • Convert to a record once we drop .NET Standard 1.3 support:

    • ArgumentMatchInfo
    • Quantity descendants
  • Do not expose internal classes from Core namespace, but instead expose interfaces.

  • Make SubsitutionContext constructor private, so it can be instantiated via container only.

  • Change return type of ArgumentMatchInfo.DescribeNonMatch to return null if cannot describe instead of an empty string.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions