public void True_for_nullable_boolean_returns_true()
        {
            bool?expected = true;

            var actual = BindingResult.True <bool?>();

            AssertSome(expected, actual);
        }
        public void False_for_nullable_boolean_returns_false()
        {
            bool?expected = false;

            var actual = BindingResult.False <bool?>();

            AssertSome(expected, actual);
        }
        public void From_nullable_creates_instance_with_some_when_value_is_not_null()
        {
            int?value = 42;

            var actual = BindingResult.FromNullable(value);

            AssertSome(value.Value, actual);
        }
        public void From_nullable_creates_instance_with_none_when_value_is_null()
        {
            int?value = null;

            var actual = BindingResult.FromNullable(value);

            AssertNone(actual);
        }
        public void Some_value_can_be_null_for_nullable_value_types()
        {
            int?value = null;

            var actual = BindingResult.Some(value);

            AssertSome(value, actual);
        }
        public void Some_value_can_be_null_for_ref_types()
        {
            object value = null;

            var actual = BindingResult.Some(value);

            AssertSome(value, actual);
        }
        public void Some_creates_instance_with_given_value()
        {
            var value = "foo";

            var actual = BindingResult.Some(value);

            AssertSome(value, actual);
        }
        public void Ctor_correctly_initializes_members()
        {
            var value = "Foo";

            var actual = new BindingResult <string>(value);

            Assert.True(actual.HasValue);
            Assert.Same(value, actual.Value);
        }
예제 #9
0
        public void Ctor_correctly_initializes_members()
        {
            var expectedOldResult = BindingResult.Some(42);
            var expectedNewResult = BindingResult.Some(84);

            var actual = new BindingResultChange <int>(expectedOldResult, expectedNewResult);

            AssertEx.Equal(expectedOldResult, actual.OldResult);
            AssertEx.Equal(expectedNewResult, actual.NewResult);
        }
예제 #10
0
 public void Implements_equality_contract()
 {
     EqualityContract.Assert(
         equivalent: new[]
     {
         new BindingResultChange <int>(BindingResult.Some(0), BindingResult.Some(1)),
         new BindingResultChange <int>(BindingResult.Some(0), BindingResult.Some(1))
     },
         distinct: new[]
     {
         new BindingResultChange <int>(BindingResult.Some(0), BindingResult.Some(1)),
         new BindingResultChange <int>(BindingResult.Some(1), BindingResult.Some(1)),
         new BindingResultChange <int>(BindingResult.Some(0), BindingResult.Some(0)),
         new BindingResultChange <int>(BindingResult.None <int>(), BindingResult.Some(1)),
         new BindingResultChange <int>(BindingResult.Some(0), BindingResult.None <int>())
     });
 }
예제 #11
0
 /// <inheritdoc />
 public bool Equals(BindingResult <T> other)
 {
     return(HasValue == other.HasValue && (!HasValue || ValueComparer.Equals(_value, other._value)));
 }
 private static void AssertNone <T>(BindingResult <T> actual)
 {
     Assert.False(actual.HasValue);
 }
 private static void AssertSome <T>(T expected, BindingResult <T> actual)
 {
     Assert.True(actual.HasValue);
     Assert.Equal(expected, actual.Value);
 }
 public void True_and_false_for_non_boolean_type_throws()
 {
     // We are not concerned with the exact exception type, only that it throws.
     Assert.ThrowsAny <Exception>(() => BindingResult.True <int>());
     Assert.ThrowsAny <Exception>(() => BindingResult.False <long>());
 }
        public void None_creates_instance_with_no_value()
        {
            var actual = BindingResult.None <string>();

            AssertNone(actual);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BindingResultChange{T}"/> structure.
 /// </summary>
 /// <param name="oldResult">The old binding result.</param>
 /// <param name="newResult">The new binding result.</param>
 public BindingResultChange(BindingResult <T> oldResult, BindingResult <T> newResult)
 {
     OldResult = oldResult;
     NewResult = newResult;
 }