Hi Patrick,
Clock and Alarm are simple classes, as follows:
public class Clock
{
public Clock()
{
Alarms = new List<Alarm>();
}
public virtual int Id { get; private set; }
public virtual IList<Alarm> Alarms { get; private set; }
public virtual DateTime GetCurrentTime()
{
return DateTime.Now;
}
public virtual void AddAlarm(Alarm alarm)
{
Alarms.Add (alarm);
alarm.Clock = this;
}
public virtual void RemoveAlarm(Alarm alarm)
{
Alarms.Remove(alarm);
alarm.Clock = null;
}
public virtual bool IsAnyAlarmSet()
{
foreach (var alarm in Alarms)
{
if (alarm.IsSet)
return true;
}
return false;
}
public virtual bool IsAnyAlarmSounding()
{
foreach (var alarm in Alarms)
{
if (alarm.AlarmTime.Hour == DateTime.Now.Hour &&
alarm.AlarmTime.Minute == DateTime.Now.Minute)
return true;
}
return false;
}
}
public class Alarm
{
public Alarm()
{
Message = "Wake up!";
_alarmTime = CreateAlarmTime(0, 0);
}
public virtual DateTime CreateAlarmTime(int hour, int minute)
{
return new DateTime(
System.Data.SqlTypes.SqlDateTime.MinValue.Value.Year,
System.Data.SqlTypes.SqlDateTime.MinValue.Value.Month,
System.Data.SqlTypes.SqlDateTime.MinValue.Value.Day,
hour, minute, 0);
}
public virtual int Id { get; set; }
public virtual Clock Clock { get; set; }
public virtual string AlarmName { get; set; }
DateTime _alarmTime;
public virtual DateTime AlarmTime
{
get { return _alarmTime; }
set { _alarmTime = CreateAlarmTime(value.Hour,
value.Minute); }
}
public virtual string Message { get; set; }
public virtual bool IsSet { get; set; }
}
Anthony
On Nov 29, 12:38 pm, Patrick Steele <[email protected]> wrote:
> What does the "Clock" object returned by
> "UnitTestHelpers.GetClockWithAlarms()" look like? Is the Alarms array
> populated? I see you're referencing "Alarms[0]" as a parameter to the
> mapper.Map call.
>
> ---
> Patrick Steelehttp://weblogs.asp.net/psteele
>
>
>
> On Mon, Nov 29, 2010 at 4:04 AM, Anthony <[email protected]> wrote:
> > Hi,
>
> > Could anyone help me with what is probably a basic question. I
> > receive an InvalidOperationException from the code below at the end of
> > the _mocks.Record() block when I run all my tests together in NUnit
> > GUI. When I run the tests individually, they all run and pass with no
> > exception!
>
> > I am using Rhino Mocks 3.6 and NUnit 2.5.8 as part of an ASP.NET 4.0
> > MVC 2 project.
>
> > Here is one of my tests, am I doing something wrong with the Record/
> > Playback syntax?
>
> > [Test]
> > public void Can_render_edit_view()
> > {
> > IClockRepository repo =
> > _mocks.DynamicMock<IClockRepository>();
> > IMapper<Alarm, AlarmViewModel> mapper =
> > _mocks.DynamicMock<IMapper<Alarm, AlarmViewModel>>();
> > var controller = new AlarmController(repo, mapper);
> > AlarmViewModel vm = new AlarmViewModel()
> > {
> > Id = 1,
> > AlarmName = "Test",
> > AlarmTime = "12:00",
> > IsSet = true,
> > Message = "Wake up"
> > };
>
> > Clock clock = UnitTestHelpers.GetClockWithAlarms();
> > using (_mocks.Record())
> > {
> > Expect.Call(repo.GetClock()).Return(clock);
> > Expect.Call(mapper.Map(clock.Alarms[0])).Return(vm);
> > }
> > ActionResult result;
> > using (_mocks.Playback())
> > {
> > result = controller.Edit(1);
> > }
>
> > result.ShouldBeDefaultView();
> > }
>
> > Any help would be really appreciated!
>
> > Anthony
>
> > --
> > 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
> > athttp://groups.google.com/group/rhinomocks?hl=en.- Hide quoted text -
>
> - Show quoted text -
--
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.