I got it to work with the much simpler test shown below which uses a
read write bool property. I can't get it to work yet for a ready only
bool property which is the problem that I have to solve in my
production code from my original post. Please advise on how to get
this to work.

--------------------------------------------
Working simplified test that uses a ready write property
---------------------------------------------

      [Test]
      public void Test()
      {
         ITest mockTest;
         using (_mockRepository.Record())
         {
            mockTest = _mockRepository.DynamicMock<ITest>();
            Expect.Call(mockTest.Test).IgnoreArguments()
               .Do(new
BoolPropertyDelegate(GetSourceGroupEnabled)).Repeat.Any();
         }

         using (_mockRepository.Playback())
         {
            bool res = mockTest.Test;
            _sourceGroupEnabled = true;
            res = mockTest.Test;
         }
      }

   public interface ITest
   {
      bool Test { get; set;}
   }



On Oct 9, 8:27 am, Ryan Vice <[EMAIL PROTECTED]> wrote:
> I'm trying to have a mocked boolean property return different values
> at different times during my test and I was told in this thread:
>
> http://groups.google.com/group/RhinoMocks/browse_thread/thread/9367c1...
>
> to use the Do() function to achieve this. I reviewed the documentation
> and I can't get it to work. I've put my code below.
>
> -----------------------------------------------------------------
> Code
> -----------------------------------------------------------------
>
>    #region UnableToShoot
>
>    /// <summary>
>    /// Class for testing DynamiteShooterStateMachine UnableToShoot
> transitions
>    /// </summary>
>    [TestFixture]
>    public class UnableToShoot : DynamiteShooterStateMachineTestsBase
>    {
>       bool _sourceGroupEnabled;
>       delegate bool BoolPropertyDelegate();
>
>       [Test]
>       public void
> SourceGroupEnabledWithDecoder_ShooterEnabled_UnableToShoot()
>       {
>          _sourceGroupEnabled = false;
>
>          using (_mockRepository.Record())
>          {
>             _sourceGroup =
> _mockRepository.DynamicMock<ISourceGroup>();
>             _sourcePoint = null;  // Type is ISourcePoint
>             _dynamiteShooterSm =
>
> _mockRepository.PartialMock<DynamiteShooterStateMachineTestHarness>
>                                  (_sourceGroup, _sourcePoint);  //
> This creates a mock DynamiteShooterStateMachine that returns the
> source group mock
>
> SetupResult.For(_sourceGroup.Name).Return("TestingGroup");
>             Expect.Call(_sourceGroup.Enabled).IgnoreArguments()
>                .Do(new
> BoolPropertyDelegate(GetSourceGroupEnabled));  //
> _sourceGroup.Enabled
> is a bool property
>             SetupResult.For(_sourceGroup.EnabledWithDecoders)
>                .Return(false);
>          }
>
>          using (_mockRepository.Playback())
>          {
>             _dynamiteShooterSm.Init();
>
> AssertThatCurrentStateIs(_dynamiteShooterSm.qUnableToShoot);
>             _sourceGroupEnabled = true;
>             DynamiteShooterStateMachineEvent shooterEnabled
>                = new DynamiteShooterStateMachineEvent
>                (DynamiteShooterStateMachineSignal.ShooterEnabled,
> _sourceGroup);
>             _dynamiteShooterSm.Dispatch(shooterEnabled);
>
> AssertThatCurrentStateIs(_dynamiteShooterSm.qAbleToShoot);
>          }
>       }
>
>       protected bool GetSourceGroupEnabled()
>       {
>          return _sourceGroupEnabled;
>       }
>
>    }
>
> -----------------------------------------------------------------
> ISourceGroup
> -----------------------------------------------------------------
>
>    /// <summary>
>    /// Defines the minimum set of properties/methods/events to be
> implemented by a source group (ie, fleet, etc).
>    /// </summary>
>    public interface ISourceGroup : IParameters
>    {
>       /// <summary>
>       /// If this source group is a vibrator fleet, this will be the
> logical number for this fleet (NOT the database ID).  For any other
> source type, this will be -1.
>       /// </summary>
>       sbyte FleetNumber { get; }
>
>       /// <summary>
>       /// Indicates whether or not this SourceGroup is ready to shoot
>       /// </summary>
>       /// TODO: Ryan - should this be renamed to ReadyToShoot?
>       bool Enabled { get; }
>
>       /// <summary>
>       /// Indicates that Source Group is both enabled and has a source
> unit (ShotPro decoder for dynamite)
>       /// assigned to it
>       /// </summary>
>       bool EnabledWithDecoders { get; }
>
>       /// <summary>
>       /// Indicates that this fleet is not a real fleet, but an
> abstraction that means "any fleet."
>       /// It is used when source point can be shot by any fleet. This
> source point is associated
>       /// with "any armed" fleet instead of concrete fleet
>       /// </summary>
>       bool AnyArmed { get; }
>
>       ///// <summary>
>       ///// Returns a bit array of decoder numbers which have been
> associated with this source group.  For dynamite crews, this will only
>       ///// contain 1 number.
>       ///// </summary>
>       //uint DecoderNumbersAsBitArray { get; }
>
>       /// <summary>
>       /// The type of technology used by this source group to generate
> a seismic source.
>       /// </summary>
>       SourceType SourceType { get; }
>
>       /// <summary>
>       /// Returns a dictionary of ISourceControllers which are
> assigned to this source group.
>       /// </summary>
>       Dictionary<int, ISourceController> SourceControllers { get; }
>    }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to