Пример #1
0
        public void ShouldPassWhenAllExpectedPropertiesChange()
        {
            // arrange
            var assert   = new Asserter();
            var subject  = new Person();
            var expected = "Bob";

            // act, asssert (expect setting FirstName also raises event for FullName)
            assert.PropertyChanged(subject, p => p.FirstName, expected, p => p.FullName);
        }
Пример #2
0
        public void ShouldPassWhenOnlyOnePropertyChangeIsExpected()
        {
            // arrange
            var assert   = new Asserter();
            var subject  = new Person();
            var expected = 123;

            // act, assert
            assert.PropertyChanged(subject, p => p.Id, expected);
        }
Пример #3
0
        public void PropertyChangedShouldAssertNullObject()
        {
            // arrange
            var assert  = new Asserter();
            var subject = default(Person);

            try
            {
                // act
                assert.PropertyChanged(subject, p => p.FirstName, string.Empty);
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual(GetExpectedMessage(nameof(subject)), ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
Пример #4
0
        public void ShouldFailWhenSomeOfTheExpectedPropertiesDoNotChange()
        {
            // assert
            var assert   = new Asserter();
            var subject  = new Person();
            var expected = "Bob";

            try
            {
                // act (expect FirstName and FullName, but not LastName)
                assert.PropertyChanged(subject, p => p.FirstName, expected, p => p.FullName, p => p.LastName);
            }
            catch (AssertFailedException)
            {
                // assert
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
Пример #5
0
        public void ShouldFailWhenOnePropertyPropertyChangeIsExpectedButMultiplePropertiesChange()
        {
            // arrange
            var assert   = new Asserter();
            var subject  = new Person();
            var expected = "Bob";

            try
            {
                // act (setting the FirstName property also raises FullName property change, but is not expected)
                assert.PropertyChanged(subject, p => p.FirstName, expected);
            }
            catch (AssertFailedException)
            {
                // assert
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
Пример #6
0
        public void PropertyChangedShouldAssertNullOtherPropertyExpressions()
        {
            // arrange
            var assert          = new Asserter();
            var subject         = new Person();
            var otherProperties = default(Expression <Func <Person, object> >[]);

            try
            {
                // act
                assert.PropertyChanged(subject, p => p.FirstName, string.Empty, otherProperties);
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual(GetExpectedMessage(nameof(otherProperties)), ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }
Пример #7
0
        public void PropertyChangedShouldAssertNullPropertyExpression()
        {
            // arrange
            var assert       = new Asserter();
            var subject      = new Person();
            var testProperty = default(Expression <Func <Person, string> >);

            try
            {
                // act
                assert.PropertyChanged(subject, testProperty, string.Empty);
            }
            catch (AssertFailedException ex)
            {
                // assert
                Assert.AreEqual(GetExpectedMessage(nameof(testProperty)), ex.Message);
                return;
            }

            Assert.Fail("An exception was expected, but not thrown.");
        }