public static ISpecification<Place> ByAddress(Address address)
        {
            Specification<Place> specification = new TrueSpecification<Place>();

            if (address != null)
            {
                var stspec = new DirectSpecification<Place>(
                    p => p.Address.Street.ToLower().Contains(
                        address.Street.ToLower()
                        )
                    );

                var dtspec = new DirectSpecification<Place>(
                    p => p.Address.District.ToLower().Contains(
                        address.District.ToLower()
                        )
                    );
                var zpspec = new DirectSpecification<Place>(
                    p => p.Address.ZipCode == address.ZipCode
                    );

                specification &= stspec || dtspec || zpspec;
            }

            return specification;
        }
Example #2
0
 public ActionResult AdList()
 {
     ISpecification<Advertisement> spec = new TrueSpecification<Advertisement>();
     var lst = productRepository.GetAdvertisementsList(spec);
     ViewBag.IsEditable = false;
     return View(lst);
 }
        /// <summary>
        /// The orders in a date range
        /// </summary>
        /// <param name="startDate">The start date </param>
        /// <param name="endDate">The end date</param>
        /// <returns>Related specification for this criteria</returns>
        public static ISpecification<Order> OrderFromDateRange(DateTime? startDate, DateTime? endDate)
        {
            Specification<Order> spec = new TrueSpecification<Order>();

            if (startDate.HasValue)
                spec &= new DirectSpecification<Order>(o => o.OrderDate > (startDate ?? DateTime.MinValue));

            if (endDate.HasValue)
                spec &= new DirectSpecification<Order>(o => o.OrderDate < (endDate ?? DateTime.MaxValue));

            return spec;
        }
      /// <summary>
      ///    Specification for bank accounts with number like to <paramref name="ibanNumber" />
      /// </summary>
      /// <param name="ibanNumber">The bank account number</param>
      /// <returns>Associated specification</returns>
      public static ISpecification<BankAccount> BankAccountIbanNumber(string ibanNumber)
      {
         Specification<BankAccount> specification = new TrueSpecification<BankAccount>();

         if (!String.IsNullOrWhiteSpace(ibanNumber))
         {
            specification &= new DirectSpecification<BankAccount>(
               (b) => b.Iban.ToLower().Contains(ibanNumber.ToLower()));
         }

         return specification;
      }
        public static ISpecification<Place> ByAddress(Guid addressId)
        {
            Specification<Place> specification = new TrueSpecification<Place>();

            if (addressId != Guid.Empty)
            {
                specification &= new DirectSpecification<Place>(
                    p => p.AddressId == addressId
                    );
            }

            return specification;
        }
Example #6
0
        /// <summary>
        /// Specification for menu with application code like to <paramref name="text"/>
        /// </summary>
        /// <param name="text">The text to search</param>
        /// <returns>Associated specification for this criterion</returns>
        public static ISpecification<User> UserName(string userName)
        {
            Specification<User> specification = new TrueSpecification<User>();

            if (!string.IsNullOrWhiteSpace(userName))
            {
                var nameSpecification = new DirectSpecification<User>(c => c.UserName.ToLower() == userName.ToLower());

                specification &= nameSpecification;
            }

            return specification;
        }
Example #7
0
        /// <summary>
        /// Specification for menu with application code like to <paramref name="text"/>
        /// </summary>
        /// <param name="text">The text to search</param>
        /// <returns>Associated specification for this criterion</returns>
        public static ISpecification<Menu> ApplicationCodeFullText(string text)
        {
            Specification<Menu> specification = new TrueSpecification<Menu>();

            if(!String.IsNullOrWhiteSpace(text)) {
                var nameSpecification = new DirectSpecification<Menu>(c => c.ApplicationCode.ToLower().Contains(text));

                specification &= nameSpecification;

            }

            return specification;
        }
        public static ISpecification<Place> ByName(string name)
        {
            Specification<Place> specification = new TrueSpecification<Place>();

            if (!string.IsNullOrWhiteSpace(name))
            {
                specification &= new DirectSpecification<Place>(
                    p => p.Name.ToLower().Contains(name.ToLower())
                    );
            }

            return specification;
        }
        public static ISpecification<Place> ByCategory(Guid categoryId)
        {
            Specification<Place> specification = new TrueSpecification<Place>();

            if (categoryId != Guid.Empty)
            {
                specification &= new DirectSpecification<Place>(
                    p => p.CategoryId == categoryId
                    );
            }

            return specification;
        }
Example #10
0
        public static ISpecification<Person> NameFullText(string text)
        {
            Specification<Person> specification = new TrueSpecification<Person>();

            if (!string.IsNullOrWhiteSpace(text))
            {
                var firstNameSpecification = new DirectSpecification<Person>(c => c.FirstName.ToLower().Contains(text.ToLower()));
                var lastNameSpecification = new DirectSpecification<Person>(c => c.LastName.ToLower().Contains(text.ToLower()));

                specification &= (firstNameSpecification || lastNameSpecification);
            }

            return specification;
        }
        /// <summary>
        /// Specification for country with name or iso code like to <paramref name="text"/>
        /// </summary>
        /// <param name="text">The text to search</param>
        /// <returns>Associated specification for this criterion</returns>
        public static ISpecification<Country> CountryFullText(string text)
        {
            Specification<Country> specification = new TrueSpecification<Country>();

            if (!String.IsNullOrWhiteSpace(text))
            {
                var nameSpecification = new DirectSpecification<Country>(c => c.CountryName.ToLower().Contains(text));
                var isoCodeSpecification = new DirectSpecification<Country>(c => c.CountryISOCode.ToLower().Contains(text));

                specification &= (nameSpecification || isoCodeSpecification);
            }

            return specification;
        }
        /// <summary>
        /// Profile with firstName or LastName or Email equal to
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="email"></param>
        /// <returns>Associated specification for this creterion</returns>
        public static Specification<Profile> GetProfileByFilter(string firstName, string lastName, string email)
        {
            Specification<Profile> specProfile = new TrueSpecification<Profile>();

            if ( !string.IsNullOrEmpty(firstName))
                specProfile &= new DirectSpecification<Profile>(p => p.FirstName.Contains(firstName));

            if (!string.IsNullOrEmpty(lastName))
                specProfile &= new DirectSpecification<Profile>(p => p.LastName.Contains(lastName));

            if (!string.IsNullOrEmpty(email))
                specProfile &= new DirectSpecification<Profile>(p => p.Email.Contains(email));

            return specProfile;
        }
      /// <summary>
      ///    The product full text specification
      /// </summary>
      /// <param name="text">the text to find in title or product description</param>
      /// <returns>Associated specification for this criterion</returns>
      public static ISpecification<Product> ProductFullText(string text)
      {
         Specification<Product> fullTextSpecification = new TrueSpecification<Product>();

         if (!String.IsNullOrWhiteSpace(text))
         {

            var left = new DirectSpecification<Product>(p => p.Title.ToLower().Contains(text.ToLower()));
            var right = new DirectSpecification<Product>(p => p.Description.ToLower().Contains(text.ToLower()));

            fullTextSpecification &= new OrSpecification<Product>(left, right);
         }

         return fullTextSpecification;
      }
Example #14
0
        public static Specification <TituloPagar> DataPeriodoMenorOuIgualSituacaoPagosRelContasPagarTitulos(SituacaoTituloPagar situacao, string tipoPesquisa, DateTime?data)
        {
            Specification <TituloPagar> specification = new TrueSpecification <TituloPagar>();

            DateTime dataUltimaHora = new DateTime(data.Value.Year, data.Value.Month, data.Value.Day, 23, 59, 59);

            if (situacao == SituacaoTituloPagar.Emitido)
            {
                if (tipoPesquisa.ToUpper() == "V")
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataVencimento <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
                else
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataEmissao <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
            }

            if (situacao == SituacaoTituloPagar.Pago)
            {
                if (tipoPesquisa.ToUpper() == "V")
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataVencimento <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
                else
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataPagamento <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
            }

            if (situacao == SituacaoTituloPagar.Baixado)
            {
                if (tipoPesquisa.ToUpper() == "V")
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataVencimento <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
                else
                {
                    if (data.HasValue)
                    {
                        var directSpecification = new DirectSpecification <TituloPagar>(l => l.DataBaixa <= dataUltimaHora);
                        specification &= directSpecification;
                    }
                }
            }


            return(specification);
        }
		public void Test_False_InvalidType()
		{
			// test something that is not a boolean value
			TrueSpecification s = new TrueSpecification();
			s.Test(1);
		}
        public void CreateTrueSpecificationTest()
        {
            ISpecification<SampleEntity> trueSpec = new TrueSpecification<SampleEntity>();

            Assert.IsNotNull(trueSpec);

            var result = trueSpec.SatisfiedBy().Compile()(new SampleEntity());

            Assert.AreEqual(true, result);
        }
		public void Test_True()
		{
			TrueSpecification s = new TrueSpecification();
			Assert.IsTrue(s.Test(true).Success);
			Assert.IsFalse(s.Test(false).Success);
		}
 public When_Invoked()
 {
     option = new TrueSpecification();
     result = option.IsSatisfiedBy(new object());
 }
 public void TrueSpecification_Creation_Test()
 {
     //Arrange
     ISpecification<TEntity> trueSpec = new TrueSpecification<TEntity>();
     bool expected = true;
     bool actual = trueSpec.SatisfiedBy().Compile()(new TEntity());
     //Assert
     Assert.IsNotNull(trueSpec);
     Assert.AreEqual(expected,actual);
 }
Example #20
0
 public void CreateTrueSpecificationTest()
 {
    //Arrange
    ISpecification<SampleEntity> trueSpec = new TrueSpecification<SampleEntity>();
    var expected = true;
    var actual = trueSpec.SatisfiedBy().Compile()(new SampleEntity());
    //Assert
    Assert.IsNotNull(trueSpec);
    Assert.AreEqual(expected, actual);
 }
Example #21
0
        public void CriaTrueSpecificationTest()
        {
            Expression<Func<ClienteStub, bool>> leftLambda = s => s.Nome == "MARCUS";

            var leftSpecification = new DirectSpecification<ClienteStub>(leftLambda);

            Specification<ClienteStub> andSpec = new TrueSpecification<ClienteStub>();

            List<ClienteStub> listaCliente = new List<ClienteStub>();

            listaCliente.Add(new ClienteStub() { Nome = "VINICIUS" });

            var result = listaCliente.AsQueryable().Where(andSpec.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 1);
        }