Giter Site home page Giter Site logo

Comments (5)

blairconrad avatar blairconrad commented on June 15, 2024

Hi, @drauch. I may be missing a subtlety. Can you show some code? Ideally what you have to do now to workaround the lack, and an envisioned improvement? Because as I read your description upstairs, I'm not sure how what you're asking for is different than Specifying different behaviors for successive calls:

public interface IDoSomething
{
    int DoSomething(int input);
}

public void Test1()
{
    var fake = A.Fake<IDoSomething>();
    A.CallTo(() => fake.DoSomething(A<int>._))
        .ReturnsLazily((int i) => i * 2).Once()
        .Then
        .ReturnsLazily((int i) => i * 2).Once();

    var doubleOne = fake.DoSomething(1);
    var doubleThree = fake.DoSomething(3);

    doubleOne.Should().Be(2);
    doubleThree.Should().Be(6);
}

from fakeiteasy.

drauch avatar drauch commented on June 15, 2024

I need it in two different locations:

void Arrange1 ()
{
    A.CallTo(() => fake.Foo()).Returns(1).Once();
}

void Arrange2 ()
{
    A.CallTo(() => fake.Foo()).Then.Returns(2).Once();
}

Best regards,
D.R.

from fakeiteasy.

blairconrad avatar blairconrad commented on June 15, 2024

This seems kind of niche, to be honest. It looks like you have access to fake from some shared location (perhaps it's an instance variable). Have you considered retaining the result of A.CallTo(() => fake.Foo()).Returns(1).Once()?

private IDoSomething? fake;
private IThenConfiguration<IReturnValueConfiguration<int>>? ongoingFakeConfiguration;

public interface IDoSomething
{
    int Foo();
}

void Arrange1()
{
    ongoingFakeConfiguration = A.CallTo(() => fake!.Foo()).Returns(1).Once();
}

void Arrange2()
{
    ongoingFakeConfiguration = ongoingFakeConfiguration!.Then.Returns(2).Once();
}

[Fact]
public void Test1()
{
    fake = A.Fake<IDoSomething>();

    Arrange1();
    Arrange2();

    var result1 = fake.Foo();
    var result2 = fake.Foo();

    result1.Should().Be(1);
    result2.Should().Be(2);
}

It doesn't seem any worse to me than the existing temporal coupling.

from fakeiteasy.

drauch avatar drauch commented on June 15, 2024

Okay, that's also a workaround I guess.

from fakeiteasy.

blairconrad avatar blairconrad commented on June 15, 2024

This may be a disappointment, but we've decided not to implement this change. While it may be useful for some, there are abundant alternate flows.

from fakeiteasy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.