示例#1
0
        public void ShouldVerifySpecificItem()
        {
            var spec = new GenericSpecification<User>(u => u.FavoriteNumber > 3);

            var user1 = new User { FavoriteNumber = 4 };
            Assert.True(spec.IsSatisfiedBy(user1));

            var user2 = new User { FavoriteNumber = 1 };
            Assert.False(spec.IsSatisfiedBy(user2));
        }
示例#2
0
        public void Specification_GenericSpecification_ShouldReturnTrue()
        {
            // Arrange
            var movie   = MovieFactory.GetMixedMovies().FirstOrDefault(m => m.MpaaRating > MpaaRating.PG && m.Rating >= 4);
            var genSpec = new GenericSpecification <Movie>(m => m.MpaaRating > MpaaRating.PG && m.Rating >= 4);

            // Act
            var result = genSpec.IsSatisfiedBy(movie);

            // Assert
            Assert.True(result);
        }
        public void AddExpressionToSpecificationtoBeSatisified(long propertyValue, long specificationValue, bool expectedResult)
        {
            //Arrange
            var aTestClassWithValue = new TestClass()
            {
                SomeProperyValue = propertyValue
            };
            IGenericSpecification <TestClass> specification = new GenericSpecification <TestClass>(x => x.SomeProperyValue <= specificationValue);

            //Action
            var actualresult = specification.IsSatisfiedBy(aTestClassWithValue);

            //Assert
            Assert.True(specification is IGenericSpecification <TestClass>);
            Assert.Equal(expectedResult, actualresult);
        }
示例#4
0
        public string BuyAvailableOnCdTicket(int movieId)
        {
            var movie = repository.GetById(movieId);

            if (movie == null)
            {
                return("Movie doesn't exist");
            }

            var specification = new GenericSpecification <MovieMiddle>(MovieMiddle.HasCdVersion);

            if (!specification.IsSatisfiedBy(movie))
            {
                return("This movie doesn't have CD version");
            }

            return("Children ticket were bought successfully");
        }
示例#5
0
        public string BuyChildTicket(int movieId)
        {
            var movie = repository.GetById(movieId);

            if (movie == null)
            {
                return("Movie doesn't exist");
            }

            var specification = new GenericSpecification <MovieMiddle>(MovieMiddle.IsSuitableForChildren);

            if (!specification.IsSatisfiedBy(movie))
            {
                return("This movie is not available for children");
            }

            return("Children ticket were bought successfully");
        }
        public void Specification_is_satisfied_when_expression_is_true_for_candidate_object()
        {
            var candidateObject = new TestClass() {Salary = 5000};
            var specification = new GenericSpecification<TestClass>(t=>t.Salary>4000);

            var isSatisfied = specification.IsSatisfiedBy(candidateObject);

            Assert.IsTrue(isSatisfied);
        }