Added more tests

This commit is contained in:
2025-01-19 12:12:01 +01:00
parent afe8a41f6c
commit 8d63910aae
14 changed files with 529 additions and 60 deletions

View File

@@ -20,9 +20,9 @@ public class PropertyConfig(PropertyInfo info, TableConfig table, int nthPropert
public bool DisplayValue { get; set; } = true;
public bool TextArea { get; set; }
public int TextAreaRows { get; set; } = 16;
public bool IsRelation { get; set; }
public bool IsRequired { get; set; }
public bool IsEnumerable { get; set; }
public bool IsRelation { get; internal set; }
public bool IsRequired { get; internal set; }
public bool IsEnumerable { get; internal set; }
public bool IsListingProperty { get; set; }
public int Order { get; set; } = nthProperty;
}

View File

@@ -99,10 +99,11 @@ public class TableConfigurator<TModel>(TableConfig config) {
/// <returns>The configurator for the virtual property</returns>
/// <seealso cref="PropertyConfigurator{TProp}"/>
public PropertyConfigurator<string> AddVirtualProperty(string name, Func<TModel, IServiceProvider, string> template) {
var prop = new PropertyConfig(InnerConfig.Properties.First().Info, InnerConfig, InnerConfig.Properties.Count);
prop.Name = name;
prop.IsListingProperty = true;
prop.Formatter = (obj, provider) => template.Invoke((TModel)obj, provider);
var prop = new PropertyConfig(InnerConfig.Properties.First().Info, InnerConfig, InnerConfig.Properties.Count) {
Name = name,
IsListingProperty = true,
Formatter = (obj, provider) => template.Invoke((TModel)obj, provider)
};
InnerConfig.Properties.Add(prop);
return new PropertyConfigurator<string>(prop);
}

View File

@@ -9,7 +9,7 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
public IQueryable<object> LoadPage(int page, int perPage = 20) {
var table = context.Set<TModel>();
var data = IncludeForgeinKeys(table);
var data = IncludeForeignKeys(table);
return data
.Skip(page * perPage)
.Take(perPage);
@@ -17,7 +17,7 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
public Task<(IEnumerable<object>, int)> Search(string searchTerm, int page = 0, int perPage = 20) {
var table = context.Set<TModel>();
var all = IncludeForgeinKeys(table)
var all = IncludeForeignKeys(table)
.AsEnumerable()
.Where(item => ItemSearched(item, searchTerm))
.ToList();
@@ -101,6 +101,8 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
}
var innerConfig = explorer.GetTable(propValue.GetType());
if (innerConfig is null) return propValue.ToString()!;
var innerProp = innerConfig!.Properties
.SingleOrDefault(p => p.Info == prop.DisplayedProperty && !p.IsListingProperty);
@@ -108,14 +110,10 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
return DisplayProperty(propValue, innerProp);
}
private IQueryable<TModel> IncludeForgeinKeys(IQueryable<TModel> query) {
var pendingQuery = query;
foreach (var property in config.Properties.Where(prop => prop.IsRelation)) {
pendingQuery = pendingQuery.Include(property.Info.Name);
}
return pendingQuery;
private IQueryable<TModel> IncludeForeignKeys(IQueryable<TModel> query) {
return config.Properties
.Where(prop => prop.IsRelation)
.Aggregate(query, (current, property) => current.Include(property.Info.Name));
}
}