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)); }
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); }
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"); }
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); }