示例#1
0
        public void Data_DatabaseReader_CountAny()
        {
            var db = DatabaseReader <CustomerType> .Construct();

            // GetAll() count and any
            var resultsAll = db.GetAll();

            Assert.IsTrue(resultsAll.Count() > 0);
            Assert.IsTrue(resultsAll.Any());

            // GetAll().Take(1) count and any
            var resultsTake = db.GetAll().Take(1);

            Assert.IsTrue(resultsTake.Count() == 1);
            Assert.IsTrue(resultsTake.Any());

            // Get an ID to test
            var id = db.GetAllExcludeDefault().FirstOrDefaultSafe().ID;

            Assert.IsTrue(id != TypeExtension.DefaultInteger);

            // GetAll().Where count and any
            var resultsWhere = db.GetAll().Where(x => x.ID == id);

            Assert.IsTrue(resultsWhere.Count() > 0);
            Assert.IsTrue(resultsWhere.Any());
        }
示例#2
0
        public void Data_DatabaseReader_GetAll()
        {
            var typeDB = DatabaseReader <CustomerType> .Construct();

            var typeResults = typeDB.GetAll().Take(1);

            Assert.IsTrue(typeResults.Count() > 0);
        }
示例#3
0
        public void Data_DatabaseReader_GetByKey()
        {
            var custData = DatabaseReader <CustomerType> .Construct();

            // ByKey Should return 1 record
            var existingKey  = custData.GetAll().FirstOrDefaultSafe().Key;
            var custWhereKey = custData.GetAll().Where(x => x.Key == existingKey);

            Assert.IsTrue(custWhereKey.Count() > 0);
        }
        /// <summary>
        /// Gets all records that equal first + last + birth date
        /// Does == style search
        /// </summary>
        /// <param name="firstName">First name of customer</param>
        /// <param name="lastName">Last Name of customer</param>
        /// <param name="birthDate">Birth Date of customer</param>
        /// <returns></returns>
        public static IQueryable <CustomerInfo> GetByNameBirthdayKey(string firstName, string lastName, DateTime birthDate)
        {
            var reader = DatabaseReader <CustomerInfo> .Construct();

            IQueryable <CustomerInfo> returnValue = reader.GetAll()
                                                    .Where(x => (firstName != TypeExtension.DefaultString && x.FirstName == firstName) &&
                                                           (lastName != TypeExtension.DefaultString && x.LastName == lastName) &&
                                                           (birthDate != TypeExtension.DefaultDate && x.BirthDate == birthDate));

            return(returnValue);
        }
        /// <summary>
        /// Gets all records that contain any of the passed fields.
        /// Does contains/like style search
        /// </summary>
        /// <param name="searchFields">ICustomer with data to search</param>
        /// <returns>All records matching the passed ICustomer</returns>
        public static IQueryable <CustomerInfo> GetByAny(ICustomer searchFields)
        {
            var reader = DatabaseReader <CustomerInfo> .Construct();

            IQueryable <CustomerInfo> returnValue = reader.GetAll()
                                                    .Where(x => (searchFields.FirstName != TypeExtension.DefaultString && x.FirstName.Contains(searchFields.FirstName)) ||
                                                           (searchFields.LastName != TypeExtension.DefaultString && x.LastName.Contains(searchFields.LastName)) ||
                                                           (searchFields.BirthDate != TypeExtension.DefaultDate && x.BirthDate == searchFields.BirthDate) ||
                                                           (x.ID == searchFields.ID));

            return(returnValue);
        }
示例#6
0
        public void Data_DatabaseReader_Lists()
        {
            var emptyGuid = TypeExtension.DefaultGuid;

            // List Type
            var typeDB = DatabaseReader <CustomerType> .Construct();

            var typeResults = typeDB.GetAllExcludeDefault();

            Assert.IsTrue(typeResults.Count() > 0);
            Assert.IsTrue(typeResults.Any(x => x.Key == emptyGuid) == false);
            Assert.IsTrue(typeResults.Any(x => x.ID == -1) == false);
        }
示例#7
0
        public void Data_DatabaseReader_GetWhere()
        {
            // Plain EntityInfo object
            var typeData = DatabaseReader <CustomerType> .Construct();

            var testType = new CustomerType();
            var testId   = typeData.GetAllExcludeDefault().FirstOrDefaultSafe().ID;

            testType = typeData.GetAll().Where(x => x.ID == testId).FirstOrDefaultSafe();
            Assert.IsTrue(testType.IsNew == false);
            Assert.IsTrue(testType.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testType.Key != TypeExtension.DefaultGuid);
        }
示例#8
0
        public void Data_DatabaseReader_GetByID()
        {
            var custData = DatabaseReader <CustomerType> .Construct();

            var custEntity = new CustomerType();

            // ByID Should return 1 record
            var existingID  = custData.GetAllExcludeDefault().FirstOrDefaultSafe().ID;
            var custWhereID = custData.GetAll().Where(x => x.ID == existingID);

            Assert.IsTrue(custWhereID.Count() > 0);
            Assert.IsTrue(custWhereID.Any());

            custEntity = custWhereID.FirstOrDefaultSafe();
            Assert.IsTrue(custEntity.ID == existingID);
            Assert.IsTrue(custEntity.IsNew == false);
        }
        public CustomerModel Get(string id)
        {
            var reader = DatabaseReader <CustomerInfo> .Construct();

            var customer = new CustomerInfo();

            if (id.IsInteger())
            {
                customer = reader.GetByID(id.TryParseInt32());
            }
            else
            {
                customer = reader.GetByKey(id.TryParseGuid());
            }

            return(customer.CastOrFill <CustomerModel>());
        }
示例#10
0
        public void Data_DatabaseReader_Singles()
        {
            var typeDB = DatabaseReader <CustomerType> .Construct();

            var testItem  = new CustomerType();
            var emptyGuid = TypeExtension.DefaultGuid;

            // By ID
            testItem = typeDB.GetByID(typeDB.GetAllExcludeDefault().FirstOrDefaultSafe().ID);
            Assert.IsTrue(testItem.IsNew == false);
            Assert.IsTrue(testItem.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testItem.Key != TypeExtension.DefaultGuid);

            // By Key
            testItem = typeDB.GetByKey(typeDB.GetAllExcludeDefault().FirstOrDefaultSafe().Key);
            Assert.IsTrue(testItem.IsNew == false);
            Assert.IsTrue(testItem.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testItem.Key != TypeExtension.DefaultGuid);
        }
        /// <summary>
        /// Gets all records that exactly equal passed name
        /// </summary>
        /// <param name="name">Value to search CustomerTypeName field </param>
        /// <returns>All records matching the passed name</returns>
        public static IQueryable <CustomerType> GetByName(string name)
        {
            var reader = DatabaseReader <CustomerType> .Construct();

            return(reader.GetAll().Where(x => x.Name == name));
        }