Bil Simser
unread,Apr 17, 2008, 3:04:55 PM4/17/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to xeva
The WindowOptions class is pretty lightweight but the properties
weren't being used except by consumers in the sample app (and even
then, some of them were not being set, only retrieved. I modified the
class to use the getter/setters rather than direct field access. The
specs have also been slightly changed (wrapping things up in record/
playback calls) to get the class fully tested.
Here's the updated WindowOptions class:
public class WindowOptions : IWindowOptions
{
private int _height;
private bool _modal;
private int _width;
public WindowOptions()
{
}
public WindowOptions(bool modal, int width, int height)
{
Modal = modal;
Width = width;
Height = height;
}
#region IWindowOptions Members
public bool Modal
{
get { return _modal; }
set { _modal = value; }
}
public int Width
{
get { return _width; }
set { _width = value; }
}
public int Height
{
get { return _height; }
set { _height = value; }
}
#endregion
public virtual void ApplyOptionsTo(IWindowAdapter
windowAdapter)
{
windowAdapter.Width = Width;
windowAdapter.Height = Height;
windowAdapter.Modal = Modal;
}
}
And here's the updated spec class:
[TestFixture]
public class When_applying_options_to_a_window_adapter : Spec
{
private IWindowAdapter _adapter;
private WindowOptions _options;
protected override void Before_each_spec()
{
_options = new WindowOptions(true, 800, 600);
_adapter = Mock<IWindowAdapter>();
}
[Test]
public void The_default_values_are_set_if_not_specified()
{
WindowOptions options = new WindowOptions();
Assert.AreEqual(0, options.Height);
Assert.AreEqual(0, options.Width);
Assert.AreEqual(false, options.Modal);
}
[Test]
public void Set_the_modal_property()
{
using (Record)
{
_adapter.Modal = true;
}
using (Playback)
{
_options.ApplyOptionsTo(_adapter);
}
}
[Test]
public void Set_the_width_property()
{
using (Record)
{
_adapter.Width = 800;
}
using (Playback)
{
_options.ApplyOptionsTo(_adapter);
}
}
[Test]
public void Set_the_height_property()
{
using (Record)
{
_adapter.Height = 600;
}
using (Playback)
{
_options.ApplyOptionsTo(_adapter);
}
}
}
Let me know what you think.