using System; using System.Collections; using Akua.Framework.Specifications.Mocking; using Akua.Framework.Specifications.Specs._ForTesting.Mocking; using Rhino.Mocks; using Rhino.Mocks.Constraints; using Concern = NUnit.Framework.TestFixtureAttribute; using Context = NUnit.Framework.TestFixtureAttribute; using Observation = NUnit.Framework.TestAttribute; using Specification = NUnit.Framework.TestAttribute; namespace Akua.Framework.Specifications.Specs.Mocking { [Concern] public class MethodChainMockerConcern { [Context] public class When_MethodChainMockerConcern_is_used_to_stub_out_a_MethodChain : ContextSpecification { private MethodChain _methodChain; private IList _withResultOfLastMethod; private IList _returnedResult; private string _param1; private SomeMethodParam _param2; private string _param3; private int _param4; private DateTime _param5; protected override void In_the_Given_Context() { _methodChain = stubbed(); _withResultOfLastMethod = new ArrayList(); _param1 = "vladan"; _param2 = new SomeMethodParam(); _param3 = "p"; _param4 = 1; _param5 = DateTime.Now; } [Specification] public void Then_it_should_be_possible_to_specify_result_and_verify_it_gets_returned() { using (Assuming_dependencies_do) { Mocks.CreateChainUsing(Mocks.DynamicMock, Expect.Call) .On(_methodChain, _withResultOfLastMethod, _chainedAs => _chainedAs.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .All()); } using (When_SUT_is_exercised_like) { _returnedResult = _methodChain.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .All(); } _returnedResult.should_be_Equal_to(_withResultOfLastMethod); } [Specification] public void Then_it_should_be_possible_to_specify_result_and_verify_it_gets_returned_2() { using (Assuming_dependencies_do) { Mocks.CreateChainUsing(Mocks.DynamicMock, Expect.Call) .On(_methodChain, _withResultOfLastMethod, _chainedAs => _chainedAs.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .All()); } using (When_SUT_is_exercised_like) { _returnedResult = _methodChain.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .All(); } _returnedResult.should_be_Equal_to(_withResultOfLastMethod); } [Specification] public void And_it_should_be_possible_to_specify_a_chain_without_an_explicit_result() { using (Assuming_dependencies_do) { Mocks.CreateChainUsing(Mocks.DynamicMock, Expect.Call) .On(_methodChain, _chainedAs => _chainedAs.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .Void()); } using (When_SUT_is_exercised_like) { _methodChain.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .Void(); } } [Specification] public void And_it_should_be_possible_to_specify_a_chain_with_constraints() { using (Assuming_dependencies_do) { Mocks.CreateChainUsing(Mocks.DynamicMock, Expect.Call) .ConstrainChainAt(0, Is.Equal("vladan")) .On(_methodChain, _chainedAs => _chainedAs.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .Void()); } using (When_SUT_is_exercised_like) { _methodChain.Level2(_param1) .Level121(_param2, _param3, _param4, _param5) .Void(); } } } } }