Added more tests
This commit is contained in:
@@ -18,6 +18,24 @@ public class HopFrameConfiguratorTests {
|
||||
Assert.IsType<DbContextConfig>(config.Contexts[0]);
|
||||
Assert.IsType<DbContextConfigurator<MockDbContext>>(dbContextConfigurator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddDbContext_WithConfigurator_AddsDbContextToInnerConfig() {
|
||||
// Arrange
|
||||
var config = new HopFrameConfig();
|
||||
var configurator = new HopFrameConfigurator(config);
|
||||
|
||||
// Act
|
||||
object dbContextConfigurator = null!;
|
||||
configurator.AddDbContext<MockDbContext>(context => {
|
||||
dbContextConfigurator = context;
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.Single(config.Contexts);
|
||||
Assert.IsType<DbContextConfig>(config.Contexts[0]);
|
||||
Assert.IsType<DbContextConfigurator<MockDbContext>>(dbContextConfigurator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisplayUserInfo_SetsDisplayUserInfoProperty() {
|
||||
|
||||
@@ -209,4 +209,17 @@ public class PropertyConfiguratorTests {
|
||||
// Assert
|
||||
Assert.Equal(orderIndex, propertyConfig.Order);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_SetsTableProperty() {
|
||||
// Arrange
|
||||
var tableConfig = new TableConfig(new DbContextConfig(typeof(MockDbContext)), typeof(MockModel), "MockModels", 0);
|
||||
|
||||
// Act
|
||||
var propertyConfig = new PropertyConfig(typeof(MockModel).GetProperty("Id")!, tableConfig, 0);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(propertyConfig.Table);
|
||||
Assert.Equal(tableConfig, propertyConfig.Table);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,22 @@ public class TableConfiguratorTests {
|
||||
// Assert
|
||||
Assert.IsType<PropertyConfigurator<int>>(propertyConfigurator);
|
||||
}
|
||||
|
||||
public void Property_WithConfigurator_ReturnsCorrectPropertyConfigurator() {
|
||||
// Arrange
|
||||
var tableConfig = new TableConfig(new DbContextConfig(typeof(MockDbContext)), typeof(MockModel), "MockModels", 0);
|
||||
var configurator = new TableConfigurator<MockModel>(tableConfig);
|
||||
Expression<Func<MockModel, int>> propertyExpression = model => model.Id;
|
||||
|
||||
// Act
|
||||
object propertyConfigurator = null!;
|
||||
configurator.Property(propertyExpression, c => {
|
||||
propertyConfigurator = c;
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.IsType<PropertyConfigurator<int>>(propertyConfigurator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddVirtualProperty_AddsVirtualPropertyToConfig() {
|
||||
@@ -50,6 +66,27 @@ public class TableConfiguratorTests {
|
||||
Assert.True(virtualProperty.IsListingProperty);
|
||||
Assert.Equal("VirtualName", virtualProperty.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddVirtualProperty_WithConfigurator_AddsVirtualPropertyToConfig() {
|
||||
// Arrange
|
||||
var tableConfig = new TableConfig(new DbContextConfig(typeof(MockDbContext)), typeof(MockModel), "MockModels", 0);
|
||||
var configurator = new TableConfigurator<MockModel>(tableConfig);
|
||||
Func<MockModel, IServiceProvider, string> template = (model, _) => model.Name!;
|
||||
|
||||
// Act
|
||||
object propertyConfigurator = null!;
|
||||
configurator.AddVirtualProperty("VirtualName", template, c => {
|
||||
propertyConfigurator = c;
|
||||
});
|
||||
|
||||
// Assert
|
||||
var virtualProperty = tableConfig.Properties.SingleOrDefault(p => p.Name == "VirtualName");
|
||||
Assert.NotNull(virtualProperty);
|
||||
Assert.NotNull(propertyConfigurator);
|
||||
Assert.True(virtualProperty.IsListingProperty);
|
||||
Assert.Equal("VirtualName", virtualProperty.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetDisplayName_SetsDisplayNameProperty() {
|
||||
@@ -148,4 +185,27 @@ public class TableConfiguratorTests {
|
||||
// Assert
|
||||
Assert.Equal(policy, tableConfig.DeletePolicy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithKeyProperty_DisablesEdit() {
|
||||
// Act
|
||||
var tableConfig = new TableConfig(new DbContextConfig(typeof(MockDbContext)), typeof(MockModel2), "Models2", 0);
|
||||
var prop = tableConfig.Properties.SingleOrDefault(prop => prop.Info.Name == nameof(MockModel2.Id));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(prop);
|
||||
Assert.False(prop.Editable);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithGeneratedProperty_DisablesEditAndCreate() {
|
||||
// Act
|
||||
var tableConfig = new TableConfig(new DbContextConfig(typeof(MockDbContext)), typeof(MockModel2), "Models2", 0);
|
||||
var prop = tableConfig.Properties.SingleOrDefault(prop => prop.Info.Name == nameof(MockModel2.Number));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(prop);
|
||||
Assert.False(prop.Editable);
|
||||
Assert.False(prop.Creatable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user