Skip to content

Set access modifier for generated *Expectations #341

@Prodigio

Description

@Prodigio

Is your feature request related to a problem? Please describe.
I'm writing some unit tests with xUnit. To have them a bit more structured, I bundle method related unit tests in a sub class, within the main test class, like so:

[assembly: Rock(typeof(IBarManager), BuildType.Create)]

namspace ...

public class FooServiceTest
{
    public class FooTestBase
    {
        private readonly IBarManagerCreateExpectations _barManagerCreateExpectations;
        private readonly IFooService _fooService; // or sut (system under test)

        // Constructor
    }

    // GetItem is a method of IFooService
    public class GetItem : FooTestBase
    {
        [Fact]
        public void GetItem()
        {
            // test logic
            // Make use of _barManagerCreateExpectations here
        }
    }

    // GetDefinition is a method of IFooService
    public class GetDefinition : FooTestBase
    {
        [Fact]
        public void GetDefinition()
        {
            // test logic
            // Make use of _barManagerCreateExpectations here
        }
    }
}

Which does not work, because IBarManagerCreateExpectations is internal. Is there a reason, which I don't understand yet, that the generated classes are internal sealed, like seen below?

writer.WriteLines(
$$"""
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal sealed class {{mockType.ExpectationsName}}
: global::Rocks.Expectations
""");

Describe the solution you'd like
I'd like to have the option to set the access modifier for a class. For example when using the RockAttribute:

[assembly: Rock(typeof(IBarManager), BuildType.Create, Modifier.Public)]

Describe alternatives you've considered
I can move away from using sub classes, sure.

Additional context
none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions