public void Then_a_specific_value_is_retrieved_by_a_number_of_pops(int[] valuesToPush, int numberOfPops, int expectedValueRetrievedByPop) { Theater theater = new Theater(); var promiseOfTheActualValue = new TaskCompletionSource<int>(); Address customer = null; Address stack = null; Given(() => { SetThe<IActorNamingService>().To(new InMemoryActorNamingService()); stack = theater.CreateActor(new StackNodeBehavior<int>(default(int), null)); foreach (var i in valuesToPush) { var push = new Push<int>(i); theater.Dispatch(push, stack); } customer = theater.CreateActor(new AssertionBehavior<int>(promiseOfTheActualValue, numberOfPops)); }); When(() => { for (var i = 0; i < numberOfPops; i++) { var pop = new Pop(customer); theater.Dispatch(pop, stack); } }); Then(async () => { var actualValue = await promiseOfTheActualValue.Task; actualValue.Should().Be(expectedValueRetrievedByPop); }); }
public void Then_factorial_of_x_is_calculated(int input, int expectedValue) { Theater theater = new Theater(); Address customer = null; var promiseOfTheActualValue = new TaskCompletionSource<CalculatedFactorial>(); Given(() => { customer = theater.CreateActor(new AssertionBehavior<CalculatedFactorial>(promiseOfTheActualValue, 1)); }); When(() => { var factorialCalculator = theater.CreateActor(new FactorialCalculationBehavior()); var calculateFactorialFor = new CalculateFactorialFor(input, customer); theater.Dispatch(calculateFactorialFor, factorialCalculator); }); Then(async () => { var calculatedFactorial = await promiseOfTheActualValue.Task; calculatedFactorial.Result.Should().Be(expectedValue); }); }