コード例 #1
0
        public void IsSatisfiedByWithNullRequestShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new PropertySpecification(typeof(object), "someName");

            // Act & assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.IsSatisfiedBy(null));
        }
コード例 #2
0
        public void IsSatisfiedByWithNullRequestShouldThrowArgumentNullException()
        {
            // Fixture setup
            var sut = new PropertySpecification(typeof(object), "someName");

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.IsSatisfiedBy(null));
            // Teardown
        }
            public void TrueSpecification_ReturnTrue <T>(FakeType candidate, Expression <Func <FakeType, T> > selector)
            {
                var specification = MockSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.True(result);
            }
コード例 #4
0
        public void IsSatisfiedByWithInvalidRequestShouldReturnFalse(object request)
        {
            // Arrange
            var sut = new PropertySpecification(typeof(object), "someName");
            // Act
            var result = sut.IsSatisfiedBy(request);

            // Assert
            Assert.False(result);
        }
コード例 #5
0
        public void IsSatisfiedByWithInvalidRequestShouldReturnFalse(object request)
        {
            // Fixture setup
            var sut = new PropertySpecification(typeof(object), "someName");
            // Exercise system
            var result = sut.IsSatisfiedBy(request);

            // Verify outcome
            Assert.False(result);
            // Teardown
        }
            public void FalseSpecification_ReturnFalse <T>(FakeType candidate, Expression <Func <FakeType, T> > selector)
            {
                candidate = candidate.Second != "null" ? candidate : null;
                var specification = MockSpecification <T> .False();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.False(result);
            }
            public void TrueSpecification_ReturnExpectedResultObject <T>(FakeType candidate,
                                                                         Expression <Func <FakeType, T> > selector, SpecificationResult expected)
            {
                ISpecification <T> specification = MockValidationSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var overall = sut.IsSatisfiedBy(candidate, out var result);

                Assert.True(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer());
            }
            public void RelatedTypes_NoException()
            {
                var specification = MockSpecification <IEnumerable <char> > .True();

                var exception = Record.Exception(() =>
                {
                    var sut = new PropertySpecification <FakeType, string>(
                        ft => ft.Second, specification);
                    sut.IsSatisfiedBy(new FakeType(), out _);
                });

                Assert.Null(exception);
            }
コード例 #9
0
        public void IsSatisfiedByWithRequestForReadOnlyPropertyWithSameNameShouldReturnTrue()
        {
            // Arrange
            var propertyName  = "Property";
            var requestedName = "Property";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(ReadOnlyPropertyHolder <object>).GetProperty(requestedName);
            // Act
            var result = sut.IsSatisfiedBy(request);

            // Assert
            Assert.True(result);
        }
コード例 #10
0
        public void IsSatisfiedByWithRequestForMemberOtherThanPropertyWithSameNameShouldReturnFalse()
        {
            // Arrange
            var propertyName  = "Field";
            var requestedName = "Field";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(FieldHolder <object>).GetField(requestedName);
            // Act
            var result = sut.IsSatisfiedBy(request);

            // Assert
            Assert.False(result);
        }
コード例 #11
0
        public void IsSatisfiedByWithRequestForPropertyWithSameNameAndIncompatibleTypeShouldReturnFalse()
        {
            // Arrange
            var propertyName  = "Property";
            var requestedName = "Property";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(PropertyHolder <int>).GetProperty(requestedName);
            // Act
            var result = sut.IsSatisfiedBy(request);

            // Assert
            Assert.False(result);
        }
コード例 #12
0
        public void IsSatisfiedByWithRequestForPropertyWithSameNameAndIncompatibleTypeShouldReturnFalse()
        {
            // Fixture setup
            var propertyName  = "Property";
            var requestedName = "Property";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(PropertyHolder <int>).GetProperty(requestedName);
            // Exercise system
            var result = sut.IsSatisfiedBy(request);

            // Verify outcome
            Assert.False(result);
            // Teardown
        }
コード例 #13
0
        public void IsSatisfiedByWithRequestForReadOnlyPropertyWithSameNameShouldReturnTrue()
        {
            // Fixture setup
            var propertyName  = "Property";
            var requestedName = "Property";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(ReadOnlyPropertyHolder <object>).GetProperty(requestedName);
            // Exercise system
            var result = sut.IsSatisfiedBy(request);

            // Verify outcome
            Assert.True(result);
            // Teardown
        }
コード例 #14
0
        public void IsSatisfiedByWithRequestForPropertyShouldReturnCorrectResult(
            string propertyName,
            string requestedName,
            bool expectedResult)
        {
            // Arrange
            var sut     = new PropertySpecification(typeof(object), propertyName);
            var request = typeof(PropertyHolder <object>).GetProperty(requestedName);
            // Act
            var result = sut.IsSatisfiedBy(request);

            // Assert
            Assert.Equal(expectedResult, result);
        }
コード例 #15
0
        public void IsSatisfiedByWithRequestForMemberOtherThanPropertyWithSameNameShouldReturnFalse()
        {
            // Fixture setup
            var propertyName  = "Field";
            var requestedName = "Field";
            var sut           = new PropertySpecification(typeof(object), propertyName);
            var request       = typeof(FieldHolder <object>).GetField(requestedName);
            // Exercise system
            var result = sut.IsSatisfiedBy(request);

            // Verify outcome
            Assert.False(result);
            // Teardown
        }
コード例 #16
0
        public void IsSatisfiedByWithRequestForPropertyShouldReturnCorrectResult(
            string propertyName,
            string requestedName,
            bool expectedResult)
        {
            // Fixture setup
            var sut     = new PropertySpecification(typeof(object), propertyName);
            var request = typeof(PropertyHolder <object>).GetProperty(requestedName);
            // Exercise system
            var result = sut.IsSatisfiedBy(request);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
            public void FalseSpecification_ReturnExpectedResultObject <T>(FakeType candidate,
                                                                          Expression <Func <FakeType, T> > selector, SpecificationResult expected)
            {
                candidate = candidate.Second != "null" ? candidate : null;
                ISpecification <T> specification = MockComplexSpecification <T> .False();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var overall = sut.IsSatisfiedBy(candidate, out var result);

                Assert.False(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer(
                                 parameters: new Dictionary <string, object>
                {
                    { "PropertySpecification", specification }
                }));
            }
コード例 #18
0
        public void IsSatisfiedByReturnsCorrectResultAccordingToTarget(
            bool expected)
        {
            var prop   = typeof(string).GetProperty("Length");
            var target = new DelegatingCriterion <PropertyInfo>
            {
                OnEquals = p =>
                {
                    Assert.Equal(prop, p);
                    return(expected);
                }
            };
            var sut = new PropertySpecification(target);

            var actual = sut.IsSatisfiedBy(prop);

            Assert.Equal(expected, actual);
        }
コード例 #19
0
 public void ItWorks(string artist, bool result)
 {
     specification.Expect(x => x.IsSatisfiedBy(artist)).Return(result);
     Assert.AreEqual(sut.IsSatisfiedBy(testAlbum), result);
 }
コード例 #20
0
        public void ReturnsCorrectResultForLambdaExpression(TestObject testObject, bool expectedResult)
        {
            var specification = new PropertySpecification <TestObject, TestObject>(p => p.Property, new ExpressionSpecification <TestObject>(p => p.BooleanProperty));

            specification.IsSatisfiedBy(testObject).ShouldBe(expectedResult);
        }