예제 #1
0
        void ValueClampedEvent()
        {
            IClampedPropertyT <Int32> prop = new ClampedPropertyT <Int32>(0, -1, 5);

            Test.IfNot.Action.RaisesEvent(() => prop.Value = 0, prop, "ValueClamped", out EventData <ValueClampedEventArgs <Int32> > eventData);

            Test.If.Action.RaisesEvent(() => prop.Value = 1, prop, "ValueClamped", out eventData);

            Test.IfNot.Object.IsNull(eventData.Sender);
            Test.If.Reference.IsEqual(eventData.Sender, prop);
            Test.IfNot.Object.IsNull(eventData.EventArgs);
            Test.If.Value.IsEqual(eventData.EventArgs.Set, 1);
            Test.If.Value.IsEqual(eventData.EventArgs.Old, 0);
            Test.If.Value.IsEqual(eventData.EventArgs.New, 1);
            Test.If.Value.IsFalse(eventData.EventArgs.HasBeenClamped);
            Test.If.Value.IsTrue(eventData.EventArgs.HasChanged);

            Test.If.Action.RaisesEvent(() => prop.Value = 6, prop, "ValueClamped", out eventData);

            Test.IfNot.Object.IsNull(eventData.Sender);
            Test.If.Reference.IsEqual(eventData.Sender, prop);
            Test.IfNot.Object.IsNull(eventData.EventArgs);
            Test.If.Value.IsEqual(eventData.EventArgs.Set, 6);
            Test.If.Value.IsEqual(eventData.EventArgs.Old, 1);
            Test.If.Value.IsEqual(eventData.EventArgs.New, 5);
            Test.If.Value.IsTrue(eventData.EventArgs.HasBeenClamped);
            Test.If.Value.IsTrue(eventData.EventArgs.HasChanged);
        }
예제 #2
0
        void ConstructorThrows()
        {
            IClampedPropertyT <Version> prop = null;

            Test.If.Action.ThrowsException(() => prop = new ClampedPropertyT <Version>(null, new Version(1, 1), new Version(1, 3)), out ArgumentNullException argEx);

            Test.IfNot.Object.IsNull(argEx);
            Test.If.Value.IsEqual(argEx.ParamName, "value");
            Test.If.Object.IsNull(prop);
        }
예제 #3
0
        void MinimumProperty <TValue>(TValue input1, TValue input2, TValue input3, TValue newMin, TValue value, TValue min, TValue max)
            where TValue : IComparable <TValue>
        {
            IClampedPropertyT <TValue> prop = new ClampedPropertyT <TValue>(input1, input2, input3);

            Test.IfNot.Action.ThrowsException(() => prop.Minimum = newMin, out Exception ex);

            Test.If.Value.IsEqual(prop.Minimum, min);
            Test.If.Value.IsEqual(prop.Maximum, max);
            Test.If.Value.IsEqual(prop.Value, value);
        }
예제 #4
0
        void Constructor <TValue>(TValue input1, TValue input2, TValue input3, TValue value, TValue min, TValue max)
            where TValue : IComparable <TValue>
        {
            IClampedPropertyT <TValue> prop = null;

            Test.IfNot.Action.ThrowsException(() => prop = new ClampedPropertyT <TValue>(input1, input2, input3), out Exception ex);

            Test.IfNot.Object.IsNull(prop);
            Test.If.Value.IsEqual(prop.Minimum, min);
            Test.If.Value.IsEqual(prop.Maximum, max);
            Test.If.Value.IsEqual(prop.Value, value);
        }
예제 #5
0
        IEnumerable <Object[]> RaisePropertyChangedEventData()
        {
            IClampedPropertyT <Int32>  intProp    = new ClampedPropertyT <Int32>(0, -1, 1);
            IClampedPropertyT <String> stringProp = new ClampedPropertyT <String>("b", "a", "c");

            return(new List <Object[]>()
            {
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Value = 1), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Minimum = -1), Enumerable.Empty <EventData <PropertyChangedEventArgs> >() },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Minimum = 0), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Minimum"))
                               } },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Minimum = 1), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Minimum")), new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Maximum = 1), Enumerable.Empty <EventData <PropertyChangedEventArgs> >() },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Maximum = 0), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Maximum"))
                               } },
                new Object[] { typeof(Int32), intProp, 0, -1, 1, new Action(() => intProp.Maximum = -1), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Maximum")), new EventData <PropertyChangedEventArgs>(intProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Value = "c"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Minimum = "a"), Enumerable.Empty <EventData <PropertyChangedEventArgs> >() },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Minimum = "b"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Minimum"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Minimum = "c"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Minimum")), new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Maximum = "c"), Enumerable.Empty <EventData <PropertyChangedEventArgs> >() },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Maximum = "b"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Maximum"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Maximum = "a"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Maximum")), new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Value"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Minimum = null), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Minimum"))
                               } },
                new Object[] { typeof(String), stringProp, "b", "a", "c", new Action(() => stringProp.Maximum = null), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Maximum"))
                               } },
                new Object[] { typeof(String), stringProp, null, null, null, new Action(() => stringProp.Minimum = "a"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Minimum"))
                               } },
                new Object[] { typeof(String), stringProp, null, null, null, new Action(() => stringProp.Maximum = "a"), new List <EventData <PropertyChangedEventArgs> >()
                               {
                                   new EventData <PropertyChangedEventArgs>(stringProp, new PropertyChangedEventArgs("Maximum"))
                               } },
            });
        }