Exemplo n.º 1
0
        public BoolEntityFilter_()
        {
            var entity = new Entity(typeof(TestEntity));
            _property = entity["IsSpecial"];

            _filter = new BoolEntityFilter(_property, "1");
        }
Exemplo n.º 2
0
        public EnumEntityFilter_()
        {
            var entity = new Entity(typeof(TestEntity));
            _property = entity["Option"];

            _filter = new EnumEntityFilter(_property, "0");
        }
        public ForeignEntityFilter_()
        {
            var entity = new Entity(typeof(TestEntity));
            _property = entity["Child"];

            _filter = new ForeignEntityFilter(_property, "1");
        }
        public ChangeEntityFilter_()
        {
            var entity = new Entity(typeof(TestEntity));
            _property = entity["Name"];

            _filter = new ChangeEntityFilter(_property, "entity_name");
        }
 public RecordsSource_GetRecord()
 {
     _source = new RecordsSource(_admin, new Notificator());
     _admin.RegisterEntity<Product>();
     _admin.Initialise(ConnectionStringName);
     _entity = _admin.GetEntity("Product");
 }
Exemplo n.º 6
0
 public EntitiesChangesModel(
     Entity entity,
     PagedRecords pagedRecords,
     TableInfo tableInfo)
     : base(entity, pagedRecords, tableInfo)
 {
 }
 public RecordsSource_GetRecord()
 {
     _source = new RecordsSource(new Notificator());
     Admin.AddEntity<Product>();
     Admin.SetForeignKeysReferences();
     Admin.ConnectionStringName = ConnectionStringName;
     _entity = Admin.EntitiesTypes
         .FirstOrDefault(x => x.Name == "Product");
 }
        public void complex_types__are_foreign_key(string propertyName)
        {
            var entityType = typeof(TestEntity);
            var entity = new Entity(entityType);

            var property = entity[propertyName];
            Assert.NotNull(property);
            Assert.True(property.IsForeignKey);
        }
        public void enums__are_not_foreign_key(string propertyName)
        {
            var entityType = typeof(TestEntity);
            var entity = new Entity(entityType);

            var property = entity[propertyName];
            Assert.NotNull(property);
            Assert.False(property.IsForeignKey);
        }
        public void collections_of_simple_types_without_foreign_attribute__are_not_foreign_key(string propertyName)
        {
            var entityType = typeof(TestEntity);
            var entity = new Entity(entityType);

            var property = entity[propertyName];
            Assert.NotNull(property);
            Assert.False(property.IsForeignKey);
        }
        public RecordsSource_Searching_String()
        {
            DB.Products.Insert(ProductName: "Test");
            DB.Products.Insert(ProductName: "Product");

            _source = new RecordsSource(_admin, new Notificator());
            Entity<Product>.Register().ReadAttributes();
            _admin.Initialise(ConnectionStringName);
            _entity = _admin.GetEntity("Product");
        }
        public RecordsSource_BoolEntityFilters()
        {
            DB.Products.Insert(ProductName: "Product", Discontinued: true);
            DB.Products.Insert(ProductName: "Product2", Discontinued: false);

            _source = new RecordsSource(_admin, new Notificator());
            Entity<Product>.Register().ReadAttributes();
            _admin.Initialise(ConnectionStringName);
            _entity = _admin.GetEntity("Product");
            _property = _entity["Discontinued"];
        }
        public RecordsSource_Searching_Numeric()
        {
            DB.Products.Insert(ProductName: "Test", UnitPrice: 3);
            DB.Products.Insert(ProductName: "Product", UnitPrice: 4.23);

            _source = new RecordsSource(_admin, new Notificator());

            Entity<Product>.Register().ReadAttributes()
                .SearchProperties(x => x.UnitPrice);
            _admin.Initialise(ConnectionStringName);
            _entity = _admin.GetEntity("Product");
        }
        public RecordsSource_Ordering()
        {
            DB.Products.Insert(ProductName: "Product");
            DB.Products.Insert(ProductName: "Product2");

            _source = new RecordsSource(new Notificator());
            Admin.AddEntity<Product>();
            Admin.SetForeignKeysReferences();
            Admin.ConnectionStringName = ConnectionStringName;
            _entity = Admin.EntitiesTypes
                .FirstOrDefault(x => x.Name == "Product");
        }
        public RecordsSource_Searching_Numeric()
        {
            DB.Products.Insert(ProductName: "Test", UnitPrice: 3);
            DB.Products.Insert(ProductName: "Product", UnitPrice: 4.23);

            _source = new RecordsSource(new Notificator());
            Entity<Product>.Add().SetSearchProperties(x => x.UnitPrice);
            Admin.SetForeignKeysReferences();
            Admin.ConnectionStringName = ConnectionStringName;
            _entity = Admin.EntitiesTypes
                .FirstOrDefault(x => x.Name == "Product");
        }
        public RecordsSource_ForeignEntityFilters()
        {
            _supplierId = DB.Suppliers.Insert(CompanyName: "Supplier").SupplierID;
            DB.Products.Insert(ProductName: "Product", SupplierID: _supplierId);
            DB.Products.Insert(ProductName: "Product2");

            _source = new RecordsSource(_admin, new Notificator());
            Entity<Product>.Register().ReadAttributes();
            _admin.Initialise(ConnectionStringName);
            _entity = _admin.GetEntity("Product");
            _property = _entity["SupplierID"];
        }
Exemplo n.º 17
0
 public RecordsCreator_()
 {
     _user = A.Fake<IProvidingUser>();
     A.CallTo(() => _user.Current()).Returns("Test");
     var executor = new DbCommandExecutor(_user);
     _creator = new RecordsCreator(executor);
     Admin.AddEntity<Product>();
     Admin.SetForeignKeysReferences();
     Admin.ConnectionStringName = ConnectionStringName;
     _entity =
         Admin.EntitiesTypes.FirstOrDefault(x => x.Name == "Product");
 }
        public RecordsSource_BoolEntityFilters()
        {
            DB.Products.Insert(ProductName: "Product", Discontinued: true);
            DB.Products.Insert(ProductName: "Product2", Discontinued: false);

            _source = new RecordsSource(new Notificator());
            Admin.AddEntity<Product>();
            Admin.SetForeignKeysReferences();
            Admin.ConnectionStringName = ConnectionStringName;
            _entity = Admin.EntitiesTypes
                .FirstOrDefault(x => x.Name == "Product");
            _property = _entity["Discontinued"];
        }
Exemplo n.º 19
0
        public RecordsUpdater_()
        {
            _source = new RecordsSource(new Notificator());
            _user = A.Fake<IProvidingUser>();
            A.CallTo(() => _user.Current()).Returns("Test");
            var executor = new DbCommandExecutor(_user);
            _updater = new RecordsUpdater(executor, _source);
            Admin.AddEntity<Product>();
            Admin.SetForeignKeysReferences();
            Admin.ConnectionStringName = ConnectionStringName;

            _productId = DB.Products.Insert(ProductName: "Product").ProductID;
            _entity = _source.GetEntityWithData(Admin.GetEntity("Product"), _productId.ToString());
        }
        public RecordsSource_ForeignEntityFilters()
        {
            _supplierId = DB.Suppliers.Insert(CompanyName: "Supplier").SupplierID;
            DB.Products.Insert(ProductName: "Product", SupplierID: _supplierId);
            DB.Products.Insert(ProductName: "Product2");

            _source = new RecordsSource(new Notificator());
            Admin.AddEntity<Product>();
            Admin.SetForeignKeysReferences();
            Admin.ConnectionStringName = ConnectionStringName;
            _entity = Admin.EntitiesTypes
                .FirstOrDefault(x => x.Name == "Product");
            _property = _entity["SupplierID"];
        }
Exemplo n.º 21
0
 public EntitiesIndexModel(
     Entity entity,
     PagedRecords pagedRecords,
     TableInfo tableInfo,
     string url)
 {
     Data = pagedRecords.Records;
     Columns = entity.DisplayProperties
         .Select(x => new Column(x, tableInfo.Order, tableInfo.OrderDirection)).ToList();
     Entity = entity;
     Pager =
         new PagerInfo(url, tableInfo.PerPage, tableInfo.Page, pagedRecords.TotalItems);
     Filters = pagedRecords.Filters.Where(x => x.DisplayInUI).ToList();
     TableInfo = tableInfo;
 }
        public static IList<PropertyDeleteOption> Merge(
            Entity entity,
            IList<PropertyDeleteOption> propertiesDeleteOptions)
        {
            var hierarchy = GetHierarchy(entity);
            foreach (var deleteOption in hierarchy
                .Where(x => x.DeleteOption == CascadeOption.AskUser))
            {
                deleteOption.DeleteOption = propertiesDeleteOptions
                    .FirstOrDefault(x => x.HierarchyName == deleteOption.HierarchyName)
                    .DeleteOption;
            }

            return hierarchy;
        }
Exemplo n.º 23
0
 public EntityDeleteModel(Entity entity)
 {
     Entity = entity;
     PropertiesDeleteOptions =
         entity.Properties
             .Where(x =>
                 x.IsForeignKey &&
                 x.DeleteOption == DeleteOption.AskUser)
             .Select(x =>
                 new PropertyDeleteOption
                 {
                     PropertyName = x.ForeignEntity.Name
                 })
             .ToList();
 }
Exemplo n.º 24
0
        public void creates_record_with_many_to_one_foreign_property()
        {
            var productId = DB.Products.Insert(ProductName: "Product").ProductID;
            Admin.AddEntity<Category>();
            Admin.SetForeignKeysReferences();
            _entity =
                Admin.EntitiesTypes.FirstOrDefault(x => x.Name == "Category");
            _entity["CategoryName"].Value.Raw = "Category";
            _entity["Products"].Value.Values.Add(productId);
            _creator.Create(_entity);

            var categories = (List<dynamic>)DB.Categories.All().ToList();
            Assert.Equal(1, categories.Count);
            var products = (List<dynamic>)DB.Products.All().ToList();
            Assert.Equal(1, products.Count);
            Assert.Equal(categories.First().CategoryID, products.First().CategoryID);
        }
        public static IList<PropertyDeleteOption> GetHierarchy(
            Entity entity,
            bool collapsed = false,
            string hierarchyNamePrefix = null,
            int level = 0)
        {
            if (hierarchyNamePrefix.HasValue())
                hierarchyNamePrefix += "-";
            var properties = new List<PropertyDeleteOption>();
            foreach (var property in entity.Properties
                       .WhereOneToMany())
            {
                var hierarchyName = hierarchyNamePrefix + property.ForeignEntity.Name;
                var visible = property.CascadeOption == CascadeOption.AskUser ||
                    property.CascadeOption == CascadeOption.Delete;
                properties.Add(new PropertyDeleteOption
                {
                    EntityName = property.ForeignEntity.Name,
                    HierarchyName = hierarchyName,
                    DeleteOption = property.CascadeOption,
                    ShowOptions = property.CascadeOption == CascadeOption.AskUser,
                    Collapsed = collapsed,
                    Level = level,
                    Visible = visible
                });

                if (visible)
                {
                    properties.AddRange(GetHierarchy(
                        property.ForeignEntity,
                        collapsed ?
                            true :
                            property.CascadeOption != CascadeOption.Delete,
                        hierarchyName,
                        ++level));
                }
            }

            return properties;
        }
Exemplo n.º 26
0
        public bool Validate(Entity entity)
        {
            var isValid = true;
            foreach (var property in entity.Properties.Where(x => x.TypeInfo.DataType == DataType.File))
            {
                var file = (HttpPostedFile)property.Value.Raw;
                var result = FileUpload.Validate(
                    file,
                    property.ImageOptions.MaxFileSize,
                    property.ImageOptions.AllowedFileExtensions,
                    !property.IsRequired);

                if (result != FileUploadValidationResult.Valid)
                {
                    isValid = false;
                    // TODO: more complex validation message
                    //modelState.AddModelError(property.Name, IlaroAdminResources.UnvalidFile);
                }
            }

            foreach (var property in entity.Properties.Where(x => x.TypeInfo.DataType != DataType.File))
            {
                foreach (var validator in property.ValidationAttributes)
                {
                    try
                    {
                        validator.Validate(property.Value.Raw, property.Name);
                    }
                    catch (ValidationException exc)
                    {
                        isValid = false;
                        //modelState.AddModelError(property.Name, exc.Message);
                    }
                }
            }
            return isValid;
        }
        public void simple_types_marked_with_foreign_attribute__are_foreign_key(string propertyName)
        {
            var entityType = typeof(TestEntity);
            var entity = new Entity(entityType);

            var property = entity[propertyName];
            Assert.NotNull(property);
            Assert.True(property.IsForeignKey);
        }
 public Property_DetermineForeignKey()
 {
     Entity<TestEntity>.Register().ReadAttributes();
     _admin.Initialise();
     _entity = _admin.GetEntity<TestEntity>();
 }
Exemplo n.º 29
0
 public EntityRecord(Entity entity)
 {
     Entity = entity;
 }
Exemplo n.º 30
0
 private void register_default_entities()
 {
     Entity<Product>.Register().ReadAttributes();
     Entity<Category>.Register().ReadAttributes();
     _admin.Initialise(ConnectionStringName);
     _productEntity = _admin.GetEntity<Product>();
 }