Skip to content

Support scenarios #638

@vbreuss

Description

@vbreuss

Consider the following concept:

	[Fact]
	public async Task Scenario_Concept()
	{
		MyClass sut = MyClass.CreateMock([3,]);

		sut.Mock.Setup.MyMethod(It.IsAny<int>()).SwitchToScenario("foo").Returns(1);
		sut.Mock.SetupScenario("foo").MyMethod(It.IsAny<int>()).SwitchToScenario("bar").Returns(2);
		sut.Mock.SetupScenario("bar", setup => setup.MyMethod(It.IsAny<int>()).Returns(3).SwitchToScenario("").When(x => x > 3));

		List<int> results = [];
		for (int i = 0; i < 10; i++)
		{
			results.Add(sut.MyMethod(0));
		}

		await That(results).IsEqualTo([1,2,3,3,3,1,2,3,3,3,]);
	}

It would be nice for Mockolate to support scenarios:

  • Different Setups that only apply when the mock is in the current scenario (SetupScenario(string key, ...))
  • A way for callbacks (or explicitely) to change the scenario (SwitchToScenario(string key))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions