Skip to content
This repository
tag: 2.2.0.0
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (54 sloc) 2.041 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
using ReactiveUI;
using Xunit;
using System;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace ReactiveUI.Tests
{
    public class ValidatedTestFixture : ReactiveValidatedObject
    {
        public string _IsNotNullString;
[Required]
        public string IsNotNullString {
            get { return _IsNotNullString; }
            set { this.RaiseAndSetIfChanged(x => x.IsNotNullString, value); }
        }
        
        public string _IsOnlyOneWord;
[Required]
[RegularExpression(@"^[a-zA-Z]+$")]
        public string IsOnlyOneWord {
            get { return _IsOnlyOneWord; }
            set { this.RaiseAndSetIfChanged(x => x.IsOnlyOneWord, value); }
        }

        public string _UsesExprRaiseSet;
        public string UsesExprRaiseSet {
            get { return _UsesExprRaiseSet; }
            set { _UsesExprRaiseSet = this.RaiseAndSetIfChanged(x => x.UsesExprRaiseSet, value); }
        }
    }

    public class ReactiveValidatedObjectTest
    {
[Fact]
        public void IsObjectValidTest()
        {
            var output = new List<bool>();
            var fixture = new ValidatedTestFixture();
            //fixture.IsValidObservable.Subscribe(output.Add);

            Assert.False(fixture.IsObjectValid());

            fixture.IsNotNullString = "foo";
            Assert.False(fixture.IsObjectValid());

            fixture.IsOnlyOneWord = "Foo Bar";
            Assert.False(fixture.IsObjectValid());

            fixture.IsOnlyOneWord = "Foo";
            Assert.True(fixture.IsObjectValid());

            fixture.IsOnlyOneWord = "";
            Assert.False(fixture.IsObjectValid());

            /*
new[] { false, false, false, true, false }.Zip(output, (expected, actual) => new { expected, actual })
.Do(Console.WriteLine)
.Run(x => Assert.Equal(x.expected, x.actual));
*/
        }
    }
}
Something went wrong with that request. Please try again.