public void Find_Should_Return_First_Ordered_Item_Which_Satisfies_Specification_WIth_Sorting_Predicate(IRepository<Contact, string> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new Contact { Name = "Test User " + i };
                repository.Add(contact);
            }

            var result = repository.Find(new Specification<Contact>(p => p.Name.StartsWith("Test")), new SortingOptions<Contact, string>(c => c.Name, true));
            result.Name.ShouldEqual("Test User 3");

            var result2 = repository.Find(new Specification<Contact>(p => p.Name.StartsWith("Test")), new SortingOptions<Contact, string>(c => c.Name, false));
            result2.Name.ShouldEqual("Test User 1");
        }
Example #2
0
        static void Main(string[] args)
        {
            IoC.Register();
            _repo = IoC.Resolve<IRepository>();

            var geos = _repo.Find<City>().ToList();
            Console.WriteLine(string.Format("{0} total cities...", geos.Count()));

            int i =0;
            foreach (var geo in geos)
            {
                if (geo.Geography.GetType() == typeof(NetTopologySuite.Geometries.MultiPoint))
                {
                    Console.WriteLine(string.Format("{0} is a MultiPoint...", geo.Name));
                    var point = new NetTopologySuite.Geometries.Point(geo.Geography.Coordinates.First());
                    geo.Geography = point;
                    _repo.Save<City>(geo);
                    _repo.SubmitChanges();
                    Console.WriteLine(string.Format("{0} updated to Point...", geo.Name));
                    i++;
                }
            }
            Console.WriteLine(string.Format("{0} total Cities updated...", i));
            Console.Read();
        }
Example #3
0
        public void Setup()
        {
            context = new InMemoryDataContext();
            repo = new Repository(context);

            // All tests will fail if the Create does not work
            repo.Context.Add(new Customer
            {
                FirstName = "Kevin",
                LastName = "Berry",
                Company = new Company("Improving Enterprises"),
                Email = "[email protected]",
                Phone = "(555)123-4567"
            });
            repo.Context.Commit();

            customerK = repo.Find(new FindCustomerByFirstName("Kevin")).First();
        }
Example #4
0
        public static Guid? ValidateUser(IRepository repository, string username, string password)
        {
            var user = repository.Find<User>(x => x.Username == username).SingleOrDefault();

            if (user == null)
            {
                return null;
            }

            if (user.VerifyPassword(password))
            {
                return new Guid(user.Guid);
            }
            else
            {
                return null;
            }
        }
        //Methods
        public List<BLL.BusinessObjects.Attribute> GetByFeatureID(int FeatureID)
        {
            //
            List<BLL.BusinessObjects.Attribute> BLLAttributes;
            using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>())
            {
                IEnumerable<DAL.DataEntities.Attribute> DALAttributes = _AttributeRepository.Find(m => m.FeatureID == FeatureID);

                //Create Business objects for each DAL object
                BLLAttributes = new List<BusinessObjects.Attribute>();
                foreach (DAL.DataEntities.Attribute DALAttribute in DALAttributes)
                {
                    //Create the BLL object
                    BLL.BusinessObjects.Attribute BLLAttribute = BLL.BusinessObjects.Attribute.CreateInstance(DALAttribute);
                    BLLAttributes.Add(BLLAttribute);
                }
            }
            return BLLAttributes;
        }
        public List<BLL.BusinessObjects.CustomRule> GetByModelID(int ModelID)
        {
            //
            List<BLL.BusinessObjects.CustomRule> BCustomRules;
            using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>())
            {
                IEnumerable<DAL.DataEntities.CustomRule> customRules = _CustomRuleRepository.Find(m => m.ModelID == ModelID);

                //Create Business objects for each DAL object
                BCustomRules = new List<BusinessObjects.CustomRule>();
                foreach (DAL.DataEntities.CustomRule customRule in customRules)
                {
                    BCustomRules.Add((BLL.BusinessObjects.CustomRule)BLL.BusinessObjects.CustomRule.CreateInstance(customRule));
                }
            }
            return BCustomRules;
        }
        public List<BLL.BusinessObjects.Relation> GetByModelID(int ModelID)
        {
            //
            List<BLL.BusinessObjects.Relation> BRelations;
            using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>())
            {
                IEnumerable<DAL.DataEntities.Relation> relations = _RelationRepository.Find(m =>
                    m.ModelID == ModelID);

                //Create Business objects for each DAL object
                BRelations = new List<BusinessObjects.Relation>();
                foreach (DAL.DataEntities.Relation relation in relations)
                {
                    BRelations.Add((BLL.BusinessObjects.Relation)BLL.BusinessObjects.Relation.CreateInstance(relation));
                }
            }
            return BRelations;
        }
        public List<BLL.BusinessObjects.UITemplate> GetByUserID(int userid, bool excludeContentAndCSS = false)
        {
            //
            List<BLL.BusinessObjects.UITemplate> BUITemplates;
            using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>())
            {
                List<DAL.DataEntities.UITemplate> templates = _UITemplateRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.UITemplate>();

                //Create Business objects for each DAL object
                BUITemplates = new List<BusinessObjects.UITemplate>();
                foreach (DAL.DataEntities.UITemplate template in templates)
                {
                    if (excludeContentAndCSS)
                    {
                        template.Content = "";
                        template.Stylesheet = "";
                    }

                    BUITemplates.Add((BLL.BusinessObjects.UITemplate)BLL.BusinessObjects.UITemplate.CreateInstance(template));
                }
            }
            return BUITemplates;
        }
        public List<BLL.BusinessObjects.Model> GetByUserID(int userid)
        {
            //
            List<BLL.BusinessObjects.Model> BModels;
            using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
            {
                List<DAL.DataEntities.Model> models = _ModelRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.Model>();

                //Create Business objects for each DAL object
                BModels = new List<BusinessObjects.Model>();
                foreach (DAL.DataEntities.Model model in models)
                {
                    BModels.Add((BLL.BusinessObjects.Model)BLL.BusinessObjects.Model.CreateInstance(model));
                }
            }
            return BModels;
        }
        public void Find_Should_Return_Single_Item_Which_Satisfies_Predicate(IRepository<Contact, string> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new Contact { Name = "Test User " + i };
                repository.Add(contact);
            }

            var result = repository.Find(p => p.Name == "Test User 1");
            result.Name.ShouldEqual("Test User 1");
        }
        public void Delete(int id)
        {
            DAL.DataEntities.Feature feature;
            using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>())
            {
                feature = _FeatureRepository.SingleOrDefault(m => m.ID == id);

                //Cascade delete on all related FeatureSelections
                using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>())
                {
                    IEnumerable<DAL.DataEntities.FeatureSelection> featureSelections = _FeatureSelectionRepository.Find(k => k.FeatureID == feature.ID);
                    foreach (DAL.DataEntities.FeatureSelection featureSelection in featureSelections)
                    {
                        _FeatureSelectionRepository.Delete(featureSelection);
                    }

                    _FeatureSelectionRepository.SaveChanges();
                }

                //
                _FeatureRepository.Delete(feature);
                _FeatureRepository.SaveChanges();
            }
        }
        public List<BLL.BusinessObjects.Feature> GetByModelID(int ModelID)
        {
            //
            List<BLL.BusinessObjects.Feature> BFeatures;
            using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>())
            {
                IEnumerable<DAL.DataEntities.Feature> DALfeatures = _FeatureRepository.Find(m => m.ModelID == ModelID);

                //Create Business objects for each DAL object
                BFeatures = new List<BusinessObjects.Feature>();
                foreach (DAL.DataEntities.Feature DALfeature in DALfeatures)
                {
                    //Create the BLL feature
                    BLL.BusinessObjects.Feature BLLfeature = BLL.BusinessObjects.Feature.CreateInstance(DALfeature);

                    BFeatures.Add(BLLfeature);
                }
            }
            return BFeatures;
        }
Example #13
0
 private static async Task<bool> FindUserByEmailAsync(IRepository<User> usersColl, string email)
 {
     var foundUser = await usersColl.Find(u => u.Email == email).FirstOrDefaultAsync();
     return (null != foundUser);
 }
 public List<BLL.BusinessObjects.Configuration> GetByModelID(int modelID)
 {
     //
     List<BLL.BusinessObjects.Configuration> BLLConfigurations = new List<BusinessObjects.Configuration>();
     using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>())
     {
         List<DAL.DataEntities.Configuration> DALConfigurations = _ConfigurationRepository.Find(m => m.ModelID == modelID).ToList<DAL.DataEntities.Configuration>();
         DALConfigurations.ForEach(DALentity => BLLConfigurations.Add(BLL.BusinessObjects.Configuration.CreateInstance(DALentity)));
     }
     return BLLConfigurations;
 }
        public List<BLL.BusinessObjects.Constraint> GetByModelID(int ModelID)
        {
            //
            List<BLL.BusinessObjects.Constraint> BConstraints;
            using (_ConstraintRepository = new GenericRepository<DAL.DataEntities.Constraint>())
            {
                IEnumerable<DAL.DataEntities.Constraint> customRules = _ConstraintRepository.Find(m => m.ModelID == ModelID);

                //Create Business objects for each DAL object
                BConstraints = new List<BusinessObjects.Constraint>();
                foreach (DAL.DataEntities.Constraint customRule in customRules)
                {
                    BConstraints.Add((BLL.BusinessObjects.Constraint)BLL.BusinessObjects.Constraint.FromDataEntity(customRule));
                }
            }
            return BConstraints;
        }
Example #16
0
        private void VerifyPlayerDataDeleted(Player player, IRepository repository)
        {
            // verify that player is deleted
            Assert.IsEmpty(repository.Find<Player>(x => x.Id == player.Id));

            // verify that actions, cards, and messages are deleted
            Assert.IsEmpty(repository.Find<Haven.Action>(x => x.OwnerId == player.Id));
            Assert.IsEmpty(repository.Find<PlayerNameCard>(x => x.PlayerId == player.Id));
            Assert.IsEmpty(repository.Find<PlayerSafeHavenCard>(x => x.PlayerId == player.Id));
            Assert.IsEmpty(repository.Find<Message>(x => x.PlayerId == player.Id));
        }
        public void Find_Should_Return_Single_Item_Which_Satisfies_Composite_Specification(IRepository<Contact, string> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new Contact { Name = "Test User " + i };
                repository.Add(contact);
            }

            var result = repository.Find(new Specification<Contact>(p => p.Name == "Test User 1").OrElse(new Specification<Contact>(p => p.Name == "Test User 1000")));
            result.Name.ShouldEqual("Test User 1");
        }
Example #18
0
        public List<BLL.BusinessObjects.Model> GetByUserID_Shallow(int userid)
        {
            //
            List<BLL.BusinessObjects.Model> BModels;
            using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
            {
                //Shallow retreival
                _ModelRepository.GetContext().ContextOptions.LazyLoadingEnabled = false;

                //
                List<DAL.DataEntities.Model> models = _ModelRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.Model>();

                //Create Business objects for each DAL object
                BModels = new List<BusinessObjects.Model>();
                foreach (DAL.DataEntities.Model model in models)
                {
                    BModels.Add((BLL.BusinessObjects.Model)BLL.BusinessObjects.Model.CreateInstance(model));
                }
            }
            return BModels;
        }
        public List<BLL.BusinessObjects.GroupRelation> GetByModelID(int ModelID)
        {
            //
            List<BLL.BusinessObjects.GroupRelation> BLLGroupRelations;
            using (_GroupRelationRepository = new GenericRepository<DAL.DataEntities.GroupRelation>())
            {
                //Get all DAL groupRelation entities
                IEnumerable<DAL.DataEntities.GroupRelation> DALgroupRelations = _GroupRelationRepository.Find(m => m.ModelID == ModelID);

                //Create Business objects for each DAL object
                BLLGroupRelations = new List<BusinessObjects.GroupRelation>();
                foreach (DAL.DataEntities.GroupRelation DALgroupRelation in DALgroupRelations)
                {
                    //Business object
                    BLL.BusinessObjects.GroupRelation BLLGroupRelation = (BLL.BusinessObjects.GroupRelation)BLL.BusinessObjects.GroupRelation.CreateInstance(DALgroupRelation);
                    BLLGroupRelations.Add(BLLGroupRelation);
                }
            }
            return BLLGroupRelations;
        }