Skip to content

Mocks With Generic Methods and Events Cannot Be Mocked #295

@JasonBock

Description

@JasonBock

To Reproduce

Run this in a test:

var code =
	"""
	using Rocks;
	using System;

	[assembly: RockCreate<IGenericsAndEvent>]
	
	public interface IGenericsAndEvent
	{
		int Work<T>(T value);
		int ConstrainedWork<T>(T value) where T : class, new();
		event EventHandler MyEvent;
	}
	""";

Expected behavior
A mock is created:

Actual behavior
Errors occur like this:

error CS0246: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

Additional context
The issue is that the event extensions do not define the generics on the methods, which causes the issue. Probably also need to bring along the constraints on those methods as well.

This was found on a number of types, Blazored.LocalStorage.ILocalStorageService being one of them. This is related to the recent code generation changes in 8.0.0.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions