Skip to content

Support ref structs on mock Setup parameter #979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pipe01 opened this issue Mar 25, 2020 · 1 comment
Closed

Support ref structs on mock Setup parameter #979

pipe01 opened this issue Mar 25, 2020 · 1 comment

Comments

@pipe01
Copy link

pipe01 commented Mar 25, 2020

I'm trying to mock a method that takes in a ref struct as a parameter, however I cannot use any of the It or Match methods as they all require generic arguments. Is there any way I could create my own specific matcher from scratch for only my ref struct type?

@stakx
Copy link
Contributor

stakx commented Mar 25, 2020

Duplicate of #829.

ref structs are types that live exclusively on the evaluation stack. Our using DynamicProxy (to intercept calls) means that mock method arguments all get boxed to type object (basically to be put in the IInvocation.Arguments array)... which doesn't work for stack-only types. So basically, Moq v4 cannot support ref struct parameters.

Note that by-ref parameters (i.e. pass-by-reference) of all other types is supported via It.Ref<T>.IsAny.

@stakx stakx closed this as completed Mar 25, 2020
dougbu added a commit to aspnet/AspNetWebStack that referenced this issue Feb 13, 2023
- expand our text matrix to include a modern (and LTS) TFM
- change how Formatting test assemblies are found
  - `netcoreapp` is no longer the only relevant folder prefix
- use the latest .NET 6 SDK
  - install the 2.1.x runtime in the pipeline
- don't require .NET in VS
  - will use binplaced `msbuild` instead
  - have `git` ignore the new .msbuild/ folder
- react to new `Exception.Message`s in `netcoreapp3.1`
  - handle different formatting of argument info in `ArgumentException.Message`s
  - handle slightly greater `decimal` precision in a `JsonReaderException.Message`
- react to new `Exception.Message`s and other changes in `net6.0`
  - handle different `Message` in `InvalidOperationException`s about invalid request URIs
- react to other changes in `net6.0`
  - handle inability to mock a `Stream` if a writer passes a `ReadOnlySpan<byte>` in `net6.0`
    - see devlooped/moq#829, devlooped/moq#979, and dotnet/runtime#45152 about the issue
  - skip tests failing due to `HttpResponseMessage` changes
    - see #386 and dotnet/runtime@b48900f (which introduced this)
    - fix coming **Real Soon Now:tm:** :grin:
- nits:
  - simplify define use now that `NETCOREAPP3_1_OR_GREATER` and so on are available
  - clean up .gitignore
  - clean up a few comments and tighten scripting up
@devlooped devlooped locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants